From 4ad9fcf2598505f6831fe7d3b80a104ab04e1ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Thu, 13 Sep 2018 14:00:09 -0700 Subject: [PATCH] Add commits in the history to the RelationalView (#824) This builds on #821 so that every commit in the default ref's history is added as a Commit entity to the GitHub relational view. This means that these commits are also added to the graph by the GitHub plugin. In general, this will have no effect on real graphs, because these commits were already available via the Git plugin. Test plan: Observe that the snapshot changes just correspond to new commits being available to the RelationalView, and correspondingly added to the GitHub graph. `yarn test --full` passes. --- .../__snapshots__/createGraph.test.js.snap | 358 ++++++++++-------- .../__snapshots__/relationalView.test.js.snap | 6 +- src/plugins/github/relationalView.js | 20 + 3 files changed, 216 insertions(+), 168 deletions(-) diff --git a/src/plugins/github/__snapshots__/createGraph.test.js.snap b/src/plugins/github/__snapshots__/createGraph.test.js.snap index 3b38976..cbff589 100644 --- a/src/plugins/github/__snapshots__/createGraph.test.js.snap +++ b/src/plugins/github/__snapshots__/createGraph.test.js.snap @@ -29,8 +29,8 @@ Array [ "6", "417104047", ], - "dstIndex": 17, - "srcIndex": 35, + "dstIndex": 21, + "srcIndex": 39, }, Object { "address": Array [ @@ -51,8 +51,8 @@ Array [ "example-github", "1", ], - "dstIndex": 21, - "srcIndex": 36, + "dstIndex": 25, + "srcIndex": 40, }, Object { "address": Array [ @@ -73,8 +73,8 @@ Array [ "example-github", "10", ], - "dstIndex": 22, - "srcIndex": 36, + "dstIndex": 26, + "srcIndex": 40, }, Object { "address": Array [ @@ -95,8 +95,8 @@ Array [ "example-github", "2", ], - "dstIndex": 24, - "srcIndex": 36, + "dstIndex": 28, + "srcIndex": 40, }, Object { "address": Array [ @@ -117,8 +117,8 @@ Array [ "example-github", "4", ], - "dstIndex": 25, - "srcIndex": 36, + "dstIndex": 29, + "srcIndex": 40, }, Object { "address": Array [ @@ -139,8 +139,8 @@ Array [ "example-github", "6", ], - "dstIndex": 26, - "srcIndex": 36, + "dstIndex": 30, + "srcIndex": 40, }, Object { "address": Array [ @@ -161,8 +161,8 @@ Array [ "example-github", "7", ], - "dstIndex": 27, - "srcIndex": 36, + "dstIndex": 31, + "srcIndex": 40, }, Object { "address": Array [ @@ -183,8 +183,8 @@ Array [ "example-github", "8", ], - "dstIndex": 28, - "srcIndex": 36, + "dstIndex": 32, + "srcIndex": 40, }, Object { "address": Array [ @@ -205,8 +205,8 @@ Array [ "example-github", "3", ], - "dstIndex": 29, - "srcIndex": 36, + "dstIndex": 33, + "srcIndex": 40, }, Object { "address": Array [ @@ -227,8 +227,8 @@ Array [ "example-github", "5", ], - "dstIndex": 30, - "srcIndex": 36, + "dstIndex": 34, + "srcIndex": 40, }, Object { "address": Array [ @@ -249,8 +249,8 @@ Array [ "example-github", "9", ], - "dstIndex": 31, - "srcIndex": 36, + "dstIndex": 35, + "srcIndex": 40, }, Object { "address": Array [ @@ -273,8 +273,8 @@ Array [ "11", "420813621", ], - "dstIndex": 5, - "srcIndex": 36, + "dstIndex": 9, + "srcIndex": 40, }, Object { "address": Array [ @@ -297,8 +297,8 @@ Array [ "2", "373768703", ], - "dstIndex": 6, - "srcIndex": 36, + "dstIndex": 10, + "srcIndex": 40, }, Object { "address": Array [ @@ -321,8 +321,8 @@ Array [ "2", "373768850", ], - "dstIndex": 7, - "srcIndex": 36, + "dstIndex": 11, + "srcIndex": 40, }, Object { "address": Array [ @@ -345,8 +345,8 @@ Array [ "2", "385576185", ], - "dstIndex": 8, - "srcIndex": 36, + "dstIndex": 12, + "srcIndex": 40, }, Object { "address": Array [ @@ -369,8 +369,8 @@ Array [ "2", "385576220", ], - "dstIndex": 9, - "srcIndex": 36, + "dstIndex": 13, + "srcIndex": 40, }, Object { "address": Array [ @@ -393,8 +393,8 @@ Array [ "2", "385576248", ], - "dstIndex": 10, - "srcIndex": 36, + "dstIndex": 14, + "srcIndex": 40, }, Object { "address": Array [ @@ -417,8 +417,8 @@ Array [ "2", "385576273", ], - "dstIndex": 11, - "srcIndex": 36, + "dstIndex": 15, + "srcIndex": 40, }, Object { "address": Array [ @@ -441,8 +441,8 @@ Array [ "2", "385576920", ], - "dstIndex": 12, - "srcIndex": 36, + "dstIndex": 16, + "srcIndex": 40, }, Object { "address": Array [ @@ -465,8 +465,8 @@ Array [ "2", "385576936", ], - "dstIndex": 13, - "srcIndex": 36, + "dstIndex": 17, + "srcIndex": 40, }, Object { "address": Array [ @@ -489,8 +489,8 @@ Array [ "6", "373768442", ], - "dstIndex": 14, - "srcIndex": 36, + "dstIndex": 18, + "srcIndex": 40, }, Object { "address": Array [ @@ -513,8 +513,8 @@ Array [ "6", "373768538", ], - "dstIndex": 15, - "srcIndex": 36, + "dstIndex": 19, + "srcIndex": 40, }, Object { "address": Array [ @@ -537,8 +537,8 @@ Array [ "6", "385223316", ], - "dstIndex": 16, - "srcIndex": 36, + "dstIndex": 20, + "srcIndex": 40, }, Object { "address": Array [ @@ -561,8 +561,8 @@ Array [ "3", "369162222", ], - "dstIndex": 18, - "srcIndex": 36, + "dstIndex": 22, + "srcIndex": 40, }, Object { "address": Array [ @@ -583,8 +583,8 @@ Array [ "example-github", "10", ], - "dstIndex": 22, - "srcIndex": 37, + "dstIndex": 26, + "srcIndex": 41, }, Object { "address": Array [ @@ -605,8 +605,8 @@ Array [ "example-github", "11", ], - "dstIndex": 23, - "srcIndex": 37, + "dstIndex": 27, + "srcIndex": 41, }, Object { "address": Array [ @@ -627,8 +627,8 @@ Array [ "example-github", "9", ], - "dstIndex": 31, - "srcIndex": 37, + "dstIndex": 35, + "srcIndex": 41, }, Object { "address": Array [ @@ -650,8 +650,8 @@ Array [ "5", "100313899", ], - "dstIndex": 33, - "srcIndex": 37, + "dstIndex": 37, + "srcIndex": 41, }, Object { "address": Array [ @@ -673,8 +673,8 @@ Array [ "5", "100314038", ], - "dstIndex": 34, - "srcIndex": 37, + "dstIndex": 38, + "srcIndex": 41, }, Object { "address": Array [ @@ -697,8 +697,8 @@ Array [ "11", "420813013", ], - "dstIndex": 3, - "srcIndex": 37, + "dstIndex": 7, + "srcIndex": 41, }, Object { "address": Array [ @@ -721,8 +721,8 @@ Array [ "5", "396430464", ], - "dstIndex": 19, - "srcIndex": 37, + "dstIndex": 23, + "srcIndex": 41, }, Object { "address": Array [ @@ -746,8 +746,8 @@ Array [ "100313899", "171460198", ], - "dstIndex": 20, - "srcIndex": 37, + "dstIndex": 24, + "srcIndex": 41, }, Object { "address": Array [ @@ -762,8 +762,8 @@ Array [ "example-github", "1", ], - "dstIndex": 32, - "srcIndex": 21, + "dstIndex": 36, + "srcIndex": 25, }, Object { "address": Array [ @@ -778,8 +778,8 @@ Array [ "example-github", "10", ], - "dstIndex": 32, - "srcIndex": 22, + "dstIndex": 36, + "srcIndex": 26, }, Object { "address": Array [ @@ -794,8 +794,8 @@ Array [ "example-github", "11", ], - "dstIndex": 32, - "srcIndex": 23, + "dstIndex": 36, + "srcIndex": 27, }, Object { "address": Array [ @@ -810,8 +810,8 @@ Array [ "example-github", "2", ], - "dstIndex": 32, - "srcIndex": 24, + "dstIndex": 36, + "srcIndex": 28, }, Object { "address": Array [ @@ -826,8 +826,8 @@ Array [ "example-github", "4", ], - "dstIndex": 32, - "srcIndex": 25, + "dstIndex": 36, + "srcIndex": 29, }, Object { "address": Array [ @@ -842,8 +842,8 @@ Array [ "example-github", "6", ], - "dstIndex": 32, - "srcIndex": 26, + "dstIndex": 36, + "srcIndex": 30, }, Object { "address": Array [ @@ -858,8 +858,8 @@ Array [ "example-github", "7", ], - "dstIndex": 32, - "srcIndex": 27, + "dstIndex": 36, + "srcIndex": 31, }, Object { "address": Array [ @@ -874,8 +874,8 @@ Array [ "example-github", "8", ], - "dstIndex": 32, - "srcIndex": 28, + "dstIndex": 36, + "srcIndex": 32, }, Object { "address": Array [ @@ -890,8 +890,8 @@ Array [ "example-github", "3", ], - "dstIndex": 32, - "srcIndex": 29, + "dstIndex": 36, + "srcIndex": 33, }, Object { "address": Array [ @@ -906,8 +906,8 @@ Array [ "example-github", "5", ], - "dstIndex": 32, - "srcIndex": 30, + "dstIndex": 36, + "srcIndex": 34, }, Object { "address": Array [ @@ -922,8 +922,8 @@ Array [ "example-github", "9", ], - "dstIndex": 32, - "srcIndex": 31, + "dstIndex": 36, + "srcIndex": 35, }, Object { "address": Array [ @@ -939,8 +939,8 @@ Array [ "5", "100313899", ], - "dstIndex": 30, - "srcIndex": 33, + "dstIndex": 34, + "srcIndex": 37, }, Object { "address": Array [ @@ -956,8 +956,8 @@ Array [ "5", "100314038", ], - "dstIndex": 30, - "srcIndex": 34, + "dstIndex": 34, + "srcIndex": 38, }, Object { "address": Array [ @@ -974,8 +974,8 @@ Array [ "11", "420811872", ], - "dstIndex": 23, - "srcIndex": 2, + "dstIndex": 27, + "srcIndex": 6, }, Object { "address": Array [ @@ -992,8 +992,8 @@ Array [ "11", "420813013", ], - "dstIndex": 23, - "srcIndex": 3, + "dstIndex": 27, + "srcIndex": 7, }, Object { "address": Array [ @@ -1010,8 +1010,8 @@ Array [ "11", "420813206", ], - "dstIndex": 23, - "srcIndex": 4, + "dstIndex": 27, + "srcIndex": 8, }, Object { "address": Array [ @@ -1028,8 +1028,8 @@ Array [ "11", "420813621", ], - "dstIndex": 23, - "srcIndex": 5, + "dstIndex": 27, + "srcIndex": 9, }, Object { "address": Array [ @@ -1046,8 +1046,8 @@ Array [ "2", "373768703", ], - "dstIndex": 24, - "srcIndex": 6, + "dstIndex": 28, + "srcIndex": 10, }, Object { "address": Array [ @@ -1064,8 +1064,8 @@ Array [ "2", "373768850", ], - "dstIndex": 24, - "srcIndex": 7, + "dstIndex": 28, + "srcIndex": 11, }, Object { "address": Array [ @@ -1082,8 +1082,8 @@ Array [ "2", "385576185", ], - "dstIndex": 24, - "srcIndex": 8, + "dstIndex": 28, + "srcIndex": 12, }, Object { "address": Array [ @@ -1100,8 +1100,8 @@ Array [ "2", "385576220", ], - "dstIndex": 24, - "srcIndex": 9, + "dstIndex": 28, + "srcIndex": 13, }, Object { "address": Array [ @@ -1118,8 +1118,8 @@ Array [ "2", "385576248", ], - "dstIndex": 24, - "srcIndex": 10, + "dstIndex": 28, + "srcIndex": 14, }, Object { "address": Array [ @@ -1136,8 +1136,8 @@ Array [ "2", "385576273", ], - "dstIndex": 24, - "srcIndex": 11, + "dstIndex": 28, + "srcIndex": 15, }, Object { "address": Array [ @@ -1154,8 +1154,8 @@ Array [ "2", "385576920", ], - "dstIndex": 24, - "srcIndex": 12, + "dstIndex": 28, + "srcIndex": 16, }, Object { "address": Array [ @@ -1172,8 +1172,8 @@ Array [ "2", "385576936", ], - "dstIndex": 24, - "srcIndex": 13, + "dstIndex": 28, + "srcIndex": 17, }, Object { "address": Array [ @@ -1190,8 +1190,8 @@ Array [ "6", "373768442", ], - "dstIndex": 26, - "srcIndex": 14, + "dstIndex": 30, + "srcIndex": 18, }, Object { "address": Array [ @@ -1208,8 +1208,8 @@ Array [ "6", "373768538", ], - "dstIndex": 26, - "srcIndex": 15, + "dstIndex": 30, + "srcIndex": 19, }, Object { "address": Array [ @@ -1226,8 +1226,8 @@ Array [ "6", "385223316", ], - "dstIndex": 26, - "srcIndex": 16, + "dstIndex": 30, + "srcIndex": 20, }, Object { "address": Array [ @@ -1244,8 +1244,8 @@ Array [ "6", "417104047", ], - "dstIndex": 26, - "srcIndex": 17, + "dstIndex": 30, + "srcIndex": 21, }, Object { "address": Array [ @@ -1262,8 +1262,8 @@ Array [ "3", "369162222", ], - "dstIndex": 29, - "srcIndex": 18, + "dstIndex": 33, + "srcIndex": 22, }, Object { "address": Array [ @@ -1280,8 +1280,8 @@ Array [ "5", "396430464", ], - "dstIndex": 30, - "srcIndex": 19, + "dstIndex": 34, + "srcIndex": 23, }, Object { "address": Array [ @@ -1299,8 +1299,8 @@ Array [ "100313899", "171460198", ], - "dstIndex": 33, - "srcIndex": 20, + "dstIndex": 37, + "srcIndex": 24, }, Object { "address": Array [ @@ -1330,8 +1330,8 @@ Array [ "USER", "wchargin", ], - "dstIndex": 19, - "srcIndex": 30, + "dstIndex": 23, + "srcIndex": 34, }, Object { "address": Array [ @@ -1347,7 +1347,7 @@ Array [ "3", ], "dstIndex": 0, - "srcIndex": 29, + "srcIndex": 33, }, Object { "address": Array [ @@ -1362,8 +1362,8 @@ Array [ "example-github", "5", ], - "dstIndex": 1, - "srcIndex": 30, + "dstIndex": 2, + "srcIndex": 34, }, Object { "address": Array [ @@ -1385,8 +1385,8 @@ Array [ "example-github", "10", ], - "dstIndex": 22, - "srcIndex": 22, + "dstIndex": 26, + "srcIndex": 26, }, Object { "address": Array [ @@ -1408,8 +1408,8 @@ Array [ "example-github", "2", ], - "dstIndex": 24, - "srcIndex": 22, + "dstIndex": 28, + "srcIndex": 26, }, Object { "address": Array [ @@ -1431,8 +1431,8 @@ Array [ "example-github", "1", ], - "dstIndex": 21, - "srcIndex": 24, + "dstIndex": 25, + "srcIndex": 28, }, Object { "address": Array [ @@ -1453,8 +1453,8 @@ Array [ "USER", "wchargin", ], - "dstIndex": 37, - "srcIndex": 30, + "dstIndex": 41, + "srcIndex": 34, }, Object { "address": Array [ @@ -1478,8 +1478,8 @@ Array [ "example-github", "6", ], - "dstIndex": 26, - "srcIndex": 6, + "dstIndex": 30, + "srcIndex": 10, }, Object { "address": Array [ @@ -1505,8 +1505,8 @@ Array [ "6", "373768538", ], - "dstIndex": 15, - "srcIndex": 7, + "dstIndex": 19, + "srcIndex": 11, }, Object { "address": Array [ @@ -1530,8 +1530,8 @@ Array [ "example-github", "5", ], - "dstIndex": 30, - "srcIndex": 8, + "dstIndex": 34, + "srcIndex": 12, }, Object { "address": Array [ @@ -1556,8 +1556,8 @@ Array [ "5", "100313899", ], - "dstIndex": 33, - "srcIndex": 9, + "dstIndex": 37, + "srcIndex": 13, }, Object { "address": Array [ @@ -1584,8 +1584,8 @@ Array [ "100313899", "171460198", ], - "dstIndex": 20, - "srcIndex": 10, + "dstIndex": 24, + "srcIndex": 14, }, Object { "address": Array [ @@ -1608,8 +1608,8 @@ Array [ "USER", "wchargin", ], - "dstIndex": 37, - "srcIndex": 11, + "dstIndex": 41, + "srcIndex": 15, }, Object { "address": Array [ @@ -1633,8 +1633,8 @@ Array [ "example-github", "1", ], - "dstIndex": 21, - "srcIndex": 12, + "dstIndex": 25, + "srcIndex": 16, }, Object { "address": Array [ @@ -1658,8 +1658,8 @@ Array [ "example-github", "2", ], - "dstIndex": 24, - "srcIndex": 12, + "dstIndex": 28, + "srcIndex": 16, }, Object { "address": Array [ @@ -1683,8 +1683,8 @@ Array [ "example-github", "3", ], - "dstIndex": 29, - "srcIndex": 12, + "dstIndex": 33, + "srcIndex": 16, }, Object { "address": Array [ @@ -1709,8 +1709,8 @@ Array [ "5", "100313899", ], - "dstIndex": 33, - "srcIndex": 12, + "dstIndex": 37, + "srcIndex": 16, }, Object { "address": Array [ @@ -1737,8 +1737,8 @@ Array [ "100313899", "171460198", ], - "dstIndex": 20, - "srcIndex": 12, + "dstIndex": 24, + "srcIndex": 16, }, Object { "address": Array [ @@ -1762,8 +1762,8 @@ Array [ "example-github", "2", ], - "dstIndex": 24, - "srcIndex": 16, + "dstIndex": 28, + "srcIndex": 20, }, Object { "address": Array [ @@ -1787,8 +1787,8 @@ Array [ "example-github", "2", ], - "dstIndex": 24, - "srcIndex": 18, + "dstIndex": 28, + "srcIndex": 22, }, ], "nodes": Array [ @@ -1798,12 +1798,36 @@ Array [ "COMMIT", "0a223346b4e6dec0127b1e6aa892c4ee0424b66a", ], + Array [ + "sourcecred", + "git", + "COMMIT", + "6bd1b4c0b719c22c688a74863be07a699b7b9b34", + ], Array [ "sourcecred", "git", "COMMIT", "6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6", ], + Array [ + "sourcecred", + "git", + "COMMIT", + "c430bd74455105f77215ece51945094ceeee6c86", + ], + Array [ + "sourcecred", + "git", + "COMMIT", + "ec91adb718a6045b492303f00d8e8beb957dc780", + ], + Array [ + "sourcecred", + "git", + "COMMIT", + "ecc889dc94cf6da17ae6eab5bb7b7155f577519d", + ], Array [ "sourcecred", "github", diff --git a/src/plugins/github/__snapshots__/relationalView.test.js.snap b/src/plugins/github/__snapshots__/relationalView.test.js.snap index 80c96b2..1550abc 100644 --- a/src/plugins/github/__snapshots__/relationalView.test.js.snap +++ b/src/plugins/github/__snapshots__/relationalView.test.js.snap @@ -147,12 +147,16 @@ Array [ ] `; -exports[`plugins/github/relationalView RelationalView entity: commits has expected number of them 1`] = `2`; +exports[`plugins/github/relationalView RelationalView entity: commits has expected number of them 1`] = `6`; exports[`plugins/github/relationalView RelationalView entity: commits they have expected urls 1`] = ` Array [ "https://github.com/sourcecred/example-github/commit/0a223346b4e6dec0127b1e6aa892c4ee0424b66a", "https://github.com/sourcecred/example-github/commit/6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6", + "https://github.com/sourcecred/example-github/commit/6bd1b4c0b719c22c688a74863be07a699b7b9b34", + "https://github.com/sourcecred/example-github/commit/c430bd74455105f77215ece51945094ceeee6c86", + "https://github.com/sourcecred/example-github/commit/ecc889dc94cf6da17ae6eab5bb7b7155f577519d", + "https://github.com/sourcecred/example-github/commit/ec91adb718a6045b492303f00d8e8beb957dc780", ] `; diff --git a/src/plugins/github/relationalView.js b/src/plugins/github/relationalView.js index ee73d32..d87c7ea 100644 --- a/src/plugins/github/relationalView.js +++ b/src/plugins/github/relationalView.js @@ -4,6 +4,8 @@ import {toCompat, fromCompat, type Compatible} from "../../util/compat"; import stringify from "json-stable-stringify"; import {parseReferences} from "./parseReferences"; import * as N from "./nodes"; +import dedent from "../../util/dedent"; + // Workaround for https://github.com/facebook/flow/issues/6538 import type { RepoAddress, @@ -288,6 +290,24 @@ export class RelationalView { }; const raw = N.toRaw(address); this._repos.set(raw, entry); + this._addCommitHistory(json); + } + + _addCommitHistory(json: RepositoryJSON) { + if (json.defaultBranchRef != null) { + const target = json.defaultBranchRef.target; + if (target.__typename === "Commit") { + target.history.nodes.forEach((commit) => this._addCommit(commit)); + } else { + throw new Error( + dedent`\ + Your repo doesn't have a commit as its defaultBranchRef's target. \ + Please file a bug reproducing this error. \ + https://github.com/sourcecred/sourcecred/issues\ + ` + ); + } + } } _addIssue(repo: RepoAddress, json: IssueJSON): IssueAddress {