2022-09-21 11:05:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2023-05-10 10:18:40 +02:00
|
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
2022-09-21 11:05:17 +02:00
|
|
|
use App\Service\giteaService;
|
|
|
|
|
|
|
|
class ReportController extends AbstractController
|
|
|
|
{
|
2023-05-10 10:18:40 +02:00
|
|
|
public function __construct(KernelInterface $appKernel, giteaService $giteaservice) {
|
|
|
|
$this->appKernel = $appKernel;
|
|
|
|
$this->giteaservice = $giteaservice;
|
|
|
|
}
|
2022-09-21 11:05:17 +02:00
|
|
|
|
|
|
|
public function list($id,Request $request)
|
|
|
|
{
|
|
|
|
set_time_limit(0);
|
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$scrum = $em->getRepository("App:Scrum")->find($id);
|
|
|
|
$repoid = $scrum->getGiteaid();
|
|
|
|
$repoowner = $scrum->getGiteajson()["owner"]["login"];
|
|
|
|
$reponame = $scrum->getGiteajson()["name"];
|
|
|
|
|
|
|
|
$repo=$this->giteaservice->getRepo($repoid);
|
|
|
|
$issues=$this->giteaservice->getIssues($repoowner,$reponame,"?state=all");
|
|
|
|
|
|
|
|
foreach($issues as $keyissue => $issue) {
|
2023-08-24 13:22:38 +02:00
|
|
|
// On ne prend pas les pull request
|
|
|
|
if(!is_null($issue->pull_request)) {
|
|
|
|
unset($issues[$keyissue]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-08-25 14:44:12 +02:00
|
|
|
//$issues[$keyissue]->body = $this->giteaservice->markdown("/".$scrum->getGiteajson()["full_name"],"comment",$issues[$keyissue]->body);
|
|
|
|
//$issues[$keyissue]->comments=$this->giteaservice->getIssueComments($repoowner,$reponame,$issue->number);
|
2023-08-24 13:22:38 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Trop lourd
|
2022-09-21 11:05:17 +02:00
|
|
|
foreach($issues[$keyissue]->comments as $keycomment => $comment) {
|
|
|
|
$issues[$keyissue]->comments[$keycomment]->body=$this->giteaservice->markdown("/".$scrum->getGiteajson()["full_name"],"comment",$issues[$keyissue]->comments[$keycomment]->body);
|
|
|
|
}
|
2023-08-24 13:22:38 +02:00
|
|
|
*/
|
2022-09-21 11:05:17 +02:00
|
|
|
|
2023-08-24 13:22:38 +02:00
|
|
|
/*
|
|
|
|
Trop lourd
|
2022-09-21 11:05:17 +02:00
|
|
|
$issues[$keyissue]->timelines=$this->giteaservice->getIssueTimelines($repoowner,$reponame,$issue->number);
|
2023-08-24 13:22:38 +02:00
|
|
|
*/
|
|
|
|
$issues[$keyissue]->timelines=[];
|
2022-09-21 11:05:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Affichage du formulaire
|
|
|
|
return $this->render('Report/list.html.twig', [
|
|
|
|
'useheader' => false,
|
|
|
|
'usesidebar' => false,
|
|
|
|
'maxwidth' => true,
|
|
|
|
'repo' => $repo,
|
|
|
|
'issues' => $issues,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-05-10 10:18:40 +02:00
|
|
|
public function csv($id,Request $request)
|
2022-09-21 11:05:17 +02:00
|
|
|
{
|
2023-05-10 10:18:40 +02:00
|
|
|
set_time_limit(0);
|
2022-09-21 11:05:17 +02:00
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
2023-05-10 10:18:40 +02:00
|
|
|
$scrum = $em->getRepository("App:Scrum")->find($id);
|
|
|
|
$repoid = $scrum->getGiteaid();
|
|
|
|
$repoowner = $scrum->getGiteajson()["owner"]["login"];
|
|
|
|
$reponame = $scrum->getGiteajson()["name"];
|
2022-09-21 11:05:17 +02:00
|
|
|
|
2023-05-10 10:18:40 +02:00
|
|
|
$repo=$this->giteaservice->getRepo($repoid);
|
|
|
|
$issues=$this->giteaservice->getIssues($repoowner,$reponame,"?state=all");
|
2022-09-21 11:05:17 +02:00
|
|
|
|
2023-05-10 10:18:40 +02:00
|
|
|
$fs = new Filesystem();
|
|
|
|
$rootdir = $this->appKernel->getProjectDir();
|
|
|
|
$destdir = $rootdir."/var/log/export.csv";
|
2022-09-21 11:05:17 +02:00
|
|
|
|
2023-05-10 10:18:40 +02:00
|
|
|
$csvh = fopen($destdir, 'w');
|
|
|
|
$d = ';'; // this is the default but i like to be explicit
|
|
|
|
$e = '"'; // this is the default but i like to be explicit
|
|
|
|
|
|
|
|
$tbcumul=[];
|
|
|
|
|
|
|
|
foreach($issues as $issue) {
|
|
|
|
$monthsubmit=new \DateTime($issue->created_at);
|
|
|
|
$monthsubmit=$monthsubmit->format("Ym");
|
|
|
|
if(!array_key_exists($monthsubmit,$tbcumul))
|
|
|
|
$tbcumul[$monthsubmit]=["month"=>$monthsubmit,"nbsubmit"=>0,"nbclose"=>0];
|
|
|
|
$tbcumul[$monthsubmit]["nbsubmit"]=$tbcumul[$monthsubmit]["nbsubmit"]+1;
|
|
|
|
|
|
|
|
$monthclose=new \DateTime($issue->closed_at);
|
|
|
|
$monthclose=$monthclose->format("Ym");
|
|
|
|
if(!array_key_exists($monthclose,$tbcumul))
|
|
|
|
$tbcumul[$monthclose]=["month"=>$monthclose,"nbsubmit"=>0,"nbclose"=>0];
|
|
|
|
$tbcumul[$monthclose]["nbclose"]=$tbcumul[$monthclose]["nbclose"]+1;
|
2022-09-21 11:05:17 +02:00
|
|
|
}
|
|
|
|
|
2023-05-10 10:18:40 +02:00
|
|
|
foreach($tbcumul as $cumul) {
|
|
|
|
fputcsv($csvh, $cumul, $d, $e);
|
2022-09-21 11:05:17 +02:00
|
|
|
}
|
2023-05-10 10:18:40 +02:00
|
|
|
fclose($csvh);
|
2022-09-21 11:05:17 +02:00
|
|
|
|
2023-05-10 10:18:40 +02:00
|
|
|
$response = new BinaryFileResponse($destdir);
|
|
|
|
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
|
2022-09-21 11:05:17 +02:00
|
|
|
|
2023-05-10 10:18:40 +02:00
|
|
|
return $response;
|
2022-09-21 11:05:17 +02:00
|
|
|
|
2023-05-10 10:18:40 +02:00
|
|
|
}
|
2023-08-24 13:22:38 +02:00
|
|
|
|
|
|
|
public function test($id,Request $request)
|
|
|
|
{
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$scrum = $em->getRepository("App:Scrum")->find($id);
|
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$scrum = $em->getRepository("App:Scrum")->find($id);
|
|
|
|
$repoid = $scrum->getGiteaid();
|
|
|
|
$repoowner = $scrum->getGiteajson()["owner"]["login"];
|
|
|
|
$reponame = $scrum->getGiteajson()["name"];
|
|
|
|
|
|
|
|
$repo=$this->giteaservice->getRepo($repoid);
|
|
|
|
dump($repo);
|
|
|
|
dump($repoowner);
|
|
|
|
$labels=$this->giteaservice->getorglabels($repoowner);
|
|
|
|
|
|
|
|
dump($labels);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-09-21 11:05:17 +02:00
|
|
|
}
|