@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add very basic item rendering for GitHub events, parse IDs + URIs

Summary: Ref T10538. This extracts and renders URIs for GitHub events so we can link to the original thing on GitHub.

Test Plan: {F1186332}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10538

Differential Revision: https://secure.phabricator.com/D15505

+165 -20
+62
src/applications/nuance/github/NuanceGitHubRawEvent.php
··· 78 78 return $this->getRawIssueNumber(); 79 79 } 80 80 81 + 82 + public function getID() { 83 + $raw = $this->raw; 84 + 85 + $id = idx($raw, 'id'); 86 + if ($id) { 87 + return (int)$id; 88 + } 89 + 90 + return null; 91 + } 92 + 93 + public function getURI() { 94 + $raw = $this->raw; 95 + 96 + if ($this->isIssueEvent()) { 97 + if ($this->type == self::TYPE_ISSUE) { 98 + $uri = idxv($raw, array('issue', 'html_url')); 99 + $uri = $uri.'#event-'.$this->getID(); 100 + } else { 101 + $uri = idxv($raw, array('payload', 'issue', 'html_url')); 102 + $uri = $uri.'#event-'.$this->getID(); 103 + } 104 + } else if ($this->isPullRequestEvent()) { 105 + if ($this->type == self::TYPE_ISSUE) { 106 + $uri = idxv($raw, array('issue', 'html_url')); 107 + $uri = $uri.'#event-'.$this->getID(); 108 + } else { 109 + // The format of pull request events varies so we need to fish around 110 + // a bit to find the correct URI. 111 + $uri = idxv($raw, array('payload', 'pull_request', 'html_url')); 112 + if (!$uri) { 113 + $uri = idxv($raw, array('payload', 'issue', 'html_url')); 114 + } 115 + $uri = $uri.'#event-'.$this->getID(); 116 + } 117 + } else { 118 + switch ($this->getIssueRawKind()) { 119 + case 'PushEvent': 120 + // These don't really have a URI since there may be multiple commits 121 + // involved and GitHub doesn't bundle the push as an object on its 122 + // own. Just try to find the URI for the log. The API also does 123 + // not return any HTML URI for these events. 124 + 125 + $head = idxv($raw, array('payload', 'head')); 126 + if ($head === null) { 127 + return null; 128 + } 129 + 130 + $repo = $this->getRepositoryFullRawName(); 131 + return "https://github.com/{$repo}/commits/{$head}"; 132 + case 'WatchEvent': 133 + // These have no reasonable URI. 134 + return null; 135 + default: 136 + return null; 137 + } 138 + } 139 + 140 + return $uri; 141 + } 142 + 81 143 private function getRepositoryFullRawName() { 82 144 $raw = $this->raw; 83 145
+2
src/applications/nuance/github/__tests__/NuanceGitHubRawEventTestCase.php
··· 48 48 'is.pull' => $event->isPullRequestEvent(), 49 49 'issue.number' => $event->getIssueNumber(), 50 50 'pull.number' => $event->getPullRequestNumber(), 51 + 'id' => $event->getID(), 52 + 'uri' => $event->getURI(), 51 53 ); 52 54 53 55 // Only verify the keys which are actually present in the test. This
+3 -1
src/applications/nuance/github/__tests__/issueevents/assigned.txt
··· 110 110 "repository.name.full": "epriestley/poems", 111 111 "is.issue": true, 112 112 "is.pull": false, 113 - "issue.number": 1 113 + "issue.number": 1, 114 + "id": 583217900, 115 + "uri": "https://github.com/epriestley/poems/issues/1#event-583217900" 114 116 }
+3 -1
src/applications/nuance/github/__tests__/issueevents/closed.txt
··· 72 72 "repository.name.full": "epriestley/poems", 73 73 "is.issue": true, 74 74 "is.pull": false, 75 - "issue.number": 1 75 + "issue.number": 1, 76 + "id": 583218864, 77 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218864" 76 78 }
+3 -1
src/applications/nuance/github/__tests__/issueevents/demilestoned.txt
··· 75 75 "repository.name.full": "epriestley/poems", 76 76 "is.issue": true, 77 77 "is.pull": false, 78 - "issue.number": 1 78 + "issue.number": 1, 79 + "id": 583218613, 80 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218613" 79 81 }
+3 -1
src/applications/nuance/github/__tests__/issueevents/labeled.txt
··· 76 76 "repository.name.full": "epriestley/poems", 77 77 "is.issue": true, 78 78 "is.pull": false, 79 - "issue.number": 1 79 + "issue.number": 1, 80 + "id": 583217784, 81 + "uri": "https://github.com/epriestley/poems/issues/1#event-583217784" 80 82 }
+3 -1
src/applications/nuance/github/__tests__/issueevents/locked.txt
··· 72 72 "repository.name.full": "epriestley/poems", 73 73 "is.issue": true, 74 74 "is.pull": false, 75 - "issue.number": 1 75 + "issue.number": 1, 76 + "id": 583218006, 77 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218006" 76 78 }
+3 -1
src/applications/nuance/github/__tests__/issueevents/milestoned.txt
··· 75 75 "repository.name.full": "epriestley/poems", 76 76 "is.issue": true, 77 77 "is.pull": false, 78 - "issue.number": 1 78 + "issue.number": 1, 79 + "id": 583217866, 80 + "uri": "https://github.com/epriestley/poems/issues/1#event-583217866" 79 81 }
+3 -1
src/applications/nuance/github/__tests__/issueevents/renamed.txt
··· 76 76 "repository.name.full": "epriestley/poems", 77 77 "is.issue": true, 78 78 "is.pull": false, 79 - "issue.number": 1 79 + "issue.number": 1, 80 + "id": 583218162, 81 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218162" 80 82 }
+3 -1
src/applications/nuance/github/__tests__/issueevents/reopened.txt
··· 72 72 "repository.name.full": "epriestley/poems", 73 73 "is.issue": true, 74 74 "is.pull": false, 75 - "issue.number": 1 75 + "issue.number": 1, 76 + "id": 583218814, 77 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218814" 76 78 }
+3 -1
src/applications/nuance/github/__tests__/issueevents/unassigned.txt
··· 110 110 "repository.name.full": "epriestley/poems", 111 111 "is.issue": true, 112 112 "is.pull": false, 113 - "issue.number": 1 113 + "issue.number": 1, 114 + "id": 583218511, 115 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218511" 114 116 }
+3 -1
src/applications/nuance/github/__tests__/issueevents/unlabeled.txt
··· 76 76 "repository.name.full": "epriestley/poems", 77 77 "is.issue": true, 78 78 "is.pull": false, 79 - "issue.number": 1 79 + "issue.number": 1, 80 + "id": 583218703, 81 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218703" 80 82 }
+3 -1
src/applications/nuance/github/__tests__/issueevents/unlocked.txt
··· 72 72 "repository.name.full": "epriestley/poems", 73 73 "is.issue": true, 74 74 "is.pull": false, 75 - "issue.number": 1 75 + "issue.number": 1, 76 + "id": 583218062, 77 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218062" 76 78 }
+3 -1
src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.pull.txt
··· 157 157 "is.issue": false, 158 158 "is.pull": true, 159 159 "issue.number": null, 160 - "pull.number": 2 160 + "pull.number": 2, 161 + "id": 3740938746, 162 + "uri": "https://github.com/epriestley/poems/pull/2#event-3740938746" 161 163 }
+3 -1
src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.txt
··· 94 94 "repository.name.full": "epriestley/poems", 95 95 "is.issue": true, 96 96 "is.pull": false, 97 - "issue.number": 1 97 + "issue.number": 1, 98 + "id": 3733510485, 99 + "uri": "https://github.com/epriestley/poems/issues/1#event-3733510485" 98 100 }
+3 -1
src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.closed.txt
··· 66 66 "repository.name.full": "epriestley/poems", 67 67 "is.issue": true, 68 68 "is.pull": false, 69 - "issue.number": 1 69 + "issue.number": 1, 70 + "id": 3740905151, 71 + "uri": "https://github.com/epriestley/poems/issues/1#event-3740905151" 70 72 }
+3 -1
src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.opened.txt
··· 66 66 "repository.name.full": "epriestley/poems", 67 67 "is.issue": true, 68 68 "is.pull": false, 69 - "issue.number": 1 69 + "issue.number": 1, 70 + "id": 3733509737, 71 + "uri": "https://github.com/epriestley/poems/issues/1#event-3733509737" 70 72 }
+3 -1
src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.reopened.txt
··· 66 66 "repository.name.full": "epriestley/poems", 67 67 "is.issue": true, 68 68 "is.pull": false, 69 - "issue.number": 1 69 + "issue.number": 1, 70 + "id": 3740908680, 71 + "uri": "https://github.com/epriestley/poems/issues/1#event-3740908680" 70 72 }
+3 -1
src/applications/nuance/github/__tests__/repositoryevents/PullRequestEvent.opened.txt
··· 330 330 "is.issue": false, 331 331 "is.pull": true, 332 332 "issue.number": null, 333 - "pull.number": 2 333 + "pull.number": 2, 334 + "id": 3740936638, 335 + "uri": "https://github.com/epriestley/poems/pull/2#event-3740936638" 334 336 }
+3 -1
src/applications/nuance/github/__tests__/repositoryevents/PushEvent.txt
··· 41 41 "repository.name.full": "epriestley/poems", 42 42 "is.issue": false, 43 43 "is.pull": false, 44 - "issue.number": null 44 + "issue.number": null, 45 + "id": 3498724127, 46 + "uri": "https://github.com/epriestley/poems/commits/c829132d37c4c1da80d319942a5a1e500632b52f" 45 47 }
+3 -1
src/applications/nuance/github/__tests__/repositoryevents/WatchEvent.started.txt
··· 25 25 "is.issue": false, 26 26 "is.pull": false, 27 27 "issue.number": null, 28 - "pull.number": null 28 + "pull.number": null, 29 + "id": 3740950917, 30 + "uri": null 29 31 }
+43
src/applications/nuance/item/NuanceGitHubEventItemType.php
··· 186 186 return null; 187 187 } 188 188 189 + protected function newItemView(NuanceItem $item) { 190 + $content = array(); 191 + 192 + $content[] = $this->newGitHubEventItemPropertyBox($item); 193 + 194 + return $content; 195 + } 196 + 197 + private function newGitHubEventItemPropertyBox($item) { 198 + $viewer = $this->getViewer(); 199 + 200 + $property_list = id(new PHUIPropertyListView()) 201 + ->setViewer($viewer); 202 + 203 + $event = $this->newRawEvent($item); 204 + 205 + $property_list->addProperty( 206 + pht('GitHub Event ID'), 207 + $event->getID()); 208 + 209 + $event_uri = $event->getURI(); 210 + if ($event_uri && PhabricatorEnv::isValidRemoteURIForLink($event_uri)) { 211 + $event_uri = phutil_tag( 212 + 'a', 213 + array( 214 + 'href' => $event_uri, 215 + ), 216 + $event_uri); 217 + } 218 + 219 + if ($event_uri) { 220 + $property_list->addProperty( 221 + pht('GitHub Event URI'), 222 + $event_uri); 223 + } 224 + 225 + return id(new PHUIObjectBoxView()) 226 + ->setHeaderText(pht('Event Properties')) 227 + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 228 + ->appendChild($property_list); 229 + } 230 + 231 + 189 232 }
+1 -1
src/applications/nuance/item/NuanceItemType.php
··· 32 32 return $this->newItemView($item); 33 33 } 34 34 35 - protected function newItemView() { 35 + protected function newItemView(NuanceItem $item) { 36 36 return null; 37 37 } 38 38