|
3 | 3 | namespace AppBundle\Issues;
|
4 | 4 |
|
5 | 5 | use AppBundle\Event\GitHubEvent;
|
| 6 | +use AppBundle\GitHubEvents; |
6 | 7 | use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
7 | 8 |
|
8 |
| -abstract class IssueListener implements EventSubscriberInterface |
| 9 | +class IssueListener implements EventSubscriberInterface |
9 | 10 | {
|
10 |
| - protected static $triggerWordToStatus; |
11 |
| - protected static $privateTriggerWordToStatus; |
| 11 | + private static $triggerWordToStatus = [ |
| 12 | + 'needs review' => Status::NEEDS_REVIEW, |
| 13 | + 'needs work' => Status::NEEDS_WORK, |
| 14 | + 'works for me' => Status::WORKS_FOR_ME, |
| 15 | + 'reviewed' => Status::REVIEWED, |
| 16 | + 'needs comments' => Status::NEEDS_COMMENTS, |
| 17 | + ]; |
| 18 | + |
| 19 | + private static $privateTriggerWordToStatus = [ |
| 20 | + 'ready' => Status::READY, |
| 21 | + ]; |
12 | 22 |
|
13 | 23 | /**
|
14 | 24 | * @var StatusApi
|
@@ -82,13 +92,56 @@ public function onPullRequest(GitHubEvent $event)
|
82 | 92 | $event->setResponseData($responseData);
|
83 | 93 | }
|
84 | 94 |
|
85 |
| - final protected function getIssueStatus($issueNumber) |
| 95 | + /** |
| 96 | + * Changes "Bug" issues to "Needs Review". |
| 97 | + * |
| 98 | + * @param GitHubEvent $event |
| 99 | + */ |
| 100 | + public function onIssues(GitHubEvent $event) |
| 101 | + { |
| 102 | + $data = $event->getData(); |
| 103 | + if ('labeled' !== $action = $data['action']) { |
| 104 | + $event->setResponseData(array('unsupported_action' => $action)); |
| 105 | + |
| 106 | + return; |
| 107 | + } |
| 108 | + |
| 109 | + $responseData = array('issue' => $issueNumber = $data['issue']['number']); |
| 110 | + // Ignore non-bugs or issue which already has a status |
| 111 | + if ('bug' !== strtolower($data['label']['name']) || null !== $currentStatus = $this->getIssueStatus($issueNumber)) { |
| 112 | + $responseData['status_change'] = null; |
| 113 | + $event->setResponseData($responseData); |
| 114 | + |
| 115 | + return; |
| 116 | + } |
| 117 | + |
| 118 | + $newStatus = Status::NEEDS_REVIEW; |
| 119 | + |
| 120 | + $this->setIssueStatus($issueNumber, $newStatus); |
| 121 | + $responseData['status_change'] = $newStatus; |
| 122 | + |
| 123 | + $event->setResponseData($responseData); |
| 124 | + } |
| 125 | + |
| 126 | + private function getIssueStatus($issueNumber) |
86 | 127 | {
|
87 | 128 | return $this->statusApi->getIssueStatus($issueNumber);
|
88 | 129 | }
|
89 | 130 |
|
90 |
| - final protected function setIssueStatus($issueNumber, $status) |
| 131 | + private function setIssueStatus($issueNumber, $status) |
91 | 132 | {
|
92 | 133 | return $this->statusApi->setIssueStatus($issueNumber, $status);
|
93 | 134 | }
|
| 135 | + |
| 136 | + /** |
| 137 | + * {@inheritdoc} |
| 138 | + */ |
| 139 | + public static function getSubscribedEvents() |
| 140 | + { |
| 141 | + return array( |
| 142 | + GitHubEvents::ISSUE_COMMENT => 'onIssueComment', |
| 143 | + GitHubEvents::PULL_REQUEST => 'onPullRequest', |
| 144 | + GitHubEvents::ISSUES => 'onIssues', |
| 145 | + ); |
| 146 | + } |
94 | 147 | }
|
0 commit comments