From 04390e560909f9becf0fdf007ebb244558e019da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dandelion=20Man=C3=A9?=
Date: Thu, 10 May 2018 11:34:53 -0700
Subject: [PATCH] Add CONTAINS edges from Repositories to Issues/PRs (#253)
Also updates the GitHub porcelain.
Existing observable behavior is unchanged, except that performance may
be improved for issueOrPrByNumber.
A bug that would afflict a multi-repository graph (namely, that calling
`repo.issues()` would get all issues for all repositories) is
pre-emptively removed. No test cases were added as we do not yet support
multi-repository graphs.
Test plan: existing unit test coverage is sufficient.
---
.../github/__snapshots__/parser.test.js.snap | 221 ++++++++++++++++++
src/plugins/github/parser.js | 24 +-
src/plugins/github/porcelain.js | 41 ++--
3 files changed, 263 insertions(+), 23 deletions(-)
diff --git a/src/plugins/github/__snapshots__/parser.test.js.snap b/src/plugins/github/__snapshots__/parser.test.js.snap
index 3653dee..01cce5b 100644
--- a/src/plugins/github/__snapshots__/parser.test.js.snap
+++ b/src/plugins/github/__snapshots__/parser.test.js.snap
@@ -16,6 +16,19 @@ Object {
"type": "ISSUE",
},
},
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/1\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/1",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
},
"nodes": Object {
"{\\"id\\":\\"https://github.com/decentralion\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"AUTHOR\\"}": Object {
@@ -138,6 +151,19 @@ Object {
"type": "ISSUE",
},
},
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/6\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/6",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
},
"nodes": Object {
"{\\"id\\":\\"https://github.com/decentralion\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"AUTHOR\\"}": Object {
@@ -267,6 +293,19 @@ Object {
"type": "PULL_REQUEST",
},
},
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/pull/5\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/pull/5",
+ "pluginName": "sourcecred/github-beta",
+ "type": "PULL_REQUEST",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
"{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/wchargin\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"AUTHOR\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/pull/5#discussion_r171460198\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW_COMMENT\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"AUTHORS\\"}": Object {
"dst": Object {
"id": "https://github.com/wchargin",
@@ -422,6 +461,19 @@ Object {
"type": "PULL_REQUEST",
},
},
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/pull/3\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/pull/3",
+ "pluginName": "sourcecred/github-beta",
+ "type": "PULL_REQUEST",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
},
"nodes": Object {
"{\\"id\\":\\"https://github.com/decentralion\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"AUTHOR\\"}": Object {
@@ -862,6 +914,45 @@ Object {
"type": "ISSUE",
},
},
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/1\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/1",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/2\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/2",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/6\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/6",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
},
"nodes": Object {
"{\\"id\\":\\"https://github.com/decentralion\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"AUTHOR\\"}": Object {
@@ -1217,6 +1308,19 @@ Object {
"type": "ISSUE",
},
},
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/2\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/2",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
},
"nodes": Object {
"{\\"id\\":\\"https://github.com/decentralion\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"AUTHOR\\"}": Object {
@@ -2010,6 +2114,123 @@ Object {
"type": "PULL_REQUEST",
},
},
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/1\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/1",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/2\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/2",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/4\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/4",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/6\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/6",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/7\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/7",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/issues/8\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/issues/8",
+ "pluginName": "sourcecred/github-beta",
+ "type": "ISSUE",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/pull/3\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/pull/3",
+ "pluginName": "sourcecred/github-beta",
+ "type": "PULL_REQUEST",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/pull/5\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/pull/5",
+ "pluginName": "sourcecred/github-beta",
+ "type": "PULL_REQUEST",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
+ "{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"REPOSITORY\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/pull/9\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"CONTAINS\\"}": Object {
+ "dst": Object {
+ "id": "https://github.com/sourcecred/example-github/pull/9",
+ "pluginName": "sourcecred/github-beta",
+ "type": "PULL_REQUEST",
+ },
+ "payload": Object {},
+ "src": Object {
+ "id": "https://github.com/sourcecred/example-github",
+ "pluginName": "sourcecred/github-beta",
+ "type": "REPOSITORY",
+ },
+ },
"{\\"id\\":\\"[{\\\\\\"id\\\\\\":\\\\\\"https://github.com/wchargin\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"AUTHOR\\\\\\"},{\\\\\\"id\\\\\\":\\\\\\"https://github.com/sourcecred/example-github/pull/5#discussion_r171460198\\\\\\",\\\\\\"pluginName\\\\\\":\\\\\\"sourcecred/github-beta\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW_COMMENT\\\\\\"}]\\",\\"pluginName\\":\\"sourcecred/github-beta\\",\\"type\\":\\"AUTHORS\\"}": Object {
"dst": Object {
"id": "https://github.com/wchargin",
diff --git a/src/plugins/github/parser.js b/src/plugins/github/parser.js
index 73234c0..e0076f9 100644
--- a/src/plugins/github/parser.js
+++ b/src/plugins/github/parser.js
@@ -166,9 +166,14 @@ class GithubParser {
addContainment(
parentNode: Node<
- IssueNodePayload | PullRequestNodePayload | PullRequestReviewNodePayload
+ | IssueNodePayload
+ | PullRequestNodePayload
+ | PullRequestReviewNodePayload
+ | RepositoryNodePayload
>,
childNode: Node<
+ | IssueNodePayload
+ | PullRequestNodePayload
| CommentNodePayload
| PullRequestReviewCommentNodePayload
| PullRequestReviewNodePayload
@@ -187,7 +192,7 @@ class GithubParser {
this.graph.addEdge(containsEdge);
}
- addIssue(issueJson: IssueJSON) {
+ addIssue(repoNode: Node, issueJson: IssueJSON) {
const issuePayload: IssueNodePayload = {
url: issueJson.url,
number: issueJson.number,
@@ -201,11 +206,15 @@ class GithubParser {
this.graph.addNode(issueNode);
this.addAuthorship(issueNode, issueJson.author);
+ this.addContainment(repoNode, issueNode);
issueJson.comments.nodes.forEach((c) => this.addComment(issueNode, c));
}
- addPullRequest(prJson: PullRequestJSON) {
+ addPullRequest(
+ repoNode: Node,
+ prJson: PullRequestJSON
+ ) {
const pullRequestPayload: PullRequestNodePayload = {
url: prJson.url,
number: prJson.number,
@@ -219,6 +228,7 @@ class GithubParser {
this.graph.addNode(pullRequestNode);
this.addAuthorship(pullRequestNode, prJson.author);
+ this.addContainment(repoNode, pullRequestNode);
prJson.comments.nodes.forEach((c) => this.addComment(pullRequestNode, c));
prJson.reviews.nodes.forEach((r) =>
@@ -338,8 +348,12 @@ class GithubParser {
payload: repositoryPayload,
};
this.graph.addNode(repositoryNode);
- repositoryJSON.issues.nodes.forEach((i) => this.addIssue(i));
- repositoryJSON.pullRequests.nodes.forEach((pr) => this.addPullRequest(pr));
+ repositoryJSON.issues.nodes.forEach((issue) =>
+ this.addIssue(repositoryNode, issue)
+ );
+ repositoryJSON.pullRequests.nodes.forEach((pr) =>
+ this.addPullRequest(repositoryNode, pr)
+ );
}
addData(dataJson: GithubResponseJSON) {
diff --git a/src/plugins/github/porcelain.js b/src/plugins/github/porcelain.js
index a4280ed..c63612e 100644
--- a/src/plugins/github/porcelain.js
+++ b/src/plugins/github/porcelain.js
@@ -172,22 +172,19 @@ export class Repository extends GithubEntity {
assertEntityType(e, REPOSITORY_NODE_TYPE);
return (e: any);
}
- // TODO: Now that the Repository is a node in the graph, re-write methods
- // that find issues and PRs to find neighbors of the repository rather than
- // any matching nodes in the graph. Then, behavior will be correct in the
- // case where we have multiple repositories in the same graph.
+
issueOrPRByNumber(number: number): ?(Issue | PullRequest) {
let result: Issue | PullRequest;
- this.graph.nodes({type: ISSUE_NODE_TYPE}).forEach((n) => {
- if (n.payload.number === number) {
- result = new Issue(this.graph, n.address);
- }
- });
- this.graph.nodes({type: PULL_REQUEST_NODE_TYPE}).forEach((n) => {
- if (n.payload.number === number) {
- result = new PullRequest(this.graph, n.address);
- }
- });
+ this.graph
+ .neighborhood(this.nodeAddress, {
+ edgeType: CONTAINS_EDGE_TYPE,
+ })
+ .forEach(({neighbor}) => {
+ const payload = this.graph.node(neighbor).payload;
+ if (payload.number === number) {
+ result = (asEntity(this.graph, neighbor): any);
+ }
+ });
return result;
}
@@ -201,14 +198,22 @@ export class Repository extends GithubEntity {
issues(): Issue[] {
return this.graph
- .nodes({type: ISSUE_NODE_TYPE})
- .map((n) => new Issue(this.graph, n.address));
+ .neighborhood(this.nodeAddress, {
+ direction: "OUT",
+ edgeType: CONTAINS_EDGE_TYPE,
+ nodeType: ISSUE_NODE_TYPE,
+ })
+ .map(({neighbor}) => new Issue(this.graph, neighbor));
}
pullRequests(): PullRequest[] {
return this.graph
- .nodes({type: PULL_REQUEST_NODE_TYPE})
- .map((n) => new PullRequest(this.graph, n.address));
+ .neighborhood(this.nodeAddress, {
+ direction: "OUT",
+ edgeType: CONTAINS_EDGE_TYPE,
+ nodeType: PULL_REQUEST_NODE_TYPE,
+ })
+ .map(({neighbor}) => new PullRequest(this.graph, neighbor));
}
}