github: fix misc. errors in old GraphQL system (#929)

Summary:
This fixes the following issues:

  - Pull request reviews actually do not have reactions.
  - We must fetch the `id` of a `Ref`.
  - We must fetch the `id` of a `Commit`, `Tree`, `Blob`, or `Tag`, and
    should also fetch its `oid`.
  - Repository owners cannot be bots.
  - Commit and reaction authors cannot be bots, organizations, or
    `undefined`.

Test Plan:
Running `yarn test --full` passes, and the snapshot diff is clearly
correct.

wchargin-branch: github-fix-up-continuations
This commit is contained in:
William Chargin 2018-10-22 09:50:24 -07:00 committed by GitHub
parent 889febb7f6
commit 6499df6b6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 12 deletions

View File

@ -217,6 +217,7 @@ exports[`plugins/github/graphql creates a query 1`] = `
...pulls ...pulls
} }
defaultBranchRef { defaultBranchRef {
id
target { target {
__typename __typename
... on Commit { ... on Commit {
@ -224,6 +225,18 @@ exports[`plugins/github/graphql creates a query 1`] = `
...commitHistory ...commitHistory
} }
} }
... on Blob {
id
oid
}
... on Tag {
id
oid
}
... on Tree {
id
oid
}
} }
} }
} }

View File

@ -1,6 +1,7 @@
{ {
"repository": { "repository": {
"defaultBranchRef": { "defaultBranchRef": {
"id": "MDM6UmVmMTIzMjU1MDA2Om1hc3Rlcg==",
"target": { "target": {
"__typename": "Commit", "__typename": "Commit",
"history": { "history": {

View File

@ -119,16 +119,21 @@ export type RepositoryJSON = {|
+pulls: ConnectionJSON<PullJSON>, +pulls: ConnectionJSON<PullJSON>,
+url: string, +url: string,
+name: string, +name: string,
+owner: AuthorJSON, +owner: UserJSON | OrganizationJSON,
+defaultBranchRef: ?RefJSON, +defaultBranchRef: ?RefJSON,
|}; |};
export type RefJSON = {|+target: GitObjectJSON|}; export type RefJSON = {|+id: string, +target: GitObjectJSON|};
export type GitObjectJSON = export type GitObjectJSON =
| {|+__typename: "Commit", +history: ConnectionJSON<CommitJSON>|} | {|
| {|+__typename: "Tree"|} +__typename: "Commit",
| {|+__typename: "Blob"|} +id: string,
| {|+__typename: "Tag"|}; +oid: string,
+history: ConnectionJSON<CommitJSON>,
|}
| {|+__typename: "Tree", +id: string, +oid: string|}
| {|+__typename: "Blob", +id: string, +oid: string|}
| {|+__typename: "Tag", +id: string, +oid: string|};
/** /**
* The top-level GitHub query to request data about a repository. * The top-level GitHub query to request data about a repository.
@ -159,6 +164,7 @@ export function createQuery(): Body {
]) ])
), ),
b.field("defaultBranchRef", {}, [ b.field("defaultBranchRef", {}, [
b.field("id"),
b.field("target", {}, [ b.field("target", {}, [
b.field("__typename"), b.field("__typename"),
b.inlineFragment("Commit", [ b.inlineFragment("Commit", [
@ -168,6 +174,9 @@ export function createQuery(): Body {
[b.fragmentSpread("commitHistory")] [b.fragmentSpread("commitHistory")]
), ),
]), ]),
b.inlineFragment("Blob", [b.field("id"), b.field("oid")]),
b.inlineFragment("Tag", [b.field("id"), b.field("oid")]),
b.inlineFragment("Tree", [b.field("id"), b.field("oid")]),
]), ]),
]), ]),
] ]
@ -871,12 +880,26 @@ function mergeDirect<T>(destination: T, source: any): T {
// Therefore, NullableAuthorJSON is preferred to AuthorJSON // Therefore, NullableAuthorJSON is preferred to AuthorJSON
// for most actual usage. // for most actual usage.
export type NullableAuthorJSON = AuthorJSON | null; export type NullableAuthorJSON = AuthorJSON | null;
export type AuthorJSON = {| export type AuthorJSON = UserJSON | BotJSON | OrganizationJSON;
+__typename: "User" | "Bot" | "Organization", export type UserJSON = {|
+__typename: "User",
+id: string, +id: string,
+login: string, +login: string,
+url: string, +url: string,
|}; |};
export type BotJSON = {|
+__typename: "Bot",
+id: string,
+login: string,
+url: string,
|};
export type OrganizationJSON = {|
+__typename: "Organization",
+id: string,
+login: string,
+url: string,
|};
function makePageInfo() { function makePageInfo() {
const b = build; const b = build;
return b.field("pageInfo", {}, [ return b.field("pageInfo", {}, [
@ -1012,7 +1035,6 @@ export type ReviewJSON = {|
+author: NullableAuthorJSON, +author: NullableAuthorJSON,
+state: ReviewState, +state: ReviewState,
+comments: ConnectionJSON<ReviewCommentJSON>, +comments: ConnectionJSON<ReviewCommentJSON>,
+reactions: ConnectionJSON<ReactionJSON>,
|}; |};
function reviewsFragment(): FragmentDefinition { function reviewsFragment(): FragmentDefinition {
const b = build; const b = build;
@ -1058,9 +1080,9 @@ export type CommitJSON = {|
+id: string, +id: string,
+url: string, +url: string,
+oid: string, // the hash +oid: string, // the hash
+author: ?{| +author: null | {|
+date: /* ISO 8601 */ string, +date: /* ISO 8601 */ string,
+user: NullableAuthorJSON, +user: null | UserJSON,
|}, |},
+message: string, +message: string,
+parents: ConnectionJSON<{|+oid: string|}>, +parents: ConnectionJSON<{|+oid: string|}>,
@ -1126,7 +1148,7 @@ export type ReactionContent =
export type ReactionJSON = {| export type ReactionJSON = {|
+id: string, +id: string,
+content: ReactionContent, +content: ReactionContent,
+user: NullableAuthorJSON, +user: null | UserJSON,
|}; |};
function reactionsFragment(): FragmentDefinition { function reactionsFragment(): FragmentDefinition {