Changeset View
Changeset View
Standalone View
Standalone View
src/applications/nuance/github/NuanceGitHubRawEvent.php
| Show All 24 Lines | public function isIssueEvent() { | ||||
| } | } | ||||
| if ($this->type == self::TYPE_ISSUE) { | if ($this->type == self::TYPE_ISSUE) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| switch ($this->getIssueRawKind()) { | switch ($this->getIssueRawKind()) { | ||||
| case 'IssuesEvent': | case 'IssuesEvent': | ||||
| case 'IssuesCommentEvent': | |||||
| return true; | return true; | ||||
| case 'IssueCommentEvent': | |||||
| if (!$this->getRawPullRequestData()) { | |||||
| return true; | |||||
| } | |||||
| break; | |||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| public function isPullRequestEvent() { | public function isPullRequestEvent() { | ||||
| if ($this->type == self::TYPE_ISSUE) { | |||||
| // TODO: This is wrong, some of these are pull events. | |||||
| return false; | |||||
| } | |||||
| $raw = $this->raw; | |||||
| switch ($this->getIssueRawKind()) { | |||||
| case 'PullRequestEvent': | |||||
| return true; | |||||
| case 'IssueCommentEvent': | |||||
| if ($this->getRawPullRequestData()) { | |||||
| return true; | |||||
| } | |||||
| break; | |||||
| } | |||||
| return false; | return false; | ||||
| } | } | ||||
| public function getIssueNumber() { | public function getIssueNumber() { | ||||
| if (!$this->isIssueEvent()) { | if (!$this->isIssueEvent()) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| return $this->getRawIssueNumber(); | |||||
| } | |||||
| public function getPullRequestNumber() { | |||||
| if (!$this->isPullRequestEvent()) { | |||||
| return null; | |||||
| } | |||||
| return $this->getRawIssueNumber(); | |||||
| } | |||||
| private function getRepositoryFullRawName() { | |||||
| $raw = $this->raw; | |||||
| $full = idxv($raw, array('repo', 'name')); | |||||
| if (strlen($full)) { | |||||
| return $full; | |||||
| } | |||||
| // For issue events, the repository is not identified explicitly in the | |||||
| // response body. Parse it out of the URI. | |||||
| $matches = null; | |||||
| $ok = preg_match( | |||||
| '(/repos/((?:[^/]+)/(?:[^/]+))/issues/events/)', | |||||
| idx($raw, 'url'), | |||||
| $matches); | |||||
| if ($ok) { | |||||
| return $matches[1]; | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private function getIssueRawKind() { | |||||
| $raw = $this->raw; | |||||
| return idxv($raw, array('type')); | |||||
| } | |||||
| private function getRawIssueNumber() { | |||||
| $raw = $this->raw; | $raw = $this->raw; | ||||
| if ($this->type == self::TYPE_ISSUE) { | if ($this->type == self::TYPE_ISSUE) { | ||||
| return idxv($raw, array('issue', 'number')); | return idxv($raw, array('issue', 'number')); | ||||
| } | } | ||||
| if ($this->type == self::TYPE_REPOSITORY) { | if ($this->type == self::TYPE_REPOSITORY) { | ||||
| return idxv($raw, array('payload', 'issue', 'number')); | $issue_number = idxv($raw, array('payload', 'issue', 'number')); | ||||
| if ($issue_number) { | |||||
| return $issue_number; | |||||
| } | } | ||||
| return null; | $pull_number = idxv($raw, array('payload', 'number')); | ||||
| if ($pull_number) { | |||||
| return $pull_number; | |||||
| } | |||||
| } | } | ||||
| private function getRepositoryFullRawName() { | return null; | ||||
| $raw = $this->raw; | |||||
| return idxv($raw, array('repo', 'name')); | |||||
| } | } | ||||
| private function getIssueRawKind() { | private function getRawPullRequestData() { | ||||
| $raw = $this->raw; | $raw = $this->raw; | ||||
| return idxv($raw, array('type')); | return idxv($raw, array('payload', 'issue', 'pull_request')); | ||||
| } | } | ||||
| } | } | ||||