diff --git a/src/plugins/github/__snapshots__/createGraph.test.js.snap b/src/plugins/github/__snapshots__/createGraph.test.js.snap index e28c584..6d8b518 100644 --- a/src/plugins/github/__snapshots__/createGraph.test.js.snap +++ b/src/plugins/github/__snapshots__/createGraph.test.js.snap @@ -1635,6 +1635,58 @@ Array [ "dstIndex": 23, "srcIndex": 42, }, + Object { + "address": Array [ + "sourcecred", + "github", + "REACTS", + "HEART", + "5", + "sourcecred", + "github", + "USERLIKE", + "USER", + "decentralion", + "9", + "sourcecred", + "github", + "COMMENT", + "REVIEW", + "sourcecred", + "example-github", + "5", + "100313899", + "171460198", + ], + "dstIndex": 24, + "srcIndex": 42, + }, + Object { + "address": Array [ + "sourcecred", + "github", + "REACTS", + "HEART", + "5", + "sourcecred", + "github", + "USERLIKE", + "USER", + "wchargin", + "9", + "sourcecred", + "github", + "COMMENT", + "REVIEW", + "sourcecred", + "example-github", + "5", + "100313899", + "171460198", + ], + "dstIndex": 24, + "srcIndex": 43, + }, Object { "address": Array [ "sourcecred", @@ -1683,6 +1735,58 @@ Array [ "dstIndex": 8, "srcIndex": 42, }, + Object { + "address": Array [ + "sourcecred", + "github", + "REACTS", + "HOORAY", + "5", + "sourcecred", + "github", + "USERLIKE", + "USER", + "decentralion", + "9", + "sourcecred", + "github", + "COMMENT", + "REVIEW", + "sourcecred", + "example-github", + "5", + "100313899", + "171460198", + ], + "dstIndex": 24, + "srcIndex": 42, + }, + Object { + "address": Array [ + "sourcecred", + "github", + "REACTS", + "HOORAY", + "5", + "sourcecred", + "github", + "USERLIKE", + "USER", + "wchargin", + "9", + "sourcecred", + "github", + "COMMENT", + "REVIEW", + "sourcecred", + "example-github", + "5", + "100313899", + "171460198", + ], + "dstIndex": 24, + "srcIndex": 43, + }, Object { "address": Array [ "sourcecred", @@ -1777,6 +1881,58 @@ Array [ "dstIndex": 8, "srcIndex": 42, }, + Object { + "address": Array [ + "sourcecred", + "github", + "REACTS", + "THUMBS_UP", + "5", + "sourcecred", + "github", + "USERLIKE", + "USER", + "decentralion", + "9", + "sourcecred", + "github", + "COMMENT", + "REVIEW", + "sourcecred", + "example-github", + "5", + "100313899", + "171460198", + ], + "dstIndex": 24, + "srcIndex": 42, + }, + Object { + "address": Array [ + "sourcecred", + "github", + "REACTS", + "THUMBS_UP", + "5", + "sourcecred", + "github", + "USERLIKE", + "USER", + "wchargin", + "9", + "sourcecred", + "github", + "COMMENT", + "REVIEW", + "sourcecred", + "example-github", + "5", + "100313899", + "171460198", + ], + "dstIndex": 24, + "srcIndex": 43, + }, Object { "address": Array [ "sourcecred", diff --git a/src/plugins/github/__snapshots__/relationalView.test.js.snap b/src/plugins/github/__snapshots__/relationalView.test.js.snap index c871fcd..c39cde4 100644 --- a/src/plugins/github/__snapshots__/relationalView.test.js.snap +++ b/src/plugins/github/__snapshots__/relationalView.test.js.snap @@ -16,7 +16,106 @@ Object { } `; -exports[`plugins/github/relationalView Comment has reactions 1`] = `Array []`; +exports[`plugins/github/relationalView Comment has reactions 1`] = ` +Array [ + Object { + "content": "THUMBS_UP", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "THUMBS_DOWN", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "THUMBS_UP", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "LAUGH", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "THUMBS_DOWN", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "HOORAY", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "LAUGH", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "CONFUSED", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "HOORAY", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "HEART", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "CONFUSED", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "HEART", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, +] +`; exports[`plugins/github/relationalView Comment has url 1`] = `"https://github.com/sourcecred/example-github/pull/5#discussion_r171460198"`; @@ -405,6 +504,104 @@ Object { }, }, ], + "https://github.com/sourcecred/example-github/pull/5#discussion_r171460198": Array [ + Object { + "content": "THUMBS_UP", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "THUMBS_DOWN", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "THUMBS_UP", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "LAUGH", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "THUMBS_DOWN", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "HOORAY", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "LAUGH", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "CONFUSED", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "HOORAY", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "HEART", + "user": Object { + "login": "wchargin", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "CONFUSED", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + Object { + "content": "HEART", + "user": Object { + "login": "decentralion", + "subtype": "USER", + "type": "USERLIKE", + }, + }, + ], "https://github.com/sourcecred/example-github/pull/5#issuecomment-396430464": Array [ Object { "content": "HEART", diff --git a/src/plugins/github/example/example-github.json b/src/plugins/github/example/example-github.json index d618534..0479bf2 100644 --- a/src/plugins/github/example/example-github.json +++ b/src/plugins/github/example/example-github.json @@ -1000,9 +1000,129 @@ "id": "MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==", "reactions": { "nodes": [ + { + "content": "THUMBS_UP", + "id": "MDg6UmVhY3Rpb24yOTU5NTI1MQ==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjQzMTc4MDY=", + "login": "wchargin", + "url": "https://github.com/wchargin" + } + }, + { + "content": "THUMBS_DOWN", + "id": "MDg6UmVhY3Rpb24yOTU5NTI1NA==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjQzMTc4MDY=", + "login": "wchargin", + "url": "https://github.com/wchargin" + } + }, + { + "content": "THUMBS_UP", + "id": "MDg6UmVhY3Rpb24yOTU5NTI1NQ==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjE0MDAwMjM=", + "login": "decentralion", + "url": "https://github.com/decentralion" + } + }, + { + "content": "LAUGH", + "id": "MDg6UmVhY3Rpb24yOTU5NTI1Nw==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjQzMTc4MDY=", + "login": "wchargin", + "url": "https://github.com/wchargin" + } + }, + { + "content": "THUMBS_DOWN", + "id": "MDg6UmVhY3Rpb24yOTU5NTI1OA==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjE0MDAwMjM=", + "login": "decentralion", + "url": "https://github.com/decentralion" + } + }, + { + "content": "HOORAY", + "id": "MDg6UmVhY3Rpb24yOTU5NTI1OQ==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjQzMTc4MDY=", + "login": "wchargin", + "url": "https://github.com/wchargin" + } + }, + { + "content": "LAUGH", + "id": "MDg6UmVhY3Rpb24yOTU5NTI2MQ==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjE0MDAwMjM=", + "login": "decentralion", + "url": "https://github.com/decentralion" + } + }, + { + "content": "CONFUSED", + "id": "MDg6UmVhY3Rpb24yOTU5NTI2NQ==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjQzMTc4MDY=", + "login": "wchargin", + "url": "https://github.com/wchargin" + } + }, + { + "content": "HOORAY", + "id": "MDg6UmVhY3Rpb24yOTU5NTI2Ng==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjE0MDAwMjM=", + "login": "decentralion", + "url": "https://github.com/decentralion" + } + }, + { + "content": "HEART", + "id": "MDg6UmVhY3Rpb24yOTU5NTI2OA==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjQzMTc4MDY=", + "login": "wchargin", + "url": "https://github.com/wchargin" + } + }, + { + "content": "CONFUSED", + "id": "MDg6UmVhY3Rpb24yOTU5NTI2OQ==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjE0MDAwMjM=", + "login": "decentralion", + "url": "https://github.com/decentralion" + } + }, + { + "content": "HEART", + "id": "MDg6UmVhY3Rpb24yOTU5NTI3NA==", + "user": { + "__typename": "User", + "id": "MDQ6VXNlcjE0MDAwMjM=", + "login": "decentralion", + "url": "https://github.com/decentralion" + } + } ], "pageInfo": { - "endCursor": null, + "endCursor": "Y3Vyc29yOnYyOpHOAcOWig==", "hasNextPage": false } }, diff --git a/src/plugins/github/fetchGithubRepo.js b/src/plugins/github/fetchGithubRepo.js index e4e8205..1bd21d5 100644 --- a/src/plugins/github/fetchGithubRepo.js +++ b/src/plugins/github/fetchGithubRepo.js @@ -188,6 +188,7 @@ function ensureNoMorePages(result: any, path = []) { } if (result.pageInfo) { if (result.pageInfo.hasNextPage) { + console.error(result); throw new Error(`More pages at: ${path.join()}`); } } diff --git a/src/plugins/github/graphql.js b/src/plugins/github/graphql.js index def00b4..eb94472 100644 --- a/src/plugins/github/graphql.js +++ b/src/plugins/github/graphql.js @@ -87,7 +87,13 @@ const PAGE_SIZE_REACTIONS = 5; * the continuation into a query, and not of the continuation itself. */ export type Continuation = {| - +enclosingNodeType: "REPOSITORY" | "ISSUE" | "PULL" | "REVIEW" | "COMMENT", + +enclosingNodeType: + | "REPOSITORY" + | "ISSUE" + | "PULL" + | "REVIEW" + | "ISSUE_COMMENT" + | "REVIEW_COMMENT", +enclosingNodeId: string, +selections: $ReadOnlyArray, +destinationPath: $ReadOnlyArray, @@ -217,7 +223,8 @@ export function continuationsFromContinuation( ISSUE: continuationsFromIssue, PULL: continuationsFromPR, REVIEW: continuationsFromReview, - COMMENT: continuationsFromComment, + ISSUE_COMMENT: continuationsFromIssueComment, + REVIEW_COMMENT: continuationsFromReviewComment, }[source.enclosingNodeType]; return continuationsFromEnclosingType( result, @@ -368,7 +375,7 @@ function* continuationsFromIssue( for (let i = 0; i < result.comments.nodes.length; i++) { const comment = result.comments.nodes[i]; const subpath = [...path, "comments", "nodes", i]; - yield* continuationsFromComment(comment, comment.id, subpath); + yield* continuationsFromIssueComment(comment, comment.id, subpath); } } } @@ -447,7 +454,7 @@ function* continuationsFromPR( for (let i = 0; i < result.comments.nodes.length; i++) { const comment = result.comments.nodes[i]; const subpath = [...path, "comments", "nodes", i]; - yield* continuationsFromComment(comment, comment.id, subpath); + yield* continuationsFromIssueComment(comment, comment.id, subpath); } } } @@ -477,9 +484,17 @@ function* continuationsFromReview( destinationPath: path, }; } + if (result.comments) { + for (let i = 0; i < result.comments.nodes.length; i++) { + const comment = result.comments.nodes[i]; + const subpath = [...path, "comments", "nodes", i]; + yield* continuationsFromReviewComment(comment, comment.id, subpath); + } + } } -function* continuationsFromComment( +// Pull Request comments are also issue comments. +function* continuationsFromIssueComment( result: any, nodeId: string, path: $ReadOnlyArray @@ -487,7 +502,7 @@ function* continuationsFromComment( const b = build; if (result.reactions && result.reactions.pageInfo.hasNextPage) { yield { - enclosingNodeType: "COMMENT", + enclosingNodeType: "ISSUE_COMMENT", enclosingNodeId: nodeId, selections: [ b.inlineFragment("IssueComment", [ @@ -506,6 +521,33 @@ function* continuationsFromComment( } } +function* continuationsFromReviewComment( + result: any, + nodeId: string, + path: $ReadOnlyArray +): Iterator { + const b = build; + if (result.reactions && result.reactions.pageInfo.hasNextPage) { + yield { + enclosingNodeType: "REVIEW_COMMENT", + enclosingNodeId: nodeId, + selections: [ + b.inlineFragment("PullRequestReviewComment", [ + b.field( + "reactions", + { + first: b.literal(PAGE_LIMIT), + after: b.literal(result.reactions.pageInfo.endCursor), + }, + [b.fragmentSpread("reactions")] + ), + ]), + ], + destinationPath: path, + }; + } +} + /** * Execute the given query, returning all pages of data throughout the * query. That is: post the query, then find any entities that require