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