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 changedFilesIfAvailable
349 }
350 }
351}
352
353# Open pull requests whose head branch has one name, from whichever repository it lives in.
354query PullRequestHeads($owner: String!, $name: String!, $head: String!, $after: String) {
355 repository(owner: $owner, name: $name) {
356 pullRequests(first: 100, after: $after, states: [OPEN], headRefName: $head) {
357 pageInfo {
358 hasNextPage
359 endCursor
360 }
361 nodes {
362 number
363 headRefOid
364 isCrossRepository
365 headRepositoryOwner {
366 login
367 }
368 }
369 }
370 }
371}
372
373# The pull request's own node id, which is what a mutation against the pull request itself is
374# addressed by. Read only when one is being written: the conversation carries an id for every
375# remark in it, and the pull request is the one subject nothing in it names.
376query PullRequestNodeId($owner: String!, $name: String!, $number: Int!) {
377 repository(owner: $owner, name: $name) {
378 pullRequest(number: $number) {
379 id
380 }
381 }
382}
383
384# Where a client-given subject actually hangs: the pull request itself, or the pull request an
385# issue comment, a review comment, a review, or a review thread belongs to. Read before a mutation
386# reaches it, so a subject named for one pull request cannot write on another's behalf.
387query PullRequestSubject($owner: String!, $name: String!, $number: Int!, $subjectId: ID!) {
388 repository(owner: $owner, name: $name) {
389 pullRequest(number: $number) {
390 id
391 }
392 }
393 node(id: $subjectId) {
394 id
395 ... on IssueComment {
396 pullRequest {
397 id
398 }
399 }
400 # Aliased apart: an issue comment's pull request is nullable, the other three are not.
401 ... on PullRequestReviewComment {
402 reviewCommentPullRequest: pullRequest {
403 id
404 }
405 }
406 ... on PullRequestReview {
407 reviewPullRequest: pullRequest {
408 id
409 }
410 }
411 ... on PullRequestReviewThread {
412 threadPullRequest: pullRequest {
413 id
414 }
415 }
416 }
417}
418
419# Core detail and write checks share one read of permissions and merge settings.
420query ViewerPermissions($owner: String!, $name: String!, $number: Int!) {
421 repository(owner: $owner, name: $name) {
422 mergeCommitAllowed
423 squashMergeAllowed
424 rebaseMergeAllowed
425 autoMergeAllowed
426 viewerPermission
427 pullRequest(number: $number) {
428 viewerCanUpdate
429 viewerDidAuthor
430 headRepository {
431 viewerPermission
432 }
433 }
434 }
435}
436
437# Who a review may be asked of, and who it has already been asked of, in one read.
438#
439# `assignableUsers` is the list GitHub's own reviewer picker is built from (everyone with access to
440# the repository) rather than `collaborators`, which the REST API refuses to anyone without push
441# access and which would therefore be empty for exactly the reader most likely to be looking.
442#
443# Teams are asked for only where one has already been requested, so a request to a team can be
444# taken back. The teams a repository could newly be sent to live on the owning organization and
445# need `read:org`, which a repository-scoped token need not carry, and a query GitHub refuses
446# fails whole, taking the people down with the teams.
447query ReviewerCandidates($owner: String!, $name: String!, $number: Int!, $query: String) {
448 repository(owner: $owner, name: $name) {
449 assignableUsers(first: 100, query: $query) {
450 pageInfo {
451 hasNextPage
452 }
453 nodes {
454 login
455 name
456 avatarUrl
457 }
458 }
459 pullRequest(number: $number) {
460 author {
461 login
462 }
463 reviewRequests(first: 100) {
464 nodes {
465 requestedReviewer {
466 ... on User {
467 login
468 name
469 avatarUrl
470 }
471 # Aliased apart from a person's: their nullability differs.
472 ... on Team {
473 slug
474 combinedSlug
475 teamName: name
476 teamAvatarUrl: avatarUrl
477 }
478 ... on Bot {
479 login
480 avatarUrl
481 }
482 }
483 }
484 }
485 }
486 }
487}
488
489query LabelCandidates($owner: String!, $name: String!, $number: Int!) {
490 repository(owner: $owner, name: $name) {
491 labels(first: 100, orderBy: { field: NAME, direction: ASC }) {
492 pageInfo {
493 hasNextPage
494 }
495 nodes {
496 name
497 color
498 description
499 }
500 }
501 pullRequest(number: $number) {
502 labels(first: 100) {
503 nodes {
504 name
505 }
506 }
507 }
508 }
509}
510
511query RepositoryLabels($owner: String!, $name: String!, $query: String) {
512 repository(owner: $owner, name: $name) {
513 labels(first: 100, query: $query, orderBy: { field: NAME, direction: ASC }) {
514 pageInfo {
515 hasNextPage
516 }
517 nodes {
518 name
519 color
520 }
521 }
522 }
523}
524
525fragment ReferenceCandidate on IssueOrPullRequest {
526 __typename
527 ... on Issue {
528 number
529 title
530 issueState: state
531 }
532 ... on PullRequest {
533 number
534 title
535 pullRequestState: state
536 }
537}
538
539# `search` cannot match a number, so a numeric query also looks the number up directly.
540query RepositoryReferences(
541 $owner: String!
542 $name: String!
543 $q: String!
544 $number: Int!
545 $exact: Boolean!
546) {
547 search(query: $q, type: ISSUE, first: 20) {
548 pageInfo {
549 hasNextPage
550 }
551 nodes {
552 ...ReferenceCandidate
553 }
554 }
555 repository(owner: $owner, name: $name) @include(if: $exact) {
556 issueOrPullRequest(number: $number) {
557 ...ReferenceCandidate
558 }
559 }
560}
561
562# Mentionable rather than assignable users: a pull request from a fork is opened by someone with
563# no access to the repository, and a listing is still narrowed by them.
564query RepositoryAuthors($owner: String!, $name: String!, $query: String) {
565 repository(owner: $owner, name: $name) {
566 mentionableUsers(first: 50, query: $query) {
567 pageInfo {
568 hasNextPage
569 }
570 nodes {
571 login
572 name
573 avatarUrl
574 }
575 }
576 }
577}
578
579# Which files of a pull request the signed-in account has cleared. GraphQL only, since the REST
580# files endpoint the patch is read from carries no viewed state, so this is a second read rather
581# than a wider version of the first.
582query PullRequestFilesViewed($owner: String!, $name: String!, $number: Int!, $after: String) {
583 repository(owner: $owner, name: $name) {
584 pullRequest(number: $number) {
585 files(first: 100, after: $after) {
586 pageInfo {
587 hasNextPage
588 endCursor
589 }
590 nodes {
591 path
592 viewerViewedState
593 }
594 }
595 }
596 }
597}
598
599query PullRequestFileStats($owner: String!, $name: String!, $number: Int!, $after: String) {
600 repository(owner: $owner, name: $name) {
601 pullRequest(number: $number) {
602 files(first: 100, after: $after) {
603 pageInfo {
604 hasNextPage
605 endCursor
606 }
607 nodes {
608 path
609 additions
610 deletions
611 }
612 }
613 }
614 }
615}
616
617# What a merge that rewrites its message reads first: GitHub's own message for the method, and
618# whether a merge queue will choose its own instead.
619query PullRequestMergeMessage(
620 $owner: String!
621 $name: String!
622 $number: Int!
623 $method: PullRequestMergeMethod!
624) {
625 repository(owner: $owner, name: $name) {
626 pullRequest(number: $number) {
627 isMergeQueueEnabled
628 headRefOid
629 viewerMergeBodyText(mergeType: $method)
630 }
631 }
632}
633
634# What `gh pr merge` and `gh pr update-branch` read before they act.
635query PullRequestActionState($owner: String!, $name: String!, $number: Int!, $headRef: String!) {
636 repository(owner: $owner, name: $name) {
637 pullRequest(number: $number) {
638 id
639 headRefOid
640 isMergeQueueEnabled
641 mergeStateStatus
642 baseRef {
643 compare(headRef: $headRef) {
644 behindBy
645 }
646 }
647 }
648 }
649}
650
651# What deleting a closed or merged pull request's source branch reads first: the branch, the
652# commit it should still point at, and the repository it lives in.
653query PullRequestBranchToDelete($owner: String!, $name: String!, $number: Int!) {
654 repository(owner: $owner, name: $name) {
655 pullRequest(number: $number) {
656 state
657 headRefName
658 baseRefName
659 headRefOid
660 headRepository {
661 id
662 }
663 }
664 }
665}
666
667# The source branch as its own repository holds it now, beside that repository's default branch,
668# so a branch that moved on or is the default is never deleted.
669query PullRequestSourceBranch($repositoryId: ID!, $ref: String!) {
670 node(id: $repositoryId) {
671 ... on Repository {
672 defaultBranchRef {
673 name
674 }
675 ref(qualifiedName: $ref) {
676 target {
677 oid
678 }
679 }
680 }
681 }
682}