mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
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
This commit is contained in:
parent
b193796266
commit
7cfc87bbe6
23 changed files with 249 additions and 72 deletions
|
@ -125,6 +125,11 @@ final class NuanceGitHubRawEvent extends Phobject {
|
|||
}
|
||||
} else {
|
||||
switch ($this->getIssueRawKind()) {
|
||||
case 'CreateEvent':
|
||||
$ref = idxv($raw, array('payload', 'ref'));
|
||||
|
||||
$repo = $this->getRepositoryFullRawName();
|
||||
return "https://github.com/{$repo}/commits/{$ref}";
|
||||
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
|
||||
|
@ -205,4 +210,171 @@ final class NuanceGitHubRawEvent extends Phobject {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ final class NuanceGitHubRawEventTestCase
|
|||
'pull.number' => $event->getPullRequestNumber(),
|
||||
'id' => $event->getID(),
|
||||
'uri' => $event->getURI(),
|
||||
'title.full' => $event->getEventFullTitle(),
|
||||
);
|
||||
|
||||
// Only verify the keys which are actually present in the test. This
|
||||
|
|
|
@ -112,5 +112,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583217900,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583217900"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583217900",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Assigned: epriestley)"
|
||||
}
|
||||
|
|
|
@ -74,5 +74,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583218864,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218864"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218864",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Closed)"
|
||||
}
|
||||
|
|
|
@ -77,5 +77,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583218613,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218613"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218613",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Removed Milestone: b)"
|
||||
}
|
||||
|
|
|
@ -78,5 +78,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583217784,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583217784"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583217784",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Added Label: bug)"
|
||||
}
|
||||
|
|
|
@ -74,5 +74,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583218006,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218006"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218006",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Locked)"
|
||||
}
|
||||
|
|
|
@ -77,5 +77,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583217866,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583217866"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583217866",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Added Milestone: b)"
|
||||
}
|
||||
|
|
|
@ -78,5 +78,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583218162,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218162"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218162",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Renamed)"
|
||||
}
|
||||
|
|
|
@ -74,5 +74,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583218814,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218814"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218814",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Reopened)"
|
||||
}
|
||||
|
|
|
@ -112,5 +112,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583218511,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218511"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218511",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Unassigned: epriestley)"
|
||||
}
|
||||
|
|
|
@ -78,5 +78,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583218703,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218703"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218703",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Removed Label: bug)"
|
||||
}
|
||||
|
|
|
@ -74,5 +74,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 583218062,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218062"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-583218062",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Unlocked)"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"id": "3784548642",
|
||||
"type": "CreateEvent",
|
||||
"actor": {
|
||||
"id": 102631,
|
||||
"login": "epriestley",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/epriestley",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/102631?"
|
||||
},
|
||||
"repo": {
|
||||
"id": 14627834,
|
||||
"name": "epriestley/poems",
|
||||
"url": "https://api.github.com/repos/epriestley/poems"
|
||||
},
|
||||
"payload": {
|
||||
"ref": "phabricator/diff/400",
|
||||
"ref_type": "tag",
|
||||
"master_branch": "master",
|
||||
"description": "Poems (Mirror)",
|
||||
"pusher_type": "user"
|
||||
},
|
||||
"public": true,
|
||||
"created_at": "2016-03-19T22:07:56Z"
|
||||
}
|
||||
|
||||
~~~~~
|
||||
{
|
||||
"repository.name.full": "epriestley/poems",
|
||||
"is.issue": false,
|
||||
"is.pull": false,
|
||||
"issue.number": null,
|
||||
"pull.number": null,
|
||||
"id": 3784548642,
|
||||
"uri": "https://github.com/epriestley/poems/commits/phabricator/diff/400",
|
||||
"title.full": "GitHub epriestley/poems Tag phabricator/diff/400 (Created)"
|
||||
}
|
|
@ -159,5 +159,6 @@
|
|||
"issue.number": null,
|
||||
"pull.number": 2,
|
||||
"id": 3740938746,
|
||||
"uri": "https://github.com/epriestley/poems/pull/2#issuecomment-194282800"
|
||||
"uri": "https://github.com/epriestley/poems/pull/2#issuecomment-194282800",
|
||||
"title.full": "GitHub epriestley/poems Pull Request #2 (Comment)"
|
||||
}
|
||||
|
|
|
@ -96,5 +96,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 3733510485,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#issuecomment-193528669"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#issuecomment-193528669",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Comment)"
|
||||
}
|
||||
|
|
|
@ -68,5 +68,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 3740905151,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-3740905151"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-3740905151",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Closed)"
|
||||
}
|
||||
|
|
|
@ -68,5 +68,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 3733509737,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-3733509737"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-3733509737",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Created)"
|
||||
}
|
||||
|
|
|
@ -68,5 +68,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": 1,
|
||||
"id": 3740908680,
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-3740908680"
|
||||
"uri": "https://github.com/epriestley/poems/issues/1#event-3740908680",
|
||||
"title.full": "GitHub epriestley/poems Issue #1 (Reopened)"
|
||||
}
|
||||
|
|
|
@ -332,5 +332,6 @@
|
|||
"issue.number": null,
|
||||
"pull.number": 2,
|
||||
"id": 3740936638,
|
||||
"uri": "https://github.com/epriestley/poems/pull/2#event-3740936638"
|
||||
"uri": "https://github.com/epriestley/poems/pull/2#event-3740936638",
|
||||
"title.full": "GitHub epriestley/poems Pull Request #2 (Created)"
|
||||
}
|
||||
|
|
|
@ -43,5 +43,6 @@
|
|||
"is.pull": false,
|
||||
"issue.number": null,
|
||||
"id": 3498724127,
|
||||
"uri": "https://github.com/epriestley/poems/commits/c829132d37c4c1da80d319942a5a1e500632b52f"
|
||||
"uri": "https://github.com/epriestley/poems/commits/c829132d37c4c1da80d319942a5a1e500632b52f",
|
||||
"title.full": "GitHub epriestley/poems Branch master (Pushed: c829132d37c4)"
|
||||
}
|
||||
|
|
|
@ -27,5 +27,6 @@
|
|||
"issue.number": null,
|
||||
"pull.number": null,
|
||||
"id": 3740950917,
|
||||
"uri": null
|
||||
"uri": null,
|
||||
"title.full": "GitHub epriestley/poems User epriestley (Watched)"
|
||||
}
|
||||
|
|
|
@ -16,59 +16,7 @@ final class NuanceGitHubEventItemType
|
|||
}
|
||||
|
||||
public function getItemDisplayName(NuanceItem $item) {
|
||||
$api_type = $item->getItemProperty('api.type');
|
||||
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);
|
||||
return $this->newRawEvent($item)->getEventFullTitle();
|
||||
}
|
||||
|
||||
public function canUpdateItems() {
|
||||
|
|
Loading…
Reference in a new issue