giteaservice = $giteaservice; } public function change(Request $request) { $em = $this->getDoctrine()->getManager(); $id=$request->get('id'); $oldcolumn=$request->get('oldcolumn'); $newcolumn=$request->get('newcolumn'); $oldmilestone=$request->get('oldmilestone'); $newmilestone=$request->get('newmilestone'); $oldsprint=$request->get('oldsprint'); $newsprint=$request->get('newsprint'); if($oldcolumn!=$newcolumn||$oldmilestone!=$newmilestone||$oldsprint!=$newsprint) { // Rechercher l'issue en cours $scrumissue=$em->getRepository("App:Scrumissue")->find($id); if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403); // Récupérer la liste des labels de l'issue $gitealabels=$this->giteaservice->getIssuelabels($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber()); if(!is_array($gitealabels)) return new JsonResponse(['message' => 'No API getIssuelabels'], 403); // Remplacer l'ancien column par la nouvelle if($oldcolumn!=$newcolumn) { $newgitelabels=[]; $haveold=false; foreach($gitealabels as $gitealabel) { if($gitealabel->id!=$oldcolumn) array_push($newgitelabels,$gitealabel->id); else $haveold=true; } if(!in_array($newcolumn,$newgitelabels)) array_push($newgitelabels,intval($newcolumn)); // Supprimer l'ancien label if($haveold) { $return=$this->giteaservice->deleteIssuelabel($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber(),$oldcolumn); if(!$return) return new JsonResponse(['message' => 'No API deleteIssuelabel'], 403); } // Mettre à jour les labels $return=$this->giteaservice->putIssuelabels($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber(),$newgitelabels); if(!$return) return new JsonResponse(['message' => 'No API putIssuelabels'], 403); } // Mettre à jour le milestone if($oldmilestone!=$newmilestone) { $patchs=["milestone"=>intval($newmilestone)]; $return=$this->giteaservice->patchIssue($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber(),$patchs); if(!$return) return new JsonResponse(['message' => 'No API patchIssue'], 403); } // Mettre à jour le sprint if($oldsprint!=$newsprint) { $scrumissue->setScrumsprint(null); $sprint=$em->getRepository("App:Scrumsprint")->find($newsprint); if($sprint) { $scrumissue->setScrumsprint($sprint); } $em->flush(); } // Récupérer l'issue modifiée pour mettre à jour la date de modification gitea $giteaissue=$this->giteaservice->getIssue($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber()); if(!$giteaissue) return new JsonResponse(['message' => 'No API getIssue'], 403); $updateissue=new \DateTime($giteaissue->updated_at); $updateissue->setTimezone(new \DateTimeZone("UTC")); $lastupdate=$scrumissue->getScrum()->getUpdatedate(); if($updateissue > $lastupdate) { $scrumissue->getScrum()->setUpdatedate($updateissue); $em->persist($scrumissue->getScrum()); $em->flush(); return new JsonResponse($updateissue->format("Ymd H:i:s")); } } return new JsonResponse(false); } public function order(Request $request) { $em = $this->getDoctrine()->getManager(); $id=$request->get('id'); $lstordered=explode(",",$request->get('lstordered')); $scrum=$em->getRepository("App:Scrum")->find($id); if(!$scrum) return new JsonResponse(['message' => 'No Scrum'], 403); $order=0; foreach($lstordered as $item) { $scrumissue=$em->getRepository("App:Scrumissue")->find($item); if($scrumissue) { $scrumissue->setRowid($order); $order++; $em->persist($scrumissue); } } $em->flush(); return new JsonResponse(); } public function info(Request $request) { $em = $this->getDoctrine()->getManager(); $id=$request->get('id'); // Rechercher l'issue en cours $scrumissue=$em->getRepository("App:Scrumissue")->find($id); if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403); $output=[]; $output["weight"]=$scrumissue->getWeight(); $output["giteajson"]=$scrumissue->getGiteajson(); return new JsonResponse($output); } public function view($id, Request $request) { $em = $this->getDoctrine()->getManager(); $issue=$em->getRepository("App:Scrumissue")->find($id); $scrum = $issue->getScrum(); $repoid = $scrum->getGiteaid(); $repoowner = $scrum->getGiteajson()["owner"]["login"]; $reponame = $scrum->getGiteajson()["name"]; $repo=$this->giteaservice->getRepo($repoid); $giteaissue=$this->giteaservice->getIssue($repoowner,$reponame,$issue->getGiteanumber()); $giteaissue->body = $this->giteaservice->markdown("/".$scrum->getGiteajson()["full_name"],"comment",$giteaissue->body); $giteaissue->comments=$this->giteaservice->getIssueComments($repoowner,$reponame,$giteaissue->number); $giteaissue->statuslife=$issue->getScrumcolumn()->getName(); $giteaissue->weight=$issue->getWeight(); $giteaissue->nineid=$issue->getId(); $giteaissue->sprint=($issue->getScrumsprint()?$issue->getScrumsprint()->getName():null); foreach($giteaissue->comments as $keycomment => $comment) { $giteaissue->comments[$keycomment]->body=$this->giteaservice->markdown("/".$scrum->getGiteajson()["full_name"],"comment",$giteaissue->comments[$keycomment]->body); } $giteaissue->timelines=$this->giteaservice->getIssueTimelines($repoowner,$reponame,$giteaissue->number); $giteaissue->labelhistos=[]; $giteaissue->refs=[]; foreach($giteaissue->timelines as $key => $timeline) { if($timeline->type == "label"){ $tmp=new stdClass(); $tmp->label=($timeline->body==1?"Ajout Label":"Suppression Label")." ".$timeline->label->name.""; $tmp->user=$timeline->user; $tmp->created_at=$timeline->created_at; array_push($giteaissue->labelhistos,$tmp); unset($giteaissue->timelines[$key]); } elseif($timeline->type == "comment_ref" || $timeline->type == "pull_ref" || $timeline->type == "issue_ref"){ $tmp=new stdClass(); $tmp->label =""; $tmp->label.=($timeline->type=="pull_ref"?"Request":"Issue")." = "; $tmp->label.="#".$timeline->ref_issue->number." = ".$timeline->ref_issue->title.""; $tmp->user=$timeline->user; $tmp->created_at=$timeline->created_at; array_push($giteaissue->refs,$tmp); unset($giteaissue->timelines[$key]); } } // Affichage du formulaire return $this->render('Scrum/issue.html.twig', [ 'useheader' => false, 'usesidebar' => false, 'maxwidth' => true, 'repo' => $repo, 'issue' => $giteaissue, ]); } public function update(Request $request) { $em = $this->getDoctrine()->getManager(); $id=$request->get('id'); $weight=$request->get('weight'); // Rechercher l'issue en cours $scrumissue=$em->getRepository("App:Scrumissue")->find($id); if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403); $scrumissue->setWeight($weight); $em->flush(); $giteaissues=$this->giteaservice->getIssues($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"]); $weights=[]; foreach($giteaissues as $giteaissue) { $issue=$em->getRepository("App:Scrumissue")->findOneBy(["scrum"=>$scrumissue->getScrum(),"giteaid"=>$giteaissue->id]); if($issue) { if($giteaissue->milestone) $milestoneid=$giteaissue->milestone->id; else $milestoneid=-100; if(!array_key_exists($milestoneid,$weights)) $weights[$milestoneid]=0; $weights[$milestoneid]=$weights[$milestoneid]+$issue->getWeight(); } } return new JsonResponse($weights); } public function block(Request $request) { $em = $this->getDoctrine()->getManager(); $id=$request->get('id'); $issueblocked=$request->get('issueblocked'); // Rechercher l'issue en cours $scrumissue=$em->getRepository("App:Scrumissue")->find($id); if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403); // Bloquer l'issue $response=$this->giteaservice->postIssueblocks($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber(),$issueblocked); if(!$response) return new JsonResponse(['message' => 'Error api'], 403); return new JsonResponse([]); } public function unblock(Request $request) { $em = $this->getDoctrine()->getManager(); $id=$request->get('id'); // Rechercher l'issue en cours $scrumissue=$em->getRepository("App:Scrumissue")->find($id); if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403); if(!$scrumissue->getScrumissueblock()) return new JsonResponse(['message' => 'No Issue'], 403); $issueblocked=$scrumissue->getScrumissueblock()->getGiteanumber(); // Débloquer l'issue $response=$this->giteaservice->deleteIssueblocks($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber(),$issueblocked); if(!$response) return new JsonResponse(['message' => 'Error api'], 403); return new JsonResponse([]); } public function assigne(Request $request) { $em = $this->getDoctrine()->getManager(); $id=$request->get('id'); $assignees=$request->get('assignees'); // Rechercher l'issue en cours $scrumissue=$em->getRepository("App:Scrumissue")->find($id); if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403); // Affecter l'issue $response=$this->giteaservice->patchissue($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber(),["assignees"=>($assignees?$assignees:[])]); if(!$response) return new JsonResponse(['message' => 'Error api'], 403); return new JsonResponse([]); } public function color(Request $request) { $em = $this->getDoctrine()->getManager(); $id=$request->get('id'); $color=$request->get('color'); // Rechercher l'issue en cours $scrumissue=$em->getRepository("App:Scrumissue")->find($id); if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403); $scrumissue->setColor($color); $em->flush(); return new JsonResponse([]); } public function ctrlchange(Request $request) { $em = $this->getDoctrine()->getManager(); $id=$request->get('id'); $lastupdate=new \DateTime($request->get('lastupdate')); $scrum=$em->getRepository("App:Scrum")->find($id); if(!$scrum) return new JsonResponse(['message' => 'No Scrum'], 403); /* $lastupdate=$scrum->getUpdatedate(); $lastupdate->setTimezone(new \DateTimeZone("UTC")); */ $giteaissues=$this->giteaservice->getIssues($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]); if(!is_array($giteaissues)) die("Probleme de connexion avec gitea veuillez vous reconnecter"); foreach($giteaissues as $giteaissue) { // On ne prend pas les pull request if(!is_null($giteaissue->pull_request)) continue; $scrumissue=$em->getRepository("App:Scrumissue")->findOneBy(["scrum"=>$scrum,"giteaid"=>$giteaissue->id]); if(!$scrumissue) { return new JsonResponse(true); } $fgissueupdated=false; $updateissue=new \DateTime(json_decode(json_encode($giteaissue), true)["updated_at"]); $updateissue->setTimezone(new \DateTimeZone("UTC")); if($updateissue>$lastupdate) { $fgissueupdated=true; } if($fgissueupdated) return new JsonResponse(true); } return new JsonResponse(false); } public function getpoker($userid,$issueid,Request $request) { return new Response(0); } public function setpoker($userid,$issueid,Request $request) { } }