Open History to see the last commit
1# Reads of the signed-in account, one pull request, or its repository.
2
3query RoutingIdentityViewer {
4 viewer {
5 databaseId
6 login
7 }
8}
9
10# Resolves a listing's authors to avatars, which no listing field carries.
11query ActorAvatars($ids: [ID!]!) {
12 nodes(ids: $ids) {
13 ... on User {
14 login
15 avatarUrl
16 }
17 ... on Bot {
18 login
19 avatarUrl
20 }
21 }
22}
23
24# A check context of the head commit. `isRequired` is asked for on github.com only (`$required`):
25# an older Enterprise server may not know it, and an unknown field fails the whole read.
26fragment CheckContext on StatusCheckRollupContext {
27 ... on StatusContext {
28 context
29 state
30 targetUrl
31 createdAt
32 description
33 isRequired(pullRequestNumber: $number) @include(if: $required)
34 }
35 ... on CheckRun {
36 name
37 status
38 conclusion
39 startedAt
40 completedAt
41 detailsUrl
42 isRequired(pullRequestNumber: $number) @include(if: $required)
43 checkSuite {
44 workflowRun {
45 workflow {
46 name
47 }
48 }
49 }
50 }
51}
52
53# The detail of a pull request with the viewer's standing on it. Pull refs let the comparison
54# (`$headRef` is `refs/pull/<number>/head`) share this read without first resolving a fork branch.
55query PullRequestCore(
56 $owner: String!
57 $name: String!
58 $number: Int!
59 $headRef: String!
60 $required: Boolean!
61 $requestedReviewers: Int!
62) {
63 repository(owner: $owner, name: $name) {
64 mergeCommitAllowed
65 squashMergeAllowed
66 rebaseMergeAllowed
67 autoMergeAllowed
68 viewerPermission
69 pullRequest(number: $number) {
70 number
71 title
72 url
73 body
74 state
75 isDraft
76 mergeable
77 mergeStateStatus
78 reviewDecision
79 additions
80 deletions
81 changedFiles
82 createdAt
83 updatedAt
84 mergedAt
85 closedAt
86 headRefName
87 baseRefName
88 headRefOid
89 isCrossRepository
90 maintainerCanModify
91 headRepositoryOwner {
92 login
93 }
94 # The source branch's own repository and ref, which is what deleting the branch needs: write
95 # there, and a branch still to delete.
96 headRepository {
97 nameWithOwner
98 viewerPermission
99 }
100 headRef {
101 id
102 }
103 author {
104 login
105 avatarUrl
106 ... on User {
107 id
108 name
109 }
110 }
111 autoMergeRequest {
112 mergeMethod
113 }
114 viewerCanUpdate
115 viewerDidAuthor
116 viewerCanUpdateBranch
117 baseRef {
118 compare(headRef: $headRef) {
119 behindBy
120 }
121 }
122 reviewRequests(first: $requestedReviewers) {
123 nodes {
124 requestedReviewer {
125 ... on User {
126 login
127 name
128 }
129 ... on Bot {
130 login
131 }
132 # A team's name and avatar are nullable differently from a person's, so they travel
133 # under their own aliases. `combinedSlug` is the `org/slug` a reviewer row shows.
134 ... on Team {
135 slug
136 combinedSlug
137 teamName: name
138 teamAvatarUrl: avatarUrl
139 }
140 }
141 }
142 }
143 labels(first: 100) {
144 nodes {
145 name
146 color
147 }
148 }
149 commits(last: 1) {
150 nodes {
151 commit {
152 statusCheckRollup {
153 contexts(first: 100) {
154 nodes {
155 ...CheckContext
156 }
157 pageInfo {
158 hasNextPage
159 }
160 }
161 }
162 }
163 }
164 }
165 }
166 }
167}
168
169# Every check context of the head commit, a page at a time, for a rollup past one page.
170query PullRequestCheckContexts(
171 $owner: String!
172 $name: String!
173 $number: Int!
174 $required: Boolean!
175 $after: String
176) {
177 repository(owner: $owner, name: $name) {
178 pullRequest(number: $number) {
179 headRefOid
180 commits(last: 1) {
181 nodes {
182 commit {
183 statusCheckRollup {
184 contexts(first: 100, after: $after) {
185 nodes {
186 ...CheckContext
187 }
188 pageInfo {
189 hasNextPage
190 endCursor
191 }
192 }
193 }
194 }
195 }
196 }
197 }
198 }
199}
200
201query PullRequestPreview($owner: String!, $name: String!, $number: Int!) {
202 repository(owner: $owner, name: $name) {
203 pullRequest(number: $number) {
204 number
205 title
206 url
207 state
208 isDraft
209 createdAt
210 author {
211 login
212 avatarUrl
213 ... on User {
214 name
215 }
216 }
217 }
218 }
219}
220
221# The conversation a pull request carries outside its review threads: who opened it, its issue
222# comments, its reviews and its newest commits. The two remark connections page independently, so
223# each is switched on only while it has more to give; the first read (`$head`) asks for everything.
224query PullRequestActivity(
225 $owner: String!
226 $name: String!
227 $number: Int!
228 $head: Boolean!
229 $withComments: Boolean!
230 $commentsAfter: String
231 $withReviews: Boolean!
232 $reviewsAfter: String
233) {
234 repository(owner: $owner, name: $name) {
235 pullRequest(number: $number) {
236 author @include(if: $head) {
237 login
238 avatarUrl
239 ... on User {
240 name
241 }
242 }
243 commits(last: 100) @include(if: $head) {
244 nodes {
245 commit {
246 id
247 oid
248 messageHeadline
249 committedDate
250 parents(first: 1) {
251 totalCount
252 }
253 authors(first: 10) {
254 nodes {
255 name
256 email
257 user {
258 login
259 }
260 }
261 }
262 }
263 }
264 }
265 comments(first: 100, after: $commentsAfter) @include(if: $withComments) {
266 pageInfo {
267 hasNextPage
268 endCursor
269 }
270 nodes {
271 id
272 body
273 createdAt
274 lastEditedAt
275 url
276 author {
277 login
278 avatarUrl
279 ... on User {
280 name
281 }
282 }
283 }
284 }
285 reviews(first: 100, after: $reviewsAfter) @include(if: $withReviews) {
286 pageInfo {
287 hasNextPage
288 endCursor
289 }
290 nodes {
291 id
292 body
293 state
294 submittedAt
295 lastEditedAt
296 url
297 author {
298 login
299 avatarUrl
300 ... on User {
301 name
302 }
303 }
304 }
305 }
306 }
307 }
308}
309
310# Merge commits include upstream changes in their stats, which the timeline does not display.
311# Read only the non-merge commits named by the activity connection.
312query PullRequestCommitStats($ids: [ID!]!) {
313 nodes(ids: $ids) {
314 ... on Commit {
315 oid
316 additions
317 deletions
318 }
319 }
320}
321
322# Open pull requests whose head branch has one name, from whichever repository it lives in.
323query PullRequestHeads($owner: String!, $name: String!, $head: String!, $after: String) {
324 repository(owner: $owner, name: $name) {
325 pullRequests(first: 100, after: $after, states: [OPEN], headRefName: $head) {
326 pageInfo {
327 hasNextPage
328 endCursor
329 }
330 nodes {
331 number
332 headRefOid
333 isCrossRepository
334 headRepositoryOwner {
335 login
336 }
337 }
338 }
339 }
340}
341
342# The pull request's own node id, which is what a mutation against the pull request itself is
343# addressed by. Read only when one is being written: the conversation carries an id for every
344# remark in it, and the pull request is the one subject nothing in it names.
345query PullRequestNodeId($owner: String!, $name: String!, $number: Int!) {
346 repository(owner: $owner, name: $name) {
347 pullRequest(number: $number) {
348 id
349 }
350 }
351}
352
353# Where a client-given subject actually hangs: the pull request itself, or the pull request an
354# issue comment, a review comment, or a review belongs to. Read before a mutation reaches it, so a
355# subject named for one pull request cannot write on another's behalf.
356query PullRequestSubject($owner: String!, $name: String!, $number: Int!, $subjectId: ID!) {
357 repository(owner: $owner, name: $name) {
358 pullRequest(number: $number) {
359 id
360 }
361 }
362 node(id: $subjectId) {
363 id
364 ... on IssueComment {
365 pullRequest {
366 id
367 }
368 }
369 # Aliased apart: an issue comment's pull request is nullable, the other two are not.
370 ... on PullRequestReviewComment {
371 reviewCommentPullRequest: pullRequest {
372 id
373 }
374 }
375 ... on PullRequestReview {
376 reviewPullRequest: pullRequest {
377 id
378 }
379 }
380 }
381}
382
383# Core detail and write checks share one read of permissions and merge settings.
384query ViewerPermissions($owner: String!, $name: String!, $number: Int!) {
385 repository(owner: $owner, name: $name) {
386 mergeCommitAllowed
387 squashMergeAllowed
388 rebaseMergeAllowed
389 autoMergeAllowed
390 viewerPermission
391 pullRequest(number: $number) {
392 viewerCanUpdate
393 viewerDidAuthor
394 headRepository {
395 viewerPermission
396 }
397 }
398 }
399}
400
401# Who a review may be asked of, and who it has already been asked of, in one read.
402#
403# `assignableUsers` is the list GitHub's own reviewer picker is built from (everyone with access to
404# the repository) rather than `collaborators`, which the REST API refuses to anyone without push
405# access and which would therefore be empty for exactly the reader most likely to be looking.
406#
407# Teams are asked for only where one has already been requested, so a request to a team can be
408# taken back. The teams a repository could newly be sent to live on the owning organization and
409# need `read:org`, which a repository-scoped token need not carry, and a query GitHub refuses
410# fails whole, taking the people down with the teams.
411query ReviewerCandidates($owner: String!, $name: String!, $number: Int!) {
412 repository(owner: $owner, name: $name) {
413 assignableUsers(first: 100) {
414 pageInfo {
415 hasNextPage
416 }
417 nodes {
418 login
419 name
420 avatarUrl
421 }
422 }
423 pullRequest(number: $number) {
424 author {
425 login
426 }
427 reviewRequests(first: 100) {
428 nodes {
429 requestedReviewer {
430 ... on User {
431 login
432 name
433 avatarUrl
434 }
435 # Aliased apart from a person's: their nullability differs.
436 ... on Team {
437 slug
438 combinedSlug
439 teamName: name
440 teamAvatarUrl: avatarUrl
441 }
442 ... on Bot {
443 login
444 avatarUrl
445 }
446 }
447 }
448 }
449 }
450 }
451}
452
453query LabelCandidates($owner: String!, $name: String!, $number: Int!) {
454 repository(owner: $owner, name: $name) {
455 labels(first: 100, orderBy: { field: NAME, direction: ASC }) {
456 pageInfo {
457 hasNextPage
458 }
459 nodes {
460 name
461 color
462 description
463 }
464 }
465 pullRequest(number: $number) {
466 labels(first: 100) {
467 nodes {
468 name
469 }
470 }
471 }
472 }
473}
474
475query RepositoryLabels($owner: String!, $name: String!, $query: String) {
476 repository(owner: $owner, name: $name) {
477 labels(first: 100, query: $query, orderBy: { field: NAME, direction: ASC }) {
478 pageInfo {
479 hasNextPage
480 }
481 nodes {
482 name
483 color
484 }
485 }
486 }
487}
488
489# Mentionable rather than assignable users: a pull request from a fork is opened by someone with
490# no access to the repository, and a listing is still narrowed by them.
491query RepositoryAuthors($owner: String!, $name: String!, $query: String) {
492 repository(owner: $owner, name: $name) {
493 mentionableUsers(first: 50, query: $query) {
494 pageInfo {
495 hasNextPage
496 }
497 nodes {
498 login
499 name
500 avatarUrl
501 }
502 }
503 }
504}
505
506# Which files of a pull request the signed-in account has cleared. GraphQL only, since the REST
507# files endpoint the patch is read from carries no viewed state, so this is a second read rather
508# than a wider version of the first.
509query PullRequestFilesViewed($owner: String!, $name: String!, $number: Int!, $after: String) {
510 repository(owner: $owner, name: $name) {
511 pullRequest(number: $number) {
512 files(first: 100, after: $after) {
513 pageInfo {
514 hasNextPage
515 endCursor
516 }
517 nodes {
518 path
519 viewerViewedState
520 }
521 }
522 }
523 }
524}
525
526query PullRequestFileStats($owner: String!, $name: String!, $number: Int!, $after: String) {
527 repository(owner: $owner, name: $name) {
528 pullRequest(number: $number) {
529 files(first: 100, after: $after) {
530 pageInfo {
531 hasNextPage
532 endCursor
533 }
534 nodes {
535 path
536 additions
537 deletions
538 }
539 }
540 }
541 }
542}
543
544# What a merge that rewrites its message reads first: GitHub's own message for the method, and
545# whether a merge queue will choose its own instead.
546query PullRequestMergeMessage(
547 $owner: String!
548 $name: String!
549 $number: Int!
550 $method: PullRequestMergeMethod!
551) {
552 repository(owner: $owner, name: $name) {
553 pullRequest(number: $number) {
554 isMergeQueueEnabled
555 headRefOid
556 viewerMergeBodyText(mergeType: $method)
557 }
558 }
559}
560
561# What `gh pr merge` and `gh pr update-branch` read before they act.
562query PullRequestActionState($owner: String!, $name: String!, $number: Int!, $headRef: String!) {
563 repository(owner: $owner, name: $name) {
564 pullRequest(number: $number) {
565 id
566 headRefOid
567 isMergeQueueEnabled
568 mergeStateStatus
569 baseRef {
570 compare(headRef: $headRef) {
571 behindBy
572 }
573 }
574 }
575 }
576}
577
578# What deleting a closed or merged pull request's source branch reads first: the branch, the
579# commit it should still point at, and the repository it lives in.
580query PullRequestBranchToDelete($owner: String!, $name: String!, $number: Int!) {
581 repository(owner: $owner, name: $name) {
582 pullRequest(number: $number) {
583 state
584 headRefName
585 baseRefName
586 headRefOid
587 headRepository {
588 id
589 }
590 }
591 }
592}
593
594# The source branch as its own repository holds it now, beside that repository's default branch,
595# so a branch that moved on or is the default is never deleted.
596query PullRequestSourceBranch($repositoryId: ID!, $ref: String!) {
597 node(id: $repositoryId) {
598 ... on Repository {
599 defaultBranchRef {
600 name
601 }
602 ref(qualifiedName: $ref) {
603 target {
604 oid
605 }
606 }
607 }
608 }
609}