/** * 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 $repositoryInformationNew * @return ChecklistItem|null */ public function getChecklistItemByRepositoryInformation(Checklist $checklist = null, RepositoryInformation $repositoryInformationNew) { if (!$checklist || $checklist->getCheckItems() === null) { return null; } foreach ($checklist->getCheckItems() as $itemData) { $repoInfo = IssueReference::getRepositoryInformationFromUrl($itemData['name']); if (!$repoInfo) { continue; } if ($repoInfo->isSame($repositoryInformationNew)) { $checkItem = new ChecklistItem(); $checkItem = ObjectPopulator::populate($checkItem, $itemData); $checkItem->setIdChecklist($checklist->getId()); return $checkItem; } } return null; }
/** * @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; }