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