diff --git a/src/plugins/github/fetchGithubRepo.js b/src/plugins/github/fetchGithubRepo.js index 2c4a4f9..f29cf08 100644 --- a/src/plugins/github/fetchGithubRepo.js +++ b/src/plugins/github/fetchGithubRepo.js @@ -8,7 +8,7 @@ import fetch from "isomorphic-fetch"; import {stringify, inlineLayout} from "../../graphql/queries"; import {createQuery, createVariables, postQueryExhaustive} from "./graphql"; -import type {RepositoryJSON} from "./graphql"; +import type {GithubResponseJSON} from "./graphql"; /** * Scrape data from a GitHub repo using the GitHub API. @@ -29,7 +29,7 @@ export default function fetchGithubRepo( repoOwner: string, repoName: string, token: string -): Promise { +): Promise { repoOwner = String(repoOwner); repoName = String(repoName); token = String(token); @@ -52,7 +52,7 @@ export default function fetchGithubRepo( return postQueryExhaustive( (somePayload) => postQuery(somePayload, token), payload - ).then((x: RepositoryJSON) => { + ).then((x: GithubResponseJSON) => { ensureNoMorePages(x); return x; }); diff --git a/src/plugins/github/graphql.js b/src/plugins/github/graphql.js index 29e8e68..c4693c1 100644 --- a/src/plugins/github/graphql.js +++ b/src/plugins/github/graphql.js @@ -101,12 +101,14 @@ export type ConnectionJSON<+T> = {| |}, |}; +export type GithubResponseJSON = {| + +repository: RepositoryJSON, +|}; + export type RepositoryJSON = {| - +repository: { - +id: string, - +issues: ConnectionJSON, - +pullRequests: ConnectionJSON, - }, + +id: string, + +issues: ConnectionJSON, + +pullRequests: ConnectionJSON, |}; /** diff --git a/src/plugins/github/parser.js b/src/plugins/github/parser.js index 1a5ef2b..dad422e 100644 --- a/src/plugins/github/parser.js +++ b/src/plugins/github/parser.js @@ -21,6 +21,7 @@ import type { import {MERGED_AS_EDGE_TYPE} from "./types"; import type { + GithubResponseJSON, RepositoryJSON, PullRequestReviewJSON, PullRequestJSON, @@ -36,10 +37,10 @@ import {findReferences} from "./findReferences"; import {commitAddress} from "../git/address"; export function parse( - repositoryJSON: RepositoryJSON + githubResponseJSON: GithubResponseJSON ): Graph { const parser = new GithubParser(); - parser.addData(repositoryJSON); + parser.addData(githubResponseJSON); parser.addReferenceEdges(); return parser.graph; } @@ -320,10 +321,12 @@ class GithubParser { return danglingReferences; } - addData(dataJson: RepositoryJSON) { - dataJson.repository.issues.nodes.forEach((i) => this.addIssue(i)); - dataJson.repository.pullRequests.nodes.forEach((pr) => - this.addPullRequest(pr) - ); + addRepository(repositoryJSON: RepositoryJSON) { + repositoryJSON.issues.nodes.forEach((i) => this.addIssue(i)); + repositoryJSON.pullRequests.nodes.forEach((pr) => this.addPullRequest(pr)); + } + + addData(dataJson: GithubResponseJSON) { + this.addRepository(dataJson.repository); } } diff --git a/src/plugins/github/parser.test.js b/src/plugins/github/parser.test.js index 2ecfd94..9fea5ca 100644 --- a/src/plugins/github/parser.test.js +++ b/src/plugins/github/parser.test.js @@ -3,7 +3,7 @@ import {AUTHORS_EDGE_TYPE, CONTAINS_EDGE_TYPE} from "./types"; import type {NodePayload, EdgePayload} from "./types"; import {parse} from "./parser"; -import type {RepositoryJSON, PullRequestJSON, IssueJSON} from "./graphql"; +import type {GithubResponseJSON, PullRequestJSON, IssueJSON} from "./graphql"; import {Graph} from "../../core/graph"; import exampleRepoData from "./demoData/example-github.json"; @@ -95,7 +95,7 @@ describe("GithubParser", () => { }: ExampleInput): Graph { const issues = issueNums.map(getIssue); const pullRequests = prNums.map(getPR); - const exampleData: RepositoryJSON = { + const exampleData: GithubResponseJSON = { repository: { id: exampleRepoData.repository.id, issues: {