From c68cb29769623eddf6ebbb08c2976c63f1e69eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Thu, 13 Sep 2018 14:19:37 -0700 Subject: [PATCH] Add commit authorship to the graph (#826) In #824, we loaded every commit in the default branch's history into the GitHub relational view, along with authorship info. This commit actually uses that authorship info to create AUTHORS edges from the commit to the user that authored it (whenever possible). The implementation is quite simple: we just need to yield the commits when we yield all the authored entities, so that we will process their authors and add them to the graph. Also, I updated the invariant declarations in `graphView.js`, and corrected a type signature so that the new invariants would typecheck. Test plan: The snapshot update shows that commits are being added to the graph appropriately. Observe that commits which do not have a valid GitHub user as their author do not correspond to edges in the graph. See [example]. This is basically a solution to #815, but I'll defer closing that issue until I've added a few more features, like reference detection. [example]: https://github.com/sourcecred/example-github/commit/6bd1b4c0b719c22c688a74863be07a699b7b9b34 --- CHANGELOG.md | 1 + .../__snapshots__/createGraph.test.js.snap | 100 ++++++++++++++++++ src/plugins/github/graphView.js | 12 ++- src/plugins/github/relationalView.js | 1 + 4 files changed, 111 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78b5d43..c4e4a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## [Unreleased] +- Add commit authorship to the graph (#826) - Add `MentionsAuthor` edges to the graph (#808) diff --git a/src/plugins/github/__snapshots__/createGraph.test.js.snap b/src/plugins/github/__snapshots__/createGraph.test.js.snap index cbff589..9bca8e3 100644 --- a/src/plugins/github/__snapshots__/createGraph.test.js.snap +++ b/src/plugins/github/__snapshots__/createGraph.test.js.snap @@ -8,6 +8,26 @@ Array [ }, Object { "edges": Array [ + Object { + "address": Array [ + "sourcecred", + "github", + "AUTHORS", + "5", + "sourcecred", + "github", + "USERLIKE", + "BOT", + "credbot", + "4", + "sourcecred", + "git", + "COMMIT", + "c430bd74455105f77215ece51945094ceeee6c86", + ], + "dstIndex": 3, + "srcIndex": 39, + }, Object { "address": Array [ "sourcecred", @@ -32,6 +52,86 @@ Array [ "dstIndex": 21, "srcIndex": 39, }, + Object { + "address": Array [ + "sourcecred", + "github", + "AUTHORS", + "5", + "sourcecred", + "github", + "USERLIKE", + "USER", + "decentralion", + "4", + "sourcecred", + "git", + "COMMIT", + "0a223346b4e6dec0127b1e6aa892c4ee0424b66a", + ], + "dstIndex": 0, + "srcIndex": 40, + }, + Object { + "address": Array [ + "sourcecred", + "github", + "AUTHORS", + "5", + "sourcecred", + "github", + "USERLIKE", + "USER", + "decentralion", + "4", + "sourcecred", + "git", + "COMMIT", + "6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6", + ], + "dstIndex": 2, + "srcIndex": 40, + }, + Object { + "address": Array [ + "sourcecred", + "github", + "AUTHORS", + "5", + "sourcecred", + "github", + "USERLIKE", + "USER", + "decentralion", + "4", + "sourcecred", + "git", + "COMMIT", + "ec91adb718a6045b492303f00d8e8beb957dc780", + ], + "dstIndex": 4, + "srcIndex": 40, + }, + Object { + "address": Array [ + "sourcecred", + "github", + "AUTHORS", + "5", + "sourcecred", + "github", + "USERLIKE", + "USER", + "decentralion", + "4", + "sourcecred", + "git", + "COMMIT", + "ecc889dc94cf6da17ae6eab5bb7b7155f577519d", + ], + "dstIndex": 5, + "srcIndex": 40, + }, Object { "address": Array [ "sourcecred", diff --git a/src/plugins/github/graphView.js b/src/plugins/github/graphView.js index 3309440..585a9c3 100644 --- a/src/plugins/github/graphView.js +++ b/src/plugins/github/graphView.js @@ -164,8 +164,8 @@ export class GraphView { +dstPrefix: NodeAddressT, |}; function homProduct( - srcPrefixes: GN.RawAddress[], - dstPrefixes: GN.RawAddress[] + srcPrefixes: NodeAddressT[], + dstPrefixes: NodeAddressT[] ): Hom[] { const result = []; for (const srcPrefix of srcPrefixes) { @@ -224,7 +224,13 @@ export class GraphView { [GE.AUTHORS_TYPE]: { homs: homProduct( [GN.Prefix.userlike], - [GN.Prefix.issue, GN.Prefix.review, GN.Prefix.pull, GN.Prefix.comment] + [ + GN.Prefix.issue, + GN.Prefix.review, + GN.Prefix.pull, + GN.Prefix.comment, + GitNode.Prefix.commit, + ] ), srcAccessor: (x) => GN.toRaw((x: any).author), dstAccessor: (x) => GN.toRaw((x: any).content), diff --git a/src/plugins/github/relationalView.js b/src/plugins/github/relationalView.js index d87c7ea..2ad8a1f 100644 --- a/src/plugins/github/relationalView.js +++ b/src/plugins/github/relationalView.js @@ -234,6 +234,7 @@ export class RelationalView { yield* this.pulls(); yield* this.reviews(); yield* this.comments(); + yield* this.commits(); } *entities(): Iterator {