Changeset View
Changeset View
Standalone View
Standalone View
src/applications/nuance/item/NuanceGitHubEventItemType.php
| Show All 10 Lines | public function getItemTypeDisplayName() { | ||||
| return pht('GitHub Event'); | return pht('GitHub Event'); | ||||
| } | } | ||||
| public function getItemTypeDisplayIcon() { | public function getItemTypeDisplayIcon() { | ||||
| return 'fa-github'; | return 'fa-github'; | ||||
| } | } | ||||
| public function getItemDisplayName(NuanceItem $item) { | public function getItemDisplayName(NuanceItem $item) { | ||||
| $api_type = $item->getItemProperty('api.type'); | return $this->newRawEvent($item)->getEventFullTitle(); | ||||
| switch ($api_type) { | |||||
| case 'issue': | |||||
| return $this->getGitHubIssueAPIEventDisplayName($item); | |||||
| case 'repository': | |||||
| return $this->getGitHubRepositoryAPIEventDisplayName($item); | |||||
| default: | |||||
| return pht('GitHub Event (Unknown API Type "%s")', $api_type); | |||||
| } | |||||
| } | |||||
| private function getGitHubIssueAPIEventDisplayName(NuanceItem $item) { | |||||
| $raw = $item->getItemProperty('api.raw', array()); | |||||
| $action = idxv($raw, array('event')); | |||||
| $number = idxv($raw, array('issue', 'number')); | |||||
| return pht('GitHub Issue #%d (%s)', $number, $action); | |||||
| } | |||||
| private function getGitHubRepositoryAPIEventDisplayName(NuanceItem $item) { | |||||
| $raw = $item->getItemProperty('api.raw', array()); | |||||
| $repo = idxv($raw, array('repo', 'name'), pht('<unknown/unknown>')); | |||||
| $type = idx($raw, 'type'); | |||||
| switch ($type) { | |||||
| case 'PushEvent': | |||||
| $head = idxv($raw, array('payload', 'head')); | |||||
| $head = substr($head, 0, 8); | |||||
| $name = pht('Push %s', $head); | |||||
| break; | |||||
| case 'IssuesEvent': | |||||
| $action = idxv($raw, array('payload', 'action')); | |||||
| $number = idxv($raw, array('payload', 'issue', 'number')); | |||||
| $name = pht('Issue #%d (%s)', $number, $action); | |||||
| break; | |||||
| case 'IssueCommentEvent': | |||||
| $action = idxv($raw, array('payload', 'action')); | |||||
| $number = idxv($raw, array('payload', 'issue', 'number')); | |||||
| $name = pht('Issue #%d (Comment, %s)', $number, $action); | |||||
| break; | |||||
| case 'PullRequestEvent': | |||||
| $action = idxv($raw, array('payload', 'action')); | |||||
| $number = idxv($raw, array('payload', 'pull_request', 'number')); | |||||
| $name = pht('Pull Request #%d (%s)', $number, $action); | |||||
| break; | |||||
| default: | |||||
| $name = pht('Unknown Event ("%s")', $type); | |||||
| break; | |||||
| } | |||||
| return pht('GitHub %s %s', $repo, $name); | |||||
| } | } | ||||
| public function canUpdateItems() { | public function canUpdateItems() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| protected function updateItemFromSource(NuanceItem $item) { | protected function updateItemFromSource(NuanceItem $item) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| ▲ Show 20 Lines • Show All 321 Lines • Show Last 20 Lines | |||||