Add return type info for fetchGithubRepo (#143)
Once the type was added, flow correctly discovered a bug in GithubGraphFetcher.js, which resulted in broken graph fetching in the ArtifactEditor. Oops! / Good work Flow! I made `ensureNoMorePages` expect the result it is testing to be an `any`, which is appropriate for how the function is written (i.e. it is written in a way that is agnostic to the actual result).
This commit is contained in:
parent
8fdfacd097
commit
4f857a8bb1
|
@ -33,7 +33,7 @@ export class GithubGraphFetcher extends React.Component<Props> {
|
||||||
fetchGithubRepo(repoOwner, repoName, githubApiToken)
|
fetchGithubRepo(repoOwner, repoName, githubApiToken)
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
const parser = new GithubParser(`${repoOwner}/${repoName}`);
|
const parser = new GithubParser(`${repoOwner}/${repoName}`);
|
||||||
parser.addData(json.data);
|
parser.addData(json);
|
||||||
return Promise.resolve(parser.graph);
|
return Promise.resolve(parser.graph);
|
||||||
})
|
})
|
||||||
.then((graph) => {
|
.then((graph) => {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import fetch from "isomorphic-fetch";
|
||||||
|
|
||||||
import {stringify, inlineLayout} from "../../graphql/queries";
|
import {stringify, inlineLayout} from "../../graphql/queries";
|
||||||
import {createQuery, createVariables, postQueryExhaustive} from "./graphql";
|
import {createQuery, createVariables, postQueryExhaustive} from "./graphql";
|
||||||
|
import type {RepositoryJSON} from "./graphql";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scrape data from a GitHub repo using the GitHub API.
|
* Scrape data from a GitHub repo using the GitHub API.
|
||||||
|
@ -28,7 +29,7 @@ export default function fetchGithubRepo(
|
||||||
repoOwner: string,
|
repoOwner: string,
|
||||||
repoName: string,
|
repoName: string,
|
||||||
token: string
|
token: string
|
||||||
): Promise<Object> {
|
): Promise<RepositoryJSON> {
|
||||||
repoOwner = String(repoOwner);
|
repoOwner = String(repoOwner);
|
||||||
repoName = String(repoName);
|
repoName = String(repoName);
|
||||||
token = String(token);
|
token = String(token);
|
||||||
|
@ -51,7 +52,7 @@ export default function fetchGithubRepo(
|
||||||
return postQueryExhaustive(
|
return postQueryExhaustive(
|
||||||
(somePayload) => postQuery(somePayload, token),
|
(somePayload) => postQuery(somePayload, token),
|
||||||
payload
|
payload
|
||||||
).then((x) => {
|
).then((x: RepositoryJSON) => {
|
||||||
ensureNoMorePages(x);
|
ensureNoMorePages(x);
|
||||||
return x;
|
return x;
|
||||||
});
|
});
|
||||||
|
@ -80,7 +81,7 @@ function postQuery({body, variables}, token) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureNoMorePages(result, path = []) {
|
function ensureNoMorePages(result: any, path = []) {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue