Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/nuance/github/NuanceGitHubRawEvent.php b/src/applications/nuance/github/NuanceGitHubRawEvent.php
index 0e8fe44c2e..9e170bf092 100644
--- a/src/applications/nuance/github/NuanceGitHubRawEvent.php
+++ b/src/applications/nuance/github/NuanceGitHubRawEvent.php
@@ -1,199 +1,204 @@
<?php
final class NuanceGitHubRawEvent extends Phobject {
private $raw;
private $type;
const TYPE_ISSUE = 'issue';
const TYPE_REPOSITORY = 'repository';
public static function newEvent($type, array $raw) {
$event = new self();
$event->type = $type;
$event->raw = $raw;
return $event;
}
public function getRepositoryFullName() {
return $this->getRepositoryFullRawName();
}
public function isIssueEvent() {
if ($this->isPullRequestEvent()) {
return false;
}
if ($this->type == self::TYPE_ISSUE) {
return true;
}
switch ($this->getIssueRawKind()) {
case 'IssuesEvent':
return true;
case 'IssueCommentEvent':
if (!$this->getRawPullRequestData()) {
return true;
}
break;
}
return false;
}
public function isPullRequestEvent() {
if ($this->type == self::TYPE_ISSUE) {
// TODO: This is wrong, some of these are pull events.
return false;
}
$raw = $this->raw;
switch ($this->getIssueRawKind()) {
case 'PullRequestEvent':
return true;
case 'IssueCommentEvent':
if ($this->getRawPullRequestData()) {
return true;
}
break;
}
return false;
}
public function getIssueNumber() {
if (!$this->isIssueEvent()) {
return null;
}
return $this->getRawIssueNumber();
}
public function getPullRequestNumber() {
if (!$this->isPullRequestEvent()) {
return null;
}
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->isIssueEvent() || $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'));
+ $need_anchor = true;
+
+ // For comments, we get a different anchor to link to the comment. In
+ // this case, the URI comes with an anchor already.
+ if (!$uri) {
+ $uri = idxv($raw, array('payload', 'comment', 'html_url'));
+ $need_anchor = false;
+ }
+
if (!$uri) {
$uri = idxv($raw, array('payload', 'issue', 'html_url'));
+ $need_anchor = true;
+ }
+
+ if ($need_anchor) {
+ $uri = $uri.'#event-'.$this->getID();
}
- $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;
$full = idxv($raw, array('repo', 'name'));
if (strlen($full)) {
return $full;
}
// For issue events, the repository is not identified explicitly in the
// response body. Parse it out of the URI.
$matches = null;
$ok = preg_match(
'(/repos/((?:[^/]+)/(?:[^/]+))/issues/events/)',
idx($raw, 'url'),
$matches);
if ($ok) {
return $matches[1];
}
return null;
}
private function getIssueRawKind() {
$raw = $this->raw;
return idxv($raw, array('type'));
}
private function getRawIssueNumber() {
$raw = $this->raw;
if ($this->type == self::TYPE_ISSUE) {
return idxv($raw, array('issue', 'number'));
}
if ($this->type == self::TYPE_REPOSITORY) {
$issue_number = idxv($raw, array('payload', 'issue', 'number'));
if ($issue_number) {
return $issue_number;
}
$pull_number = idxv($raw, array('payload', 'number'));
if ($pull_number) {
return $pull_number;
}
}
return null;
}
private function getRawPullRequestData() {
$raw = $this->raw;
return idxv($raw, array('payload', 'issue', 'pull_request'));
}
}
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 9c784f21be..7b3e7d3708 100644
--- a/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.pull.txt
+++ b/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.pull.txt
@@ -1,163 +1,163 @@
{
"id": "3740938746",
"type": "IssueCommentEvent",
"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": {
"action": "created",
"issue": {
"url": "https://api.github.com/repos/epriestley/poems/issues/2",
"repository_url": "https://api.github.com/repos/epriestley/poems",
"labels_url": "https://api.github.com/repos/epriestley/poems/issues/2/labels{/name}",
"comments_url": "https://api.github.com/repos/epriestley/poems/issues/2/comments",
"events_url": "https://api.github.com/repos/epriestley/poems/issues/2/events",
"html_url": "https://github.com/epriestley/poems/pull/2",
"id": 139568860,
"number": 2,
"title": "Please Merge Quack2 into Feature",
"user": {
"login": "epriestley",
"id": 102631,
"avatar_url": "https://avatars.githubusercontent.com/u/102631?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/epriestley",
"html_url": "https://github.com/epriestley",
"followers_url": "https://api.github.com/users/epriestley/followers",
"following_url": "https://api.github.com/users/epriestley/following{/other_user}",
"gists_url": "https://api.github.com/users/epriestley/gists{/gist_id}",
"starred_url": "https://api.github.com/users/epriestley/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/epriestley/subscriptions",
"organizations_url": "https://api.github.com/users/epriestley/orgs",
"repos_url": "https://api.github.com/users/epriestley/repos",
"events_url": "https://api.github.com/users/epriestley/events{/privacy}",
"received_events_url": "https://api.github.com/users/epriestley/received_events",
"type": "User",
"site_admin": false
},
"labels": [
{
"url": "https://api.github.com/repos/epriestley/poems/labels/bug",
"name": "bug",
"color": "fc2929"
}
],
"state": "open",
"locked": false,
"assignee": {
"login": "epriestley",
"id": 102631,
"avatar_url": "https://avatars.githubusercontent.com/u/102631?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/epriestley",
"html_url": "https://github.com/epriestley",
"followers_url": "https://api.github.com/users/epriestley/followers",
"following_url": "https://api.github.com/users/epriestley/following{/other_user}",
"gists_url": "https://api.github.com/users/epriestley/gists{/gist_id}",
"starred_url": "https://api.github.com/users/epriestley/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/epriestley/subscriptions",
"organizations_url": "https://api.github.com/users/epriestley/orgs",
"repos_url": "https://api.github.com/users/epriestley/repos",
"events_url": "https://api.github.com/users/epriestley/events{/privacy}",
"received_events_url": "https://api.github.com/users/epriestley/received_events",
"type": "User",
"site_admin": false
},
"milestone": {
"url": "https://api.github.com/repos/epriestley/poems/milestones/1",
"html_url": "https://github.com/epriestley/poems/milestones/b",
"labels_url": "https://api.github.com/repos/epriestley/poems/milestones/1/labels",
"id": 1633589,
"number": 1,
"title": "b",
"description": null,
"creator": {
"login": "epriestley",
"id": 102631,
"avatar_url": "https://avatars.githubusercontent.com/u/102631?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/epriestley",
"html_url": "https://github.com/epriestley",
"followers_url": "https://api.github.com/users/epriestley/followers",
"following_url": "https://api.github.com/users/epriestley/following{/other_user}",
"gists_url": "https://api.github.com/users/epriestley/gists{/gist_id}",
"starred_url": "https://api.github.com/users/epriestley/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/epriestley/subscriptions",
"organizations_url": "https://api.github.com/users/epriestley/orgs",
"repos_url": "https://api.github.com/users/epriestley/repos",
"events_url": "https://api.github.com/users/epriestley/events{/privacy}",
"received_events_url": "https://api.github.com/users/epriestley/received_events",
"type": "User",
"site_admin": false
},
"open_issues": 1,
"closed_issues": 0,
"state": "open",
"created_at": "2016-03-09T12:42:50Z",
"updated_at": "2016-03-09T12:52:41Z",
"due_on": null,
"closed_at": null
},
"comments": 1,
"created_at": "2016-03-09T12:52:31Z",
"updated_at": "2016-03-09T12:53:06Z",
"closed_at": null,
"pull_request": {
"url": "https://api.github.com/repos/epriestley/poems/pulls/2",
"html_url": "https://github.com/epriestley/poems/pull/2",
"diff_url": "https://github.com/epriestley/poems/pull/2.diff",
"patch_url": "https://github.com/epriestley/poems/pull/2.patch"
},
"body": ""
},
"comment": {
"url": "https://api.github.com/repos/epriestley/poems/issues/comments/194282800",
"html_url": "https://github.com/epriestley/poems/pull/2#issuecomment-194282800",
"issue_url": "https://api.github.com/repos/epriestley/poems/issues/2",
"id": 194282800,
"user": {
"login": "epriestley",
"id": 102631,
"avatar_url": "https://avatars.githubusercontent.com/u/102631?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/epriestley",
"html_url": "https://github.com/epriestley",
"followers_url": "https://api.github.com/users/epriestley/followers",
"following_url": "https://api.github.com/users/epriestley/following{/other_user}",
"gists_url": "https://api.github.com/users/epriestley/gists{/gist_id}",
"starred_url": "https://api.github.com/users/epriestley/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/epriestley/subscriptions",
"organizations_url": "https://api.github.com/users/epriestley/orgs",
"repos_url": "https://api.github.com/users/epriestley/repos",
"events_url": "https://api.github.com/users/epriestley/events{/privacy}",
"received_events_url": "https://api.github.com/users/epriestley/received_events",
"type": "User",
"site_admin": false
},
"created_at": "2016-03-09T12:53:06Z",
"updated_at": "2016-03-09T12:53:06Z",
"body": "wub wub"
}
},
"public": true,
"created_at": "2016-03-09T12:53:06Z"
}
~~~~~
{
"repository.name.full": "epriestley/poems",
"is.issue": false,
"is.pull": true,
"issue.number": null,
"pull.number": 2,
"id": 3740938746,
- "uri": "https://github.com/epriestley/poems/pull/2#event-3740938746"
+ "uri": "https://github.com/epriestley/poems/pull/2#issuecomment-194282800"
}
diff --git a/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.txt b/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.txt
index b5034ef453..acb40f0971 100644
--- a/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.txt
+++ b/src/applications/nuance/github/__tests__/repositoryevents/IssueCommentEvent.created.txt
@@ -1,100 +1,100 @@
{
"id": "3733510485",
"type": "IssueCommentEvent",
"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": {
"action": "created",
"issue": {
"url": "https://api.github.com/repos/epriestley/poems/issues/1",
"repository_url": "https://api.github.com/repos/epriestley/poems",
"labels_url": "https://api.github.com/repos/epriestley/poems/issues/1/labels{/name}",
"comments_url": "https://api.github.com/repos/epriestley/poems/issues/1/comments",
"events_url": "https://api.github.com/repos/epriestley/poems/issues/1/events",
"html_url": "https://github.com/epriestley/poems/issues/1",
"id": 139138813,
"number": 1,
"title": "Enforce haiku in commit messages",
"user": {
"login": "epriestley",
"id": 102631,
"avatar_url": "https://avatars.githubusercontent.com/u/102631?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/epriestley",
"html_url": "https://github.com/epriestley",
"followers_url": "https://api.github.com/users/epriestley/followers",
"following_url": "https://api.github.com/users/epriestley/following{/other_user}",
"gists_url": "https://api.github.com/users/epriestley/gists{/gist_id}",
"starred_url": "https://api.github.com/users/epriestley/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/epriestley/subscriptions",
"organizations_url": "https://api.github.com/users/epriestley/orgs",
"repos_url": "https://api.github.com/users/epriestley/repos",
"events_url": "https://api.github.com/users/epriestley/events{/privacy}",
"received_events_url": "https://api.github.com/users/epriestley/received_events",
"type": "User",
"site_admin": false
},
"labels": [
],
"state": "open",
"locked": false,
"assignee": null,
"milestone": null,
"comments": 1,
"created_at": "2016-03-08T00:41:08Z",
"updated_at": "2016-03-08T00:41:22Z",
"closed_at": null,
"body": "OK"
},
"comment": {
"url": "https://api.github.com/repos/epriestley/poems/issues/comments/193528669",
"html_url": "https://github.com/epriestley/poems/issues/1#issuecomment-193528669",
"issue_url": "https://api.github.com/repos/epriestley/poems/issues/1",
"id": 193528669,
"user": {
"login": "epriestley",
"id": 102631,
"avatar_url": "https://avatars.githubusercontent.com/u/102631?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/epriestley",
"html_url": "https://github.com/epriestley",
"followers_url": "https://api.github.com/users/epriestley/followers",
"following_url": "https://api.github.com/users/epriestley/following{/other_user}",
"gists_url": "https://api.github.com/users/epriestley/gists{/gist_id}",
"starred_url": "https://api.github.com/users/epriestley/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/epriestley/subscriptions",
"organizations_url": "https://api.github.com/users/epriestley/orgs",
"repos_url": "https://api.github.com/users/epriestley/repos",
"events_url": "https://api.github.com/users/epriestley/events{/privacy}",
"received_events_url": "https://api.github.com/users/epriestley/received_events",
"type": "User",
"site_admin": false
},
"created_at": "2016-03-08T00:41:22Z",
"updated_at": "2016-03-08T00:41:22Z",
"body": "comment on issue"
}
},
"public": true,
"created_at": "2016-03-08T00:41:22Z"
}
~~~~~
{
"repository.name.full": "epriestley/poems",
"is.issue": true,
"is.pull": false,
"issue.number": 1,
"id": 3733510485,
- "uri": "https://github.com/epriestley/poems/issues/1#event-3733510485"
+ "uri": "https://github.com/epriestley/poems/issues/1#issuecomment-193528669"
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Apr 7, 9:07 AM (22 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1166056
Default Alt Text
(18 KB)

Event Timeline