mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
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
This commit is contained in:
parent
e523585811
commit
a90daf5d30
23 changed files with 165 additions and 20 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -25,5 +25,7 @@
|
|||
"is.issue": false,
|
||||
"is.pull": false,
|
||||
"issue.number": null,
|
||||
"pull.number": null
|
||||
"pull.number": null,
|
||||
"id": 3740950917,
|
||||
"uri": null
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ abstract class NuanceItemType
|
|||
return $this->newItemView($item);
|
||||
}
|
||||
|
||||
protected function newItemView() {
|
||||
protected function newItemView(NuanceItem $item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue