Skip to content

Commit

Permalink
Detect references in commit messages (#829)
Browse files Browse the repository at this point in the history
Now that the GitHub plugin knows about commit messages (#828), we can
parse those commit messages to find references to other GitHub entities.

Fixed a minor typing mistake along the way.

Test plan:
Observe that a number of references have been detected among the commits
in the example GitHub repository. We mistakenly find references to
wchargin because we don't have a proper tokenizer. (#481)

Progress on #815.
  • Loading branch information
teamdandelion committed Sep 13, 2018
1 parent a1af953 commit ab85c97
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# Changelog

## [Unreleased]
- Detect references in commit messages (#829)
- Add commit authorship to the graph (#826)
- Add `MentionsAuthor` edges to the graph (#808)
<!-- Please add new entries to the _top_ of this section. -->
Expand Down
82 changes: 82 additions & 0 deletions src/plugins/github/__snapshots__/createGraph.test.js.snap
Expand Up @@ -1465,6 +1465,88 @@ Array [
"dstIndex": 2,
"srcIndex": 34,
},
Object {
"address": Array [
"sourcecred",
"github",
"REFERENCES",
"4",
"sourcecred",
"git",
"COMMIT",
"0a223346b4e6dec0127b1e6aa892c4ee0424b66a",
"6",
"sourcecred",
"github",
"PULL",
"sourcecred",
"example-github",
"3",
],
"dstIndex": 33,
"srcIndex": 0,
},
Object {
"address": Array [
"sourcecred",
"github",
"REFERENCES",
"4",
"sourcecred",
"git",
"COMMIT",
"6bd1b4c0b719c22c688a74863be07a699b7b9b34",
"5",
"sourcecred",
"github",
"USERLIKE",
"USER",
"wchargin",
],
"dstIndex": 41,
"srcIndex": 1,
},
Object {
"address": Array [
"sourcecred",
"github",
"REFERENCES",
"4",
"sourcecred",
"git",
"COMMIT",
"6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6",
"6",
"sourcecred",
"github",
"PULL",
"sourcecred",
"example-github",
"5",
],
"dstIndex": 34,
"srcIndex": 2,
},
Object {
"address": Array [
"sourcecred",
"github",
"REFERENCES",
"4",
"sourcecred",
"git",
"COMMIT",
"c430bd74455105f77215ece51945094ceeee6c86",
"5",
"sourcecred",
"github",
"USERLIKE",
"USER",
"wchargin",
],
"dstIndex": 41,
"srcIndex": 3,
},
Object {
"address": Array [
"sourcecred",
Expand Down
16 changes: 16 additions & 0 deletions src/plugins/github/__snapshots__/relationalView.test.js.snap
Expand Up @@ -351,5 +351,21 @@ Array [
"from": "https://github.com/sourcecred/example-github/pull/3#issuecomment-369162222",
"to": "https://github.com/sourcecred/example-github/issues/2",
},
Object {
"from": "https://github.com/sourcecred/example-github/commit/0a223346b4e6dec0127b1e6aa892c4ee0424b66a",
"to": "https://github.com/sourcecred/example-github/pull/3",
},
Object {
"from": "https://github.com/sourcecred/example-github/commit/6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6",
"to": "https://github.com/sourcecred/example-github/pull/5",
},
Object {
"from": "https://github.com/sourcecred/example-github/commit/6bd1b4c0b719c22c688a74863be07a699b7b9b34",
"to": "https://github.com/wchargin",
},
Object {
"from": "https://github.com/sourcecred/example-github/commit/c430bd74455105f77215ece51945094ceeee6c86",
"to": "https://github.com/wchargin",
},
]
`;
1 change: 1 addition & 0 deletions src/plugins/github/graphView.js
Expand Up @@ -208,6 +208,7 @@ export class GraphView {
GN.Prefix.pull,
GN.Prefix.review,
GN.Prefix.comment,
GitNode.Prefix.commit,
],
[
GN.Prefix.repo,
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/github/nodes.js
Expand Up @@ -91,7 +91,8 @@ export type TextContentAddress =
| IssueAddress
| PullAddress
| ReviewAddress
| CommentAddress;
| CommentAddress
| GitNode.CommitAddress;

// Each of these types may be referred to by something
// with text content.
Expand Down
14 changes: 11 additions & 3 deletions src/plugins/github/relationalView.js
Expand Up @@ -219,6 +219,7 @@ export class RelationalView {
yield* this.pulls();
yield* this.reviews();
yield* this.comments();
yield* this.commits();
}

*parentEntities(): Iterator<ParentEntity> {
Expand Down Expand Up @@ -465,7 +466,8 @@ export class RelationalView {
}
for (const e of this.textContentEntities()) {
const srcAddress = e.address();
for (const {ref, refType} of parseReferences(e.body())) {
const body = e instanceof Commit ? e.message() : e.body();
for (const {ref, refType} of parseReferences(body)) {
const refAddress = refToAddress.get(ref);
if (refAddress != null) {
switch (refType) {
Expand Down Expand Up @@ -544,6 +546,9 @@ export class RelationalView {
case "COMMENT":
entity = this.comment(address);
break;
case "COMMIT":
entity = this.commit(address);
break;
default:
throw new Error(
`Unexpected referrer address type: ${(address.type: empty)}`
Expand Down Expand Up @@ -661,7 +666,7 @@ export class Repo extends _Entity<RepoEntry> {
yield assertExists(pull, address);
}
}
referencedBy(): Iterator<ReferentEntity> {
referencedBy(): Iterator<TextContentEntity> {
return this._view._referencedBy(this);
}
}
Expand Down Expand Up @@ -874,6 +879,9 @@ export class Commit extends _Entity<CommitEntry> {
message(): string {
return this._entry.message;
}
references(): Iterator<ReferentEntity> {
return this._view._references(this);
}
}

type UserlikeEntry = {|
Expand Down Expand Up @@ -948,7 +956,7 @@ export function match<T>(handlers: MatchHandlers<T>, x: Entity): T {

export type Entity = Repo | Issue | Pull | Review | Comment | Commit | Userlike;
export type AuthoredEntity = Issue | Pull | Review | Comment | Commit;
export type TextContentEntity = Issue | Pull | Review | Comment;
export type TextContentEntity = Issue | Pull | Review | Comment | Commit;
export type ParentEntity = Repo | Issue | Pull | Review;
export type ChildEntity = Issue | Pull | Review | Comment;
export type ReferentEntity = Repo | Issue | Pull | Review | Comment | Userlike;
Expand Down

0 comments on commit ab85c97

Please sign in to comment.