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.
This commit is contained in:
Dandelion Mané 2018-05-10 11:34:53 -07:00 committed by GitHub
parent 9d24190c03
commit 04390e5609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 263 additions and 23 deletions

View File

@ -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",

View File

@ -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<RepositoryNodePayload>, 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<RepositoryNodePayload>,
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) {

View File

@ -172,22 +172,19 @@ export class Repository extends GithubEntity<RepositoryNodePayload> {
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<RepositoryNodePayload> {
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));
}
}