Changeset View
Changeset View
Standalone View
Standalone View
src/applications/nuance/github/NuanceGitHubRawEvent.php
| Show First 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | if ($this->isIssueEvent() || $this->isPullRequestEvent()) { | ||||
| } | } | ||||
| if ($need_anchor) { | if ($need_anchor) { | ||||
| $uri = $uri.'#event-'.$this->getID(); | $uri = $uri.'#event-'.$this->getID(); | ||||
| } | } | ||||
| } | } | ||||
| } else { | } else { | ||||
| switch ($this->getIssueRawKind()) { | switch ($this->getIssueRawKind()) { | ||||
| case 'CreateEvent': | |||||
| $ref = idxv($raw, array('payload', 'ref')); | |||||
| $repo = $this->getRepositoryFullRawName(); | |||||
| return "https://github.com/{$repo}/commits/{$ref}"; | |||||
| case 'PushEvent': | case 'PushEvent': | ||||
| // These don't really have a URI since there may be multiple commits | // These don't really have a URI since there may be multiple commits | ||||
| // involved and GitHub doesn't bundle the push as an object on its | // involved and GitHub doesn't bundle the push as an object on its | ||||
| // own. Just try to find the URI for the log. The API also does | // own. Just try to find the URI for the log. The API also does | ||||
| // not return any HTML URI for these events. | // not return any HTML URI for these events. | ||||
| $head = idxv($raw, array('payload', 'head')); | $head = idxv($raw, array('payload', 'head')); | ||||
| if ($head === null) { | if ($head === null) { | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | private function getRawIssueNumber() { | ||||
| return null; | return null; | ||||
| } | } | ||||
| private function getRawPullRequestData() { | private function getRawPullRequestData() { | ||||
| $raw = $this->raw; | $raw = $this->raw; | ||||
| return idxv($raw, array('payload', 'issue', 'pull_request')); | return idxv($raw, array('payload', 'issue', 'pull_request')); | ||||
| } | } | ||||
| public function getEventFullTitle() { | |||||
| switch ($this->type) { | |||||
| case self::TYPE_ISSUE: | |||||
| $title = $this->getRawIssueEventTitle(); | |||||
| break; | |||||
| case self::TYPE_REPOSITORY: | |||||
| $title = $this->getRawRepositoryEventTitle(); | |||||
| break; | |||||
| default: | |||||
| $title = pht('Unknown Event Type ("%s")', $this->type); | |||||
| break; | |||||
| } | |||||
| return pht( | |||||
| 'GitHub %s %s (%s)', | |||||
| $this->getRepositoryFullRawName(), | |||||
| $this->getTargetObjectName(), | |||||
| $title); | |||||
| } | |||||
| private function getTargetObjectName() { | |||||
| if ($this->isPullRequestEvent()) { | |||||
| $number = $this->getRawIssueNumber(); | |||||
| return pht('Pull Request #%d', $number); | |||||
| } else if ($this->isIssueEvent()) { | |||||
| $number = $this->getRawIssueNumber(); | |||||
| return pht('Issue #%d', $number); | |||||
| } else if ($this->type == self::TYPE_REPOSITORY) { | |||||
| $raw = $this->raw; | |||||
| $type = idx($raw, 'type'); | |||||
| switch ($type) { | |||||
| case 'CreateEvent': | |||||
| $ref = idxv($raw, array('payload', 'ref')); | |||||
| $ref_type = idxv($raw, array('payload', 'ref_type')); | |||||
| switch ($ref_type) { | |||||
| case 'branch': | |||||
| return pht('Branch %s', $ref); | |||||
| case 'tag': | |||||
| return pht('Tag %s', $ref); | |||||
| default: | |||||
| return pht('Ref %s', $ref); | |||||
| } | |||||
| break; | |||||
| case 'PushEvent': | |||||
| $ref = idxv($raw, array('payload', 'ref')); | |||||
| if (preg_match('(^refs/heads/)', $ref)) { | |||||
| return pht('Branch %s', substr($ref, strlen('refs/heads/'))); | |||||
| } else { | |||||
| return pht('Ref %s', $ref); | |||||
| } | |||||
| break; | |||||
| case 'WatchEvent': | |||||
| $actor = idxv($raw, array('actor', 'login')); | |||||
| return pht('User %s', $actor); | |||||
| } | |||||
| return pht('Unknown Object'); | |||||
| } else { | |||||
| return pht('Unknown Object'); | |||||
| } | |||||
| } | |||||
| private function getRawIssueEventTitle() { | |||||
| $raw = $this->raw; | |||||
| $action = idxv($raw, array('event')); | |||||
| switch ($action) { | |||||
| case 'assigned': | |||||
| $assignee = idxv($raw, array('assignee', 'login')); | |||||
| $title = pht('Assigned: %s', $assignee); | |||||
| break; | |||||
| case 'closed': | |||||
| $title = pht('Closed'); | |||||
| break; | |||||
| case 'demilestoned': | |||||
| $milestone = idxv($raw, array('milestone', 'title')); | |||||
| $title = pht('Removed Milestone: %s', $milestone); | |||||
| break; | |||||
| case 'labeled': | |||||
| $label = idxv($raw, array('label', 'name')); | |||||
| $title = pht('Added Label: %s', $label); | |||||
| break; | |||||
| case 'locked': | |||||
| $title = pht('Locked'); | |||||
| break; | |||||
| case 'milestoned': | |||||
| $milestone = idxv($raw, array('milestone', 'title')); | |||||
| $title = pht('Added Milestone: %s', $milestone); | |||||
| break; | |||||
| case 'renamed': | |||||
| $title = pht('Renamed'); | |||||
| break; | |||||
| case 'reopened': | |||||
| $title = pht('Reopened'); | |||||
| break; | |||||
| case 'unassigned': | |||||
| $assignee = idxv($raw, array('assignee', 'login')); | |||||
| $title = pht('Unassigned: %s', $assignee); | |||||
| break; | |||||
| case 'unlabeled': | |||||
| $label = idxv($raw, array('label', 'name')); | |||||
| $title = pht('Removed Label: %s', $label); | |||||
| break; | |||||
| case 'unlocked': | |||||
| $title = pht('Unlocked'); | |||||
| break; | |||||
| default: | |||||
| $title = pht('"%s"', $action); | |||||
| break; | |||||
| } | |||||
| return $title; | |||||
| } | |||||
| private function getRawRepositoryEventTitle() { | |||||
| $raw = $this->raw; | |||||
| $type = idx($raw, 'type'); | |||||
| switch ($type) { | |||||
| case 'CreateEvent': | |||||
| return pht('Created'); | |||||
| case 'PushEvent': | |||||
| $head = idxv($raw, array('payload', 'head')); | |||||
| $head = substr($head, 0, 12); | |||||
| return pht('Pushed: %s', $head); | |||||
| case 'IssuesEvent': | |||||
| $action = idxv($raw, array('payload', 'action')); | |||||
| switch ($action) { | |||||
| case 'closed': | |||||
| return pht('Closed'); | |||||
| case 'opened': | |||||
| return pht('Created'); | |||||
| case 'reopened': | |||||
| return pht('Reopened'); | |||||
| default: | |||||
| return pht('"%s"', $action); | |||||
| } | |||||
| break; | |||||
| case 'IssueCommentEvent': | |||||
| $action = idxv($raw, array('payload', 'action')); | |||||
| switch ($action) { | |||||
| case 'created': | |||||
| return pht('Comment'); | |||||
| default: | |||||
| return pht('"%s"', $action); | |||||
| } | |||||
| break; | |||||
| case 'PullRequestEvent': | |||||
| $action = idxv($raw, array('payload', 'action')); | |||||
| switch ($action) { | |||||
| case 'opened': | |||||
| return pht('Created'); | |||||
| default: | |||||
| return pht('"%s"', $action); | |||||
| } | |||||
| break; | |||||
| case 'WatchEvent': | |||||
| return pht('Watched'); | |||||
| } | |||||
| return pht('"%s"', $type); | |||||
| } | |||||
| } | } | ||||