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