commit iniziale
This commit is contained in:
parent
9e364c6696
commit
a40cafc383
46 changed files with 9556 additions and 1 deletions
23
app/Http/Controllers/CheckSimpleAuthController.php
Normal file
23
app/Http/Controllers/CheckSimpleAuthController.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class CheckSimpleAuthController extends Controller
|
||||
{
|
||||
public function check(Request $req) {
|
||||
if (
|
||||
getenv('GITEA_ORGANIZATION') === $req->input('organizzazione')
|
||||
&&
|
||||
getenv('APP_PASSWORD') === $req->input('password')
|
||||
) {
|
||||
return view('backend', [
|
||||
'token' => getenv('GITEA_TOKEN')
|
||||
]);
|
||||
} else {
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
}
|
10
app/Http/Controllers/Controller.php
Normal file
10
app/Http/Controllers/Controller.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Laravel\Lumen\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
//
|
||||
}
|
18
app/Http/Controllers/ExampleController.php
Normal file
18
app/Http/Controllers/ExampleController.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
class ExampleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
}
|
120
app/Http/Controllers/GiteaApiController.php
Normal file
120
app/Http/Controllers/GiteaApiController.php
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use OwenVoke\Gitea\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use DateTime;
|
||||
|
||||
class GiteaApiController extends Controller
|
||||
{
|
||||
private $giteaClient;
|
||||
private $organization;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->organization = getenv('GITEA_ORGANIZATION');
|
||||
$this->giteaClient = new Client(null, null, getenv('GITEA_URL'));
|
||||
$this->giteaClient->authenticate(getenv('GITEA_TOKEN'), null, Client::AUTH_ACCESS_TOKEN);
|
||||
}
|
||||
|
||||
private function get_repositories()
|
||||
{
|
||||
$repositories = $this->giteaClient->organizations()->repositories($this->organization, 1, 9999);
|
||||
return $repositories;
|
||||
}
|
||||
|
||||
private function get_issues(string $repository, array $parameters = array())
|
||||
{
|
||||
return $issues = $this->giteaClient->repositories()->issues()->all($this->organization, $repository, $parameters);
|
||||
}
|
||||
|
||||
private function get_issue_total_time(string $repository, int $id)
|
||||
{
|
||||
$times = $this->giteaClient->repositories()->issues()->times($this->organization, $repository, $id);
|
||||
$count = 0;
|
||||
foreach ($times as $time) {
|
||||
$count += (int) $time['time'];
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
private function get_issue_labels(array $issue)
|
||||
{
|
||||
$labels = '';
|
||||
foreach ($issue['labels'] as $label) {
|
||||
$labels .= $label['name'] . ',';
|
||||
}
|
||||
return $labels;
|
||||
}
|
||||
|
||||
private function create_columns(array $issue)
|
||||
{
|
||||
return array(
|
||||
'Progetto' => $issue['repository']['name'],
|
||||
'#' => $issue['number'],
|
||||
'Titolo' => $issue['title'],
|
||||
'URL' => $issue['html_url'],
|
||||
'Aperto_il' => $issue['created_at'],
|
||||
'Chiuso_il' => $issue['closed_at'],
|
||||
'Etichette' => $this->get_issue_labels($issue),
|
||||
'Tempo' => gmdate('H:i:s', $this->get_issue_total_time($issue['repository']['name'], $issue['number']))
|
||||
);
|
||||
}
|
||||
|
||||
private function create_csv(string $file_name, array $data)
|
||||
{
|
||||
$f = fopen('php://output', 'w'); // Configure fopen to create, open, and write data.
|
||||
|
||||
fputcsv($f, array_keys($data[0])); // Add the keys as the column headers
|
||||
// Loop over the array and passing in the values only.
|
||||
foreach ($data as $row) {
|
||||
fputcsv($f, $row);
|
||||
}
|
||||
fclose($f);
|
||||
// tell the browser it's going to be a csv file
|
||||
header('Content-Type: text/csv');
|
||||
// tell the browser we want to save it instead of displaying it
|
||||
header('Content-Disposition: attachment; filename="' . $file_name . '.csv";');
|
||||
exit();
|
||||
}
|
||||
|
||||
private function date_to_datetime(string $date)
|
||||
{
|
||||
$date = str_replace('/', '-', $date);
|
||||
$datetime = new DateTime($date);
|
||||
|
||||
return $datetime->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
private function export_issues(string $from_date, array $issues_params)
|
||||
{
|
||||
$data = array();
|
||||
$repositories = $this->get_repositories();
|
||||
foreach ($repositories as $repository) {
|
||||
$issues = $this->get_issues($repository['name'], $issues_params);
|
||||
foreach ($issues as $issue) {
|
||||
$from_datetime = $this->date_to_datetime($from_date);
|
||||
if (substr($issue['closed_at'], 0, 19) > $from_datetime) {
|
||||
$data[] = $this->create_columns($issue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$file_name = date('Y_F', strtotime(explode(' ', $data[0]['Chiuso_il'])[0]));
|
||||
$this->create_csv($file_name, $data);
|
||||
}
|
||||
|
||||
public function export_closed_issues(Request $req)
|
||||
{
|
||||
if ($req->input('token') != getenv('GITEA_TOKEN')) {
|
||||
return redirect('/');
|
||||
}
|
||||
$date = $req->input('year') . '-' . $req->input('month') . '-01';
|
||||
$this->export_issues($date, ['state' => 'closed']);
|
||||
return view('backend', [
|
||||
'token' => getenv('GITEA_TOKEN')
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue