@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.

Improve rendering of many GitHub event strings

Summary: Ref T10538. This makes us render better human-readable descriptions of more GitHub event types.

Test Plan: Ran unit tests.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10538

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

+249 -72
+172
src/applications/nuance/github/NuanceGitHubRawEvent.php
··· 125 125 } 126 126 } else { 127 127 switch ($this->getIssueRawKind()) { 128 + case 'CreateEvent': 129 + $ref = idxv($raw, array('payload', 'ref')); 130 + 131 + $repo = $this->getRepositoryFullRawName(); 132 + return "https://github.com/{$repo}/commits/{$ref}"; 128 133 case 'PushEvent': 129 134 // These don't really have a URI since there may be multiple commits 130 135 // involved and GitHub doesn't bundle the push as an object on its ··· 203 208 private function getRawPullRequestData() { 204 209 $raw = $this->raw; 205 210 return idxv($raw, array('payload', 'issue', 'pull_request')); 211 + } 212 + 213 + public function getEventFullTitle() { 214 + switch ($this->type) { 215 + case self::TYPE_ISSUE: 216 + $title = $this->getRawIssueEventTitle(); 217 + break; 218 + case self::TYPE_REPOSITORY: 219 + $title = $this->getRawRepositoryEventTitle(); 220 + break; 221 + default: 222 + $title = pht('Unknown Event Type ("%s")', $this->type); 223 + break; 224 + } 225 + 226 + return pht( 227 + 'GitHub %s %s (%s)', 228 + $this->getRepositoryFullRawName(), 229 + $this->getTargetObjectName(), 230 + $title); 231 + } 232 + 233 + private function getTargetObjectName() { 234 + if ($this->isPullRequestEvent()) { 235 + $number = $this->getRawIssueNumber(); 236 + return pht('Pull Request #%d', $number); 237 + } else if ($this->isIssueEvent()) { 238 + $number = $this->getRawIssueNumber(); 239 + return pht('Issue #%d', $number); 240 + } else if ($this->type == self::TYPE_REPOSITORY) { 241 + $raw = $this->raw; 242 + 243 + 244 + $type = idx($raw, 'type'); 245 + switch ($type) { 246 + case 'CreateEvent': 247 + $ref = idxv($raw, array('payload', 'ref')); 248 + $ref_type = idxv($raw, array('payload', 'ref_type')); 249 + 250 + switch ($ref_type) { 251 + case 'branch': 252 + return pht('Branch %s', $ref); 253 + case 'tag': 254 + return pht('Tag %s', $ref); 255 + default: 256 + return pht('Ref %s', $ref); 257 + } 258 + break; 259 + case 'PushEvent': 260 + $ref = idxv($raw, array('payload', 'ref')); 261 + if (preg_match('(^refs/heads/)', $ref)) { 262 + return pht('Branch %s', substr($ref, strlen('refs/heads/'))); 263 + } else { 264 + return pht('Ref %s', $ref); 265 + } 266 + break; 267 + case 'WatchEvent': 268 + $actor = idxv($raw, array('actor', 'login')); 269 + return pht('User %s', $actor); 270 + } 271 + 272 + return pht('Unknown Object'); 273 + } else { 274 + return pht('Unknown Object'); 275 + } 276 + } 277 + 278 + private function getRawIssueEventTitle() { 279 + $raw = $this->raw; 280 + 281 + $action = idxv($raw, array('event')); 282 + switch ($action) { 283 + case 'assigned': 284 + $assignee = idxv($raw, array('assignee', 'login')); 285 + $title = pht('Assigned: %s', $assignee); 286 + break; 287 + case 'closed': 288 + $title = pht('Closed'); 289 + break; 290 + case 'demilestoned': 291 + $milestone = idxv($raw, array('milestone', 'title')); 292 + $title = pht('Removed Milestone: %s', $milestone); 293 + break; 294 + case 'labeled': 295 + $label = idxv($raw, array('label', 'name')); 296 + $title = pht('Added Label: %s', $label); 297 + break; 298 + case 'locked': 299 + $title = pht('Locked'); 300 + break; 301 + case 'milestoned': 302 + $milestone = idxv($raw, array('milestone', 'title')); 303 + $title = pht('Added Milestone: %s', $milestone); 304 + break; 305 + case 'renamed': 306 + $title = pht('Renamed'); 307 + break; 308 + case 'reopened': 309 + $title = pht('Reopened'); 310 + break; 311 + case 'unassigned': 312 + $assignee = idxv($raw, array('assignee', 'login')); 313 + $title = pht('Unassigned: %s', $assignee); 314 + break; 315 + case 'unlabeled': 316 + $label = idxv($raw, array('label', 'name')); 317 + $title = pht('Removed Label: %s', $label); 318 + break; 319 + case 'unlocked': 320 + $title = pht('Unlocked'); 321 + break; 322 + default: 323 + $title = pht('"%s"', $action); 324 + break; 325 + } 326 + 327 + 328 + return $title; 329 + } 330 + 331 + private function getRawRepositoryEventTitle() { 332 + $raw = $this->raw; 333 + 334 + $type = idx($raw, 'type'); 335 + switch ($type) { 336 + case 'CreateEvent': 337 + return pht('Created'); 338 + case 'PushEvent': 339 + $head = idxv($raw, array('payload', 'head')); 340 + $head = substr($head, 0, 12); 341 + return pht('Pushed: %s', $head); 342 + case 'IssuesEvent': 343 + $action = idxv($raw, array('payload', 'action')); 344 + switch ($action) { 345 + case 'closed': 346 + return pht('Closed'); 347 + case 'opened': 348 + return pht('Created'); 349 + case 'reopened': 350 + return pht('Reopened'); 351 + default: 352 + return pht('"%s"', $action); 353 + } 354 + break; 355 + case 'IssueCommentEvent': 356 + $action = idxv($raw, array('payload', 'action')); 357 + switch ($action) { 358 + case 'created': 359 + return pht('Comment'); 360 + default: 361 + return pht('"%s"', $action); 362 + } 363 + break; 364 + case 'PullRequestEvent': 365 + $action = idxv($raw, array('payload', 'action')); 366 + switch ($action) { 367 + case 'opened': 368 + return pht('Created'); 369 + default: 370 + return pht('"%s"', $action); 371 + } 372 + break; 373 + case 'WatchEvent': 374 + return pht('Watched'); 375 + } 376 + 377 + return pht('"%s"', $type); 206 378 } 207 379 208 380 }
+1
src/applications/nuance/github/__tests__/NuanceGitHubRawEventTestCase.php
··· 50 50 'pull.number' => $event->getPullRequestNumber(), 51 51 'id' => $event->getID(), 52 52 'uri' => $event->getURI(), 53 + 'title.full' => $event->getEventFullTitle(), 53 54 ); 54 55 55 56 // Only verify the keys which are actually present in the test. This
+2 -1
src/applications/nuance/github/__tests__/issueevents/assigned.txt
··· 112 112 "is.pull": false, 113 113 "issue.number": 1, 114 114 "id": 583217900, 115 - "uri": "https://github.com/epriestley/poems/issues/1#event-583217900" 115 + "uri": "https://github.com/epriestley/poems/issues/1#event-583217900", 116 + "title.full": "GitHub epriestley/poems Issue #1 (Assigned: epriestley)" 116 117 }
+2 -1
src/applications/nuance/github/__tests__/issueevents/closed.txt
··· 74 74 "is.pull": false, 75 75 "issue.number": 1, 76 76 "id": 583218864, 77 - "uri": "https://github.com/epriestley/poems/issues/1#event-583218864" 77 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218864", 78 + "title.full": "GitHub epriestley/poems Issue #1 (Closed)" 78 79 }
+2 -1
src/applications/nuance/github/__tests__/issueevents/demilestoned.txt
··· 77 77 "is.pull": false, 78 78 "issue.number": 1, 79 79 "id": 583218613, 80 - "uri": "https://github.com/epriestley/poems/issues/1#event-583218613" 80 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218613", 81 + "title.full": "GitHub epriestley/poems Issue #1 (Removed Milestone: b)" 81 82 }
+2 -1
src/applications/nuance/github/__tests__/issueevents/labeled.txt
··· 78 78 "is.pull": false, 79 79 "issue.number": 1, 80 80 "id": 583217784, 81 - "uri": "https://github.com/epriestley/poems/issues/1#event-583217784" 81 + "uri": "https://github.com/epriestley/poems/issues/1#event-583217784", 82 + "title.full": "GitHub epriestley/poems Issue #1 (Added Label: bug)" 82 83 }
+2 -1
src/applications/nuance/github/__tests__/issueevents/locked.txt
··· 74 74 "is.pull": false, 75 75 "issue.number": 1, 76 76 "id": 583218006, 77 - "uri": "https://github.com/epriestley/poems/issues/1#event-583218006" 77 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218006", 78 + "title.full": "GitHub epriestley/poems Issue #1 (Locked)" 78 79 }
+2 -1
src/applications/nuance/github/__tests__/issueevents/milestoned.txt
··· 77 77 "is.pull": false, 78 78 "issue.number": 1, 79 79 "id": 583217866, 80 - "uri": "https://github.com/epriestley/poems/issues/1#event-583217866" 80 + "uri": "https://github.com/epriestley/poems/issues/1#event-583217866", 81 + "title.full": "GitHub epriestley/poems Issue #1 (Added Milestone: b)" 81 82 }
+2 -1
src/applications/nuance/github/__tests__/issueevents/renamed.txt
··· 78 78 "is.pull": false, 79 79 "issue.number": 1, 80 80 "id": 583218162, 81 - "uri": "https://github.com/epriestley/poems/issues/1#event-583218162" 81 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218162", 82 + "title.full": "GitHub epriestley/poems Issue #1 (Renamed)" 82 83 }
+2 -1
src/applications/nuance/github/__tests__/issueevents/reopened.txt
··· 74 74 "is.pull": false, 75 75 "issue.number": 1, 76 76 "id": 583218814, 77 - "uri": "https://github.com/epriestley/poems/issues/1#event-583218814" 77 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218814", 78 + "title.full": "GitHub epriestley/poems Issue #1 (Reopened)" 78 79 }
+2 -1
src/applications/nuance/github/__tests__/issueevents/unassigned.txt
··· 112 112 "is.pull": false, 113 113 "issue.number": 1, 114 114 "id": 583218511, 115 - "uri": "https://github.com/epriestley/poems/issues/1#event-583218511" 115 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218511", 116 + "title.full": "GitHub epriestley/poems Issue #1 (Unassigned: epriestley)" 116 117 }
+2 -1
src/applications/nuance/github/__tests__/issueevents/unlabeled.txt
··· 78 78 "is.pull": false, 79 79 "issue.number": 1, 80 80 "id": 583218703, 81 - "uri": "https://github.com/epriestley/poems/issues/1#event-583218703" 81 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218703", 82 + "title.full": "GitHub epriestley/poems Issue #1 (Removed Label: bug)" 82 83 }
+2 -1
src/applications/nuance/github/__tests__/issueevents/unlocked.txt
··· 74 74 "is.pull": false, 75 75 "issue.number": 1, 76 76 "id": 583218062, 77 - "uri": "https://github.com/epriestley/poems/issues/1#event-583218062" 77 + "uri": "https://github.com/epriestley/poems/issues/1#event-583218062", 78 + "title.full": "GitHub epriestley/poems Issue #1 (Unlocked)" 78 79 }
+37
src/applications/nuance/github/__tests__/repositoryevents/CreateEvent.tag.txt
··· 1 + { 2 + "id": "3784548642", 3 + "type": "CreateEvent", 4 + "actor": { 5 + "id": 102631, 6 + "login": "epriestley", 7 + "gravatar_id": "", 8 + "url": "https://api.github.com/users/epriestley", 9 + "avatar_url": "https://avatars.githubusercontent.com/u/102631?" 10 + }, 11 + "repo": { 12 + "id": 14627834, 13 + "name": "epriestley/poems", 14 + "url": "https://api.github.com/repos/epriestley/poems" 15 + }, 16 + "payload": { 17 + "ref": "phabricator/diff/400", 18 + "ref_type": "tag", 19 + "master_branch": "master", 20 + "description": "Poems (Mirror)", 21 + "pusher_type": "user" 22 + }, 23 + "public": true, 24 + "created_at": "2016-03-19T22:07:56Z" 25 + } 26 + 27 + ~~~~~ 28 + { 29 + "repository.name.full": "epriestley/poems", 30 + "is.issue": false, 31 + "is.pull": false, 32 + "issue.number": null, 33 + "pull.number": null, 34 + "id": 3784548642, 35 + "uri": "https://github.com/epriestley/poems/commits/phabricator/diff/400", 36 + "title.full": "GitHub epriestley/poems Tag phabricator/diff/400 (Created)" 37 + }
+2 -1
src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.pull.txt
··· 159 159 "issue.number": null, 160 160 "pull.number": 2, 161 161 "id": 3740938746, 162 - "uri": "https://github.com/epriestley/poems/pull/2#issuecomment-194282800" 162 + "uri": "https://github.com/epriestley/poems/pull/2#issuecomment-194282800", 163 + "title.full": "GitHub epriestley/poems Pull Request #2 (Comment)" 163 164 }
+2 -1
src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.txt
··· 96 96 "is.pull": false, 97 97 "issue.number": 1, 98 98 "id": 3733510485, 99 - "uri": "https://github.com/epriestley/poems/issues/1#issuecomment-193528669" 99 + "uri": "https://github.com/epriestley/poems/issues/1#issuecomment-193528669", 100 + "title.full": "GitHub epriestley/poems Issue #1 (Comment)" 100 101 }
+2 -1
src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.closed.txt
··· 68 68 "is.pull": false, 69 69 "issue.number": 1, 70 70 "id": 3740905151, 71 - "uri": "https://github.com/epriestley/poems/issues/1#event-3740905151" 71 + "uri": "https://github.com/epriestley/poems/issues/1#event-3740905151", 72 + "title.full": "GitHub epriestley/poems Issue #1 (Closed)" 72 73 }
+2 -1
src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.opened.txt
··· 68 68 "is.pull": false, 69 69 "issue.number": 1, 70 70 "id": 3733509737, 71 - "uri": "https://github.com/epriestley/poems/issues/1#event-3733509737" 71 + "uri": "https://github.com/epriestley/poems/issues/1#event-3733509737", 72 + "title.full": "GitHub epriestley/poems Issue #1 (Created)" 72 73 }
+2 -1
src/applications/nuance/github/__tests__/repositoryevents/IssuesEvent.reopened.txt
··· 68 68 "is.pull": false, 69 69 "issue.number": 1, 70 70 "id": 3740908680, 71 - "uri": "https://github.com/epriestley/poems/issues/1#event-3740908680" 71 + "uri": "https://github.com/epriestley/poems/issues/1#event-3740908680", 72 + "title.full": "GitHub epriestley/poems Issue #1 (Reopened)" 72 73 }
+2 -1
src/applications/nuance/github/__tests__/repositoryevents/PullRequestEvent.opened.txt
··· 332 332 "issue.number": null, 333 333 "pull.number": 2, 334 334 "id": 3740936638, 335 - "uri": "https://github.com/epriestley/poems/pull/2#event-3740936638" 335 + "uri": "https://github.com/epriestley/poems/pull/2#event-3740936638", 336 + "title.full": "GitHub epriestley/poems Pull Request #2 (Created)" 336 337 }
+2 -1
src/applications/nuance/github/__tests__/repositoryevents/PushEvent.txt
··· 43 43 "is.pull": false, 44 44 "issue.number": null, 45 45 "id": 3498724127, 46 - "uri": "https://github.com/epriestley/poems/commits/c829132d37c4c1da80d319942a5a1e500632b52f" 46 + "uri": "https://github.com/epriestley/poems/commits/c829132d37c4c1da80d319942a5a1e500632b52f", 47 + "title.full": "GitHub epriestley/poems Branch master (Pushed: c829132d37c4)" 47 48 }
+2 -1
src/applications/nuance/github/__tests__/repositoryevents/WatchEvent.started.txt
··· 27 27 "issue.number": null, 28 28 "pull.number": null, 29 29 "id": 3740950917, 30 - "uri": null 30 + "uri": null, 31 + "title.full": "GitHub epriestley/poems User epriestley (Watched)" 31 32 }
+1 -53
src/applications/nuance/item/NuanceGitHubEventItemType.php
··· 16 16 } 17 17 18 18 public function getItemDisplayName(NuanceItem $item) { 19 - $api_type = $item->getItemProperty('api.type'); 20 - switch ($api_type) { 21 - case 'issue': 22 - return $this->getGitHubIssueAPIEventDisplayName($item); 23 - case 'repository': 24 - return $this->getGitHubRepositoryAPIEventDisplayName($item); 25 - default: 26 - return pht('GitHub Event (Unknown API Type "%s")', $api_type); 27 - } 28 - } 29 - 30 - private function getGitHubIssueAPIEventDisplayName(NuanceItem $item) { 31 - $raw = $item->getItemProperty('api.raw', array()); 32 - 33 - $action = idxv($raw, array('event')); 34 - $number = idxv($raw, array('issue', 'number')); 35 - 36 - return pht('GitHub Issue #%d (%s)', $number, $action); 37 - } 38 - 39 - private function getGitHubRepositoryAPIEventDisplayName(NuanceItem $item) { 40 - $raw = $item->getItemProperty('api.raw', array()); 41 - 42 - $repo = idxv($raw, array('repo', 'name'), pht('<unknown/unknown>')); 43 - 44 - $type = idx($raw, 'type'); 45 - switch ($type) { 46 - case 'PushEvent': 47 - $head = idxv($raw, array('payload', 'head')); 48 - $head = substr($head, 0, 8); 49 - $name = pht('Push %s', $head); 50 - break; 51 - case 'IssuesEvent': 52 - $action = idxv($raw, array('payload', 'action')); 53 - $number = idxv($raw, array('payload', 'issue', 'number')); 54 - $name = pht('Issue #%d (%s)', $number, $action); 55 - break; 56 - case 'IssueCommentEvent': 57 - $action = idxv($raw, array('payload', 'action')); 58 - $number = idxv($raw, array('payload', 'issue', 'number')); 59 - $name = pht('Issue #%d (Comment, %s)', $number, $action); 60 - break; 61 - case 'PullRequestEvent': 62 - $action = idxv($raw, array('payload', 'action')); 63 - $number = idxv($raw, array('payload', 'pull_request', 'number')); 64 - $name = pht('Pull Request #%d (%s)', $number, $action); 65 - break; 66 - default: 67 - $name = pht('Unknown Event ("%s")', $type); 68 - break; 69 - } 70 - 71 - return pht('GitHub %s %s', $repo, $name); 19 + return $this->newRawEvent($item)->getEventFullTitle(); 72 20 } 73 21 74 22 public function canUpdateItems() {