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