GitHub parser now recognizes pull request reviews (#91)

Also, since there are now two types of things that are being
"contained" (comments and pull request reviews), I factored out an
addContainment method to avoid repeating that code.

To make our handling of PullRequestReviewComments and regular Comments
consistent, I modified our query string so that we now request urls on
PullRequestReviewComments. Also, since I didn't notice until closely
inspecting the snapshot that we had been adding payloads with some
undefined properties, I added a test to verify that every property on
every node and edge payload is defined.

I regenerated the example-repo data to reflect the change to query
string.

Test plan:
Verify that the snapshot changes are appropriate
Run standard tests
Run `yarn backend`
Run `GITHUB_TOKEN={your_token} ./src/plugins/github/fetchGithubRepoTest.sh`
This commit is contained in:
Dandelion Mané 2018-03-20 11:46:46 -07:00 committed by GitHub
parent ab6e0d91a8
commit 02754d2523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 331 additions and 11 deletions

View File

@ -148,8 +148,98 @@ Object {
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"authorID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDQ6VXNlcjQzMTc4MDY=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"USER\\\\\\"},\\\\\\"contributionID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzE0MDM4\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"AUTHORSHIP\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDQ6VXNlcjQzMTc4MDY=\\",\\"type\\":\\"USER\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzE0MDM4\\",\\"type\\":\\"PULL_REQUEST_REVIEW\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"authorID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDQ6VXNlcjQzMTc4MDY=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"USER\\\\\\"},\\\\\\"contributionID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"AUTHORSHIP\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDQ6VXNlcjQzMTc4MDY=\\",\\"type\\":\\"USER\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\",\\"type\\":\\"PULL_REQUEST_REVIEW\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"authorID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDQ6VXNlcjQzMTc4MDY=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"USER\\\\\\"},\\\\\\"contributionID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW_COMMENT\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"AUTHORSHIP\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDQ6VXNlcjQzMTc4MDY=\\",\\"type\\":\\"USER\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==\\",\\"type\\":\\"PULL_REQUEST_REVIEW_COMMENT\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"childID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzE0MDM4\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"},\\\\\\"parentID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDExOlB1bGxSZXF1ZXN0MTcxODg4NTIy\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"CONTAINMENT\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzE0MDM4\\",\\"type\\":\\"PULL_REQUEST_REVIEW\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDExOlB1bGxSZXF1ZXN0MTcxODg4NTIy\\",\\"type\\":\\"PULL_REQUEST\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"childID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"},\\\\\\"parentID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDExOlB1bGxSZXF1ZXN0MTcxODg4NTIy\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"CONTAINMENT\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\",\\"type\\":\\"PULL_REQUEST_REVIEW\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDExOlB1bGxSZXF1ZXN0MTcxODg4NTIy\\",\\"type\\":\\"PULL_REQUEST\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"childID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW_COMMENT\\\\\\"},\\\\\\"parentID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"CONTAINMENT\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==\\",\\"type\\":\\"PULL_REQUEST_REVIEW_COMMENT\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\",\\"type\\":\\"PULL_REQUEST_REVIEW\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
},
"nodes": Object {
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzE0MDM4\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"}\\"}": Object {
"payload": Object {
"body": "I'm sold",
"state": "APPROVED",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"}\\"}": Object {
"payload": Object {
"body": "hmmm.jpg",
"state": "CHANGES_REQUESTED",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDExOlB1bGxSZXF1ZXN0MTcxODg4NTIy\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"}\\"}": Object {
"payload": Object {
"body": "@wchargin could you please do the following:
@ -161,11 +251,22 @@ Object {
"title": "This pull request will be more contentious. I can feel it...",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW_COMMENT\\\\\\"}\\"}": Object {
"payload": Object {
"body": "seems a bit capricious",
"url": "https://github.com/sourcecred/example-repo/pull/5#discussion_r171460198",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDQ6VXNlcjE0MDAwMjM=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"USER\\\\\\"}\\"}": Object {
"payload": Object {
"login": "dandelionmane",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDQ6VXNlcjQzMTc4MDY=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"USER\\\\\\"}\\"}": Object {
"payload": Object {
"login": "wchargin",
},
},
},
}
`;
@ -382,6 +483,71 @@ Object {
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"authorID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDQ6VXNlcjQzMTc4MDY=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"USER\\\\\\"},\\\\\\"contributionID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzE0MDM4\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"AUTHORSHIP\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDQ6VXNlcjQzMTc4MDY=\\",\\"type\\":\\"USER\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzE0MDM4\\",\\"type\\":\\"PULL_REQUEST_REVIEW\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"authorID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDQ6VXNlcjQzMTc4MDY=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"USER\\\\\\"},\\\\\\"contributionID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"AUTHORSHIP\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDQ6VXNlcjQzMTc4MDY=\\",\\"type\\":\\"USER\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\",\\"type\\":\\"PULL_REQUEST_REVIEW\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"authorID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDQ6VXNlcjQzMTc4MDY=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"USER\\\\\\"},\\\\\\"contributionID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW_COMMENT\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"AUTHORSHIP\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDQ6VXNlcjQzMTc4MDY=\\",\\"type\\":\\"USER\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==\\",\\"type\\":\\"PULL_REQUEST_REVIEW_COMMENT\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"childID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzE0MDM4\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"},\\\\\\"parentID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDExOlB1bGxSZXF1ZXN0MTcxODg4NTIy\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"CONTAINMENT\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzE0MDM4\\",\\"type\\":\\"PULL_REQUEST_REVIEW\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDExOlB1bGxSZXF1ZXN0MTcxODg4NTIy\\",\\"type\\":\\"PULL_REQUEST\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"childID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"},\\\\\\"parentID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDExOlB1bGxSZXF1ZXN0MTcxODg4NTIy\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"CONTAINMENT\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\",\\"type\\":\\"PULL_REQUEST_REVIEW\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDExOlB1bGxSZXF1ZXN0MTcxODg4NTIy\\",\\"type\\":\\"PULL_REQUEST\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"childID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDEyOklzc3VlQ29tbWVudDM2OTE2MjIyMg==\\\\\\",\\\\\\"type\\\\\\":\\\\\\"COMMENT\\\\\\"},\\\\\\"parentID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDExOlB1bGxSZXF1ZXN0MTcxODg3NzQx\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"CONTAINMENT\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDEyOklzc3VlQ29tbWVudDM2OTE2MjIyMg==\\",\\"type\\":\\"COMMENT\\"}",
@ -447,8 +613,33 @@ Object {
"repositoryName": "sourcecred/example-repo",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"childID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW_COMMENT\\\\\\"},\\\\\\"parentID\\\\\\":{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"},\\\\\\"type\\\\\\":\\\\\\"CONTAINMENT\\\\\\"}\\"}": Object {
"dst": Object {
"id": "{\\"id\\":\\"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==\\",\\"type\\":\\"PULL_REQUEST_REVIEW_COMMENT\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
"payload": Object {},
"src": Object {
"id": "{\\"id\\":\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\",\\"type\\":\\"PULL_REQUEST_REVIEW\\"}",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
},
},
},
"nodes": Object {
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzE0MDM4\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"}\\"}": Object {
"payload": Object {
"body": "I'm sold",
"state": "APPROVED",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTAwMzEzODk5\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW\\\\\\"}\\"}": Object {
"payload": Object {
"body": "hmmm.jpg",
"state": "CHANGES_REQUESTED",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDExOlB1bGxSZXF1ZXN0MTcxODg3NzQx\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST\\\\\\"}\\"}": Object {
"payload": Object {
"body": "Oh look, it's a pull request.",
@ -498,11 +689,22 @@ https://github.com/sourcecred/example-repo/issues/6#issuecomment-373768538",
"url": "https://github.com/sourcecred/example-repo/issues/2#issuecomment-373768850",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==\\\\\\",\\\\\\"type\\\\\\":\\\\\\"PULL_REQUEST_REVIEW_COMMENT\\\\\\"}\\"}": Object {
"payload": Object {
"body": "seems a bit capricious",
"url": "https://github.com/sourcecred/example-repo/pull/5#discussion_r171460198",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDQ6VXNlcjE0MDAwMjM=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"USER\\\\\\"}\\"}": Object {
"payload": Object {
"login": "dandelionmane",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDQ6VXNlcjQzMTc4MDY=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"USER\\\\\\"}\\"}": Object {
"payload": Object {
"login": "wchargin",
},
},
"{\\"pluginName\\":\\"sourcecred/github-beta\\",\\"repositoryName\\":\\"sourcecred/example-repo\\",\\"id\\":\\"{\\\\\\"id\\\\\\":\\\\\\"MDU6SXNzdWUzMDA5MzQ4MTg=\\\\\\",\\\\\\"type\\\\\\":\\\\\\"ISSUE\\\\\\"}\\"}": Object {
"payload": Object {
"body": "This is just an example issue.",

View File

@ -191,7 +191,8 @@
"login": "wchargin"
},
"body": "seems a bit capricious",
"id": "MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA=="
"id": "MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3MTQ2MDE5OA==",
"url": "https://github.com/sourcecred/example-repo/pull/5#discussion_r171460198"
}
],
"pageInfo": {

View File

@ -113,6 +113,7 @@ export default function fetchGitHubRepo(
}
nodes {
id
url
body
author {
...whoami

View File

@ -27,6 +27,21 @@ export type PullRequestNodeID = {|
+id: string,
|};
export type PullRequestReviewState =
| "CHANGES_REQUESTED"
| "APPROVED"
| "COMMENTED"
| "DISMISSED"
| "PENDING";
export type PullRequestReviewNodePayload = {|
+body: string,
+state: PullRequestReviewState,
|};
export type PullRequestReviewNodeID = {|
+type: "PULL_REQUEST_REVIEW",
+id: string,
|};
export type CommentNodePayload = {|
+url: string,
+body: string,
@ -36,6 +51,18 @@ export type CommentNodeID = {|
+id: string,
|};
// We have this as a separate type from regular comments because we may
// be interested in diff hunks, which are only present on PR review
// comments.
export type PullRequestReviewCommentNodePayload = {|
+url: string,
+body: string,
|};
export type PullRequestReviewCommentNodeID = {|
+type: "PULL_REQUEST_REVIEW_COMMENT",
+id: string,
|};
export type UserNodePayload = {|
+login: string,
|};
@ -70,11 +97,15 @@ export type NodePayload =
| IssueNodePayload
| PullRequestNodePayload
| CommentNodePayload
| PullRequestReviewCommentNodePayload
| PullRequestReviewNodePayload
| AuthorNodePayload;
export type NodeID =
| IssueNodeID
| PullRequestNodeID
| PullRequestReviewCommentNodeID
| CommentNodeID
| PullRequestReviewNodeID
| AuthorNodeID;
export type NodeType = $ElementType<NodeID, "type">;
@ -130,9 +161,18 @@ export class GithubParser {
}
addAuthorship(
authoredNodeID: IssueNodeID | PullRequestNodeID | CommentNodeID,
authoredNodeID:
| IssueNodeID
| PullRequestNodeID
| CommentNodeID
| PullRequestReviewCommentNodeID
| PullRequestReviewNodeID,
authoredNode: Node<
IssueNodePayload | PullRequestNodePayload | CommentNodePayload
| IssueNodePayload
| PullRequestNodePayload
| CommentNodePayload
| PullRequestReviewCommentNodePayload
| PullRequestReviewNodePayload
>,
authorJson: *
) {
@ -177,33 +217,63 @@ export class GithubParser {
}
addComment(
parentID: IssueNodeID | PullRequestNodeID,
parentNode: Node<IssueNodePayload | PullRequestNodePayload>,
parentID: IssueNodeID | PullRequestNodeID | PullRequestReviewNodeID,
parentNode: Node<
IssueNodePayload | PullRequestNodePayload | PullRequestReviewNodePayload
>,
commentJson: *
) {
const commentID: CommentNodeID = {type: "COMMENT", id: commentJson.id};
const commentNodePayload: CommentNodePayload = {
let commentID: CommentNodeID | PullRequestReviewCommentNodeID;
if (parentID.type === "PULL_REQUEST_REVIEW") {
commentID = {type: "PULL_REQUEST_REVIEW_COMMENT", id: commentJson.id};
} else if (parentID.type === "ISSUE" || parentID.type === "PULL_REQUEST") {
commentID = {type: "COMMENT", id: commentJson.id};
} else {
throw new Error(`Unexpected comment parent type ${parentID.type}`);
}
const commentNodePayload:
| CommentNodePayload
| PullRequestReviewCommentNodePayload = {
body: commentJson.body,
url: commentJson.url,
};
const commentNode: Node<CommentNodePayload> = {
const commentNode: Node<
CommentNodePayload | PullRequestReviewCommentNodePayload
> = {
address: this.makeAddress(commentID),
payload: commentNodePayload,
};
this.graph.addNode(commentNode);
this.addAuthorship(commentID, commentNode, commentJson.author);
this.addContainment(parentID, parentNode, commentID, commentNode);
}
addContainment(
parentID: IssueNodeID | PullRequestNodeID | PullRequestReviewNodeID,
parentNode: Node<
IssueNodePayload | PullRequestNodePayload | PullRequestReviewNodePayload
>,
childID:
| CommentNodeID
| PullRequestReviewCommentNodeID
| PullRequestReviewNodeID,
childNode: Node<
| CommentNodePayload
| PullRequestReviewCommentNodePayload
| PullRequestReviewNodePayload
>
) {
const containmentID: ContainmentEdgeID = {
type: "CONTAINMENT",
childID: commentID,
parentID: parentID,
childID,
parentID,
};
const containmentEdge = {
address: this.makeAddress(containmentID),
payload: {},
src: parentNode.address,
dst: commentNode.address,
dst: childNode.address,
};
this.graph.addEdge(containmentEdge);
}
@ -248,6 +318,35 @@ export class GithubParser {
prJson.comments.nodes.forEach((c) =>
this.addComment(pullRequestID, pullRequestNode, c)
);
prJson.reviews.nodes.forEach((r) =>
this.addPullRequestReview(pullRequestID, pullRequestNode, r)
);
}
addPullRequestReview(
pullRequestID: PullRequestNodeID,
pullRequestNode: Node<PullRequestNodePayload>,
reviewJson: *
) {
const reviewID: PullRequestReviewNodeID = {
type: "PULL_REQUEST_REVIEW",
id: reviewJson.id,
};
const reviewPayload: PullRequestReviewNodePayload = {
state: reviewJson.state,
body: reviewJson.body,
};
const reviewNode: Node<PullRequestReviewNodePayload> = {
address: this.makeAddress(reviewID),
payload: reviewPayload,
};
this.graph.addNode(reviewNode);
this.addContainment(pullRequestID, pullRequestNode, reviewID, reviewNode);
this.addAuthorship(reviewID, reviewNode, reviewJson.author);
reviewJson.comments.nodes.forEach((c) =>
this.addComment(reviewID, reviewNode, c)
);
}
addData(dataJson: *) {

View File

@ -13,6 +13,23 @@ describe("GithubParser", () => {
expect(graph).toMatchSnapshot();
});
it("no node or edge has undefined properties in its payload", () => {
graph
.getAllNodes()
.forEach((n) =>
Object.keys(n.payload).forEach((k) =>
expect((n.payload: any)[k]).toBeDefined()
)
);
graph
.getAllEdges()
.forEach((e) =>
Object.keys(e.payload).forEach((k) =>
expect((e.payload: any)[k]).toBeDefined()
)
);
});
it("every comment has an author and container", () => {
const comments = graph
.getAllNodes()