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