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