diff --git a/src/applications/nuance/github/NuanceGitHubRawEvent.php b/src/applications/nuance/github/NuanceGitHubRawEvent.php index 50ab9020ef..0e8fe44c2e 100644 --- a/src/applications/nuance/github/NuanceGitHubRawEvent.php +++ b/src/applications/nuance/github/NuanceGitHubRawEvent.php @@ -78,6 +78,68 @@ final class NuanceGitHubRawEvent extends Phobject { return $this->getRawIssueNumber(); } + + public function getID() { + $raw = $this->raw; + + $id = idx($raw, 'id'); + if ($id) { + return (int)$id; + } + + return null; + } + + public function getURI() { + $raw = $this->raw; + + if ($this->isIssueEvent()) { + if ($this->type == self::TYPE_ISSUE) { + $uri = idxv($raw, array('issue', 'html_url')); + $uri = $uri.'#event-'.$this->getID(); + } else { + $uri = idxv($raw, array('payload', 'issue', 'html_url')); + $uri = $uri.'#event-'.$this->getID(); + } + } else if ($this->isPullRequestEvent()) { + if ($this->type == self::TYPE_ISSUE) { + $uri = idxv($raw, array('issue', 'html_url')); + $uri = $uri.'#event-'.$this->getID(); + } else { + // The format of pull request events varies so we need to fish around + // a bit to find the correct URI. + $uri = idxv($raw, array('payload', 'pull_request', 'html_url')); + if (!$uri) { + $uri = idxv($raw, array('payload', 'issue', 'html_url')); + } + $uri = $uri.'#event-'.$this->getID(); + } + } else { + switch ($this->getIssueRawKind()) { + case 'PushEvent': + // 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 + // own. Just try to find the URI for the log. The API also does + // not return any HTML URI for these events. + + $head = idxv($raw, array('payload', 'head')); + if ($head === null) { + return null; + } + + $repo = $this->getRepositoryFullRawName(); + return "https://github.com/{$repo}/commits/{$head}"; + case 'WatchEvent': + // These have no reasonable URI. + return null; + default: + return null; + } + } + + return $uri; + } + private function getRepositoryFullRawName() { $raw = $this->raw; diff --git a/src/applications/nuance/github/__tests__/NuanceGitHubRawEventTestCase.php b/src/applications/nuance/github/__tests__/NuanceGitHubRawEventTestCase.php index f956079b6a..5ce199cb8c 100644 --- a/src/applications/nuance/github/__tests__/NuanceGitHubRawEventTestCase.php +++ b/src/applications/nuance/github/__tests__/NuanceGitHubRawEventTestCase.php @@ -48,6 +48,8 @@ final class NuanceGitHubRawEventTestCase 'is.pull' => $event->isPullRequestEvent(), 'issue.number' => $event->getIssueNumber(), 'pull.number' => $event->getPullRequestNumber(), + 'id' => $event->getID(), + 'uri' => $event->getURI(), ); // Only verify the keys which are actually present in the test. This diff --git a/src/applications/nuance/github/__tests__/issueevents/assigned.txt b/src/applications/nuance/github/__tests__/issueevents/assigned.txt index bdf5046e00..7c1c89435f 100644 --- a/src/applications/nuance/github/__tests__/issueevents/assigned.txt +++ b/src/applications/nuance/github/__tests__/issueevents/assigned.txt @@ -110,5 +110,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583217900, + "uri": "https://github.com/epriestley/poems/issues/1#event-583217900" } diff --git a/src/applications/nuance/github/__tests__/issueevents/closed.txt b/src/applications/nuance/github/__tests__/issueevents/closed.txt index 7651d07172..e13c9a1ffd 100644 --- a/src/applications/nuance/github/__tests__/issueevents/closed.txt +++ b/src/applications/nuance/github/__tests__/issueevents/closed.txt @@ -72,5 +72,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583218864, + "uri": "https://github.com/epriestley/poems/issues/1#event-583218864" } diff --git a/src/applications/nuance/github/__tests__/issueevents/demilestoned.txt b/src/applications/nuance/github/__tests__/issueevents/demilestoned.txt index bbde0e7d24..1c9bab5725 100644 --- a/src/applications/nuance/github/__tests__/issueevents/demilestoned.txt +++ b/src/applications/nuance/github/__tests__/issueevents/demilestoned.txt @@ -75,5 +75,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583218613, + "uri": "https://github.com/epriestley/poems/issues/1#event-583218613" } diff --git a/src/applications/nuance/github/__tests__/issueevents/labeled.txt b/src/applications/nuance/github/__tests__/issueevents/labeled.txt index bf41262ac4..92cd7cd4f0 100644 --- a/src/applications/nuance/github/__tests__/issueevents/labeled.txt +++ b/src/applications/nuance/github/__tests__/issueevents/labeled.txt @@ -76,5 +76,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583217784, + "uri": "https://github.com/epriestley/poems/issues/1#event-583217784" } diff --git a/src/applications/nuance/github/__tests__/issueevents/locked.txt b/src/applications/nuance/github/__tests__/issueevents/locked.txt index 440eec0d95..536d95af8e 100644 --- a/src/applications/nuance/github/__tests__/issueevents/locked.txt +++ b/src/applications/nuance/github/__tests__/issueevents/locked.txt @@ -72,5 +72,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583218006, + "uri": "https://github.com/epriestley/poems/issues/1#event-583218006" } diff --git a/src/applications/nuance/github/__tests__/issueevents/milestoned.txt b/src/applications/nuance/github/__tests__/issueevents/milestoned.txt index e8b32b1113..748beddda9 100644 --- a/src/applications/nuance/github/__tests__/issueevents/milestoned.txt +++ b/src/applications/nuance/github/__tests__/issueevents/milestoned.txt @@ -75,5 +75,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583217866, + "uri": "https://github.com/epriestley/poems/issues/1#event-583217866" } diff --git a/src/applications/nuance/github/__tests__/issueevents/renamed.txt b/src/applications/nuance/github/__tests__/issueevents/renamed.txt index 0cbbd1ebb8..e4a4614ebb 100644 --- a/src/applications/nuance/github/__tests__/issueevents/renamed.txt +++ b/src/applications/nuance/github/__tests__/issueevents/renamed.txt @@ -76,5 +76,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583218162, + "uri": "https://github.com/epriestley/poems/issues/1#event-583218162" } diff --git a/src/applications/nuance/github/__tests__/issueevents/reopened.txt b/src/applications/nuance/github/__tests__/issueevents/reopened.txt index bc778728d8..baab332450 100644 --- a/src/applications/nuance/github/__tests__/issueevents/reopened.txt +++ b/src/applications/nuance/github/__tests__/issueevents/reopened.txt @@ -72,5 +72,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583218814, + "uri": "https://github.com/epriestley/poems/issues/1#event-583218814" } diff --git a/src/applications/nuance/github/__tests__/issueevents/unassigned.txt b/src/applications/nuance/github/__tests__/issueevents/unassigned.txt index bc8b9e1df9..43c610b576 100644 --- a/src/applications/nuance/github/__tests__/issueevents/unassigned.txt +++ b/src/applications/nuance/github/__tests__/issueevents/unassigned.txt @@ -110,5 +110,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583218511, + "uri": "https://github.com/epriestley/poems/issues/1#event-583218511" } diff --git a/src/applications/nuance/github/__tests__/issueevents/unlabeled.txt b/src/applications/nuance/github/__tests__/issueevents/unlabeled.txt index e3435605e0..8d40ba5702 100644 --- a/src/applications/nuance/github/__tests__/issueevents/unlabeled.txt +++ b/src/applications/nuance/github/__tests__/issueevents/unlabeled.txt @@ -76,5 +76,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583218703, + "uri": "https://github.com/epriestley/poems/issues/1#event-583218703" } diff --git a/src/applications/nuance/github/__tests__/issueevents/unlocked.txt b/src/applications/nuance/github/__tests__/issueevents/unlocked.txt index e59ba6e93f..080fbd79e8 100644 --- a/src/applications/nuance/github/__tests__/issueevents/unlocked.txt +++ b/src/applications/nuance/github/__tests__/issueevents/unlocked.txt @@ -72,5 +72,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 583218062, + "uri": "https://github.com/epriestley/poems/issues/1#event-583218062" } diff --git a/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.pull.txt b/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.pull.txt index 0068f7c092..9c784f21be 100644 --- a/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.pull.txt +++ b/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.pull.txt @@ -157,5 +157,7 @@ "is.issue": false, "is.pull": true, "issue.number": null, - "pull.number": 2 + "pull.number": 2, + "id": 3740938746, + "uri": "https://github.com/epriestley/poems/pull/2#event-3740938746" } diff --git a/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.txt b/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.txt index c6fa5ccb54..b5034ef453 100644 --- a/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.txt +++ b/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.txt @@ -94,5 +94,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 3733510485, + "uri": "https://github.com/epriestley/poems/issues/1#event-3733510485" } diff --git a/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.closed.txt b/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.closed.txt index 8373e2ee52..78fc81be95 100644 --- a/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.closed.txt +++ b/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.closed.txt @@ -66,5 +66,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 3740905151, + "uri": "https://github.com/epriestley/poems/issues/1#event-3740905151" } diff --git a/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.opened.txt b/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.opened.txt index 91068727e7..7ba07a591b 100644 --- a/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.opened.txt +++ b/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.opened.txt @@ -66,5 +66,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 3733509737, + "uri": "https://github.com/epriestley/poems/issues/1#event-3733509737" } diff --git a/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.reopened.txt b/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.reopened.txt index 6ab81e1028..797eb84078 100644 --- a/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.reopened.txt +++ b/src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.reopened.txt @@ -66,5 +66,7 @@ "repository.name.full": "epriestley/poems", "is.issue": true, "is.pull": false, - "issue.number": 1 + "issue.number": 1, + "id": 3740908680, + "uri": "https://github.com/epriestley/poems/issues/1#event-3740908680" } diff --git a/src/applications/nuance/github/__tests__/repositoryevents/PullRequestEvent.opened.txt b/src/applications/nuance/github/__tests__/repositoryevents/PullRequestEvent.opened.txt index 848ed63afe..c2f892f090 100644 --- a/src/applications/nuance/github/__tests__/repositoryevents/PullRequestEvent.opened.txt +++ b/src/applications/nuance/github/__tests__/repositoryevents/PullRequestEvent.opened.txt @@ -330,5 +330,7 @@ "is.issue": false, "is.pull": true, "issue.number": null, - "pull.number": 2 + "pull.number": 2, + "id": 3740936638, + "uri": "https://github.com/epriestley/poems/pull/2#event-3740936638" } diff --git a/src/applications/nuance/github/__tests__/repositoryevents/PushEvent.txt b/src/applications/nuance/github/__tests__/repositoryevents/PushEvent.txt index f36fed2f52..d7c1b5ecad 100644 --- a/src/applications/nuance/github/__tests__/repositoryevents/PushEvent.txt +++ b/src/applications/nuance/github/__tests__/repositoryevents/PushEvent.txt @@ -41,5 +41,7 @@ "repository.name.full": "epriestley/poems", "is.issue": false, "is.pull": false, - "issue.number": null + "issue.number": null, + "id": 3498724127, + "uri": "https://github.com/epriestley/poems/commits/c829132d37c4c1da80d319942a5a1e500632b52f" } diff --git a/src/applications/nuance/github/__tests__/repositoryevents/WatchEvent.started.txt b/src/applications/nuance/github/__tests__/repositoryevents/WatchEvent.started.txt index 7cc6ed8164..c65a5ee771 100644 --- a/src/applications/nuance/github/__tests__/repositoryevents/WatchEvent.started.txt +++ b/src/applications/nuance/github/__tests__/repositoryevents/WatchEvent.started.txt @@ -25,5 +25,7 @@ "is.issue": false, "is.pull": false, "issue.number": null, - "pull.number": null + "pull.number": null, + "id": 3740950917, + "uri": null } diff --git a/src/applications/nuance/item/NuanceGitHubEventItemType.php b/src/applications/nuance/item/NuanceGitHubEventItemType.php index cec3d366ec..dd52dc1c15 100644 --- a/src/applications/nuance/item/NuanceGitHubEventItemType.php +++ b/src/applications/nuance/item/NuanceGitHubEventItemType.php @@ -186,4 +186,47 @@ final class NuanceGitHubEventItemType return null; } + protected function newItemView(NuanceItem $item) { + $content = array(); + + $content[] = $this->newGitHubEventItemPropertyBox($item); + + return $content; + } + + private function newGitHubEventItemPropertyBox($item) { + $viewer = $this->getViewer(); + + $property_list = id(new PHUIPropertyListView()) + ->setViewer($viewer); + + $event = $this->newRawEvent($item); + + $property_list->addProperty( + pht('GitHub Event ID'), + $event->getID()); + + $event_uri = $event->getURI(); + if ($event_uri && PhabricatorEnv::isValidRemoteURIForLink($event_uri)) { + $event_uri = phutil_tag( + 'a', + array( + 'href' => $event_uri, + ), + $event_uri); + } + + if ($event_uri) { + $property_list->addProperty( + pht('GitHub Event URI'), + $event_uri); + } + + return id(new PHUIObjectBoxView()) + ->setHeaderText(pht('Event Properties')) + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) + ->appendChild($property_list); + } + + } diff --git a/src/applications/nuance/item/NuanceItemType.php b/src/applications/nuance/item/NuanceItemType.php index 2f348dee1f..14b2fc5324 100644 --- a/src/applications/nuance/item/NuanceItemType.php +++ b/src/applications/nuance/item/NuanceItemType.php @@ -32,7 +32,7 @@ abstract class NuanceItemType return $this->newItemView($item); } - protected function newItemView() { + protected function newItemView(NuanceItem $item) { return null; }