/** * Close/Re-open Github issue when checklistItem changed on Trello */ public function trigger() { $checkItemDto = $this->trelloWebHook->getDtoContainer()->getCheckItemDto(); $repoInfo = IssueReference::getRepositoryInformationFromUrl($checkItemDto->getName()); if (!$repoInfo) { return; } $githubIssueStateNew = $checkItemDto->getState() == ChecklistItem::STATUS_COMPLETE ? Issue::STATE_CLOSED : Issue::STATE_OPEN; $issue = $this->getIssueFromGithub($repoInfo); if ($issue && $issue['state'] != $githubIssueStateNew) { $this->updateIssue($repoInfo, $githubIssueStateNew); } }
/** * @return bool|\LooplineSystems\IssueManager\Library\Github\RepositoryInformation */ protected function getRepositoryInformation() { return IssueReference::getRepositoryInformationFromUrl($this->event->getIssue()->getUrl()); }
/** * @param Checklist $checklist * @param RepositoryInformation $repoInfo * @param $title * @return ChecklistItem */ public function createChecklistItem(Checklist $checklist, RepositoryInformation $repoInfo, $title) { $itemName = IssueReference::createReferenceFromRepositoryInformation($repoInfo, $title); $checklistItem = new ChecklistItem(); $checklistItem->setIdChecklist($checklist->getId()); $checklistItem->setName($itemName); return $this->api->createChecklistItem($checklistItem); }
/** * @param $comment * @param Checklist $checklist * @return mixed|string */ private function prepareBadgeCommentForMentionedRepositories($comment, Checklist $checklist) { $replaceWords = []; /* @var RepositoryInformation $mentionedIssue */ foreach ($this->mentionedRepositories as $mentionedRepository) { //--___________________________________________________--> //-- if checklist items are mentioned add badge foreach ($checklist->getCheckItems() as $checkItem) { if (!$checkItem instanceof ChecklistItem) { //--___________________________________________________--> //-- prepare /* @var CheckListItem $checkListItem */ $checkListItem = ObjectPopulator::populate(new ChecklistItem(), $checkItem); $checkListItemName = $checkListItem->getName(); $repositoryInformationFromChecklistItemName = IssueReference::getRepositoryInformationFromUrl($checkListItemName); //--___________________________________________________--> //-- check if repository exists try { $this->githubClient->issues()->show($this->getGithubUserName(), $repositoryInformationFromChecklistItemName->getRepositoryName(), $repositoryInformationFromChecklistItemName->getIssueId()); } catch (\Github\Exception\RuntimeException $runtimeException) { continue; } //--___________________________________________________--> //-- add issue badge if repository was mentioned if ($repositoryInformationFromChecklistItemName->getRepositoryName() == $mentionedRepository) { $comment .= $this->getIssueBadge($repositoryInformationFromChecklistItemName); } } } $replaceWords[] = '[' . $mentionedRepository . ']'; } $comment = str_replace($replaceWords, '', $comment); return $comment; }