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 oid
246 messageHeadline
247 committedDate
248 authors(first: 10) {
249 nodes {
250 name
251 email
252 user {
253 login
254 }
255 }
256 }
257 }
258 }
259 }
260 comments(first: 100, after: $commentsAfter) @include(if: $withComments) {
261 pageInfo {
262 hasNextPage
263 endCursor
264 }
265 nodes {
266 id
267 body
268 createdAt
269 lastEditedAt
270 url
271 author {
272 login
273 avatarUrl
274 ... on User {
275 name
276 }
277 }
278 }
279 }
280 reviews(first: 100, after: $reviewsAfter) @include(if: $withReviews) {
281 pageInfo {
282 hasNextPage
283 endCursor
284 }
285 nodes {
286 id
287 body
288 state
289 submittedAt
290 lastEditedAt
291 url
292 author {
293 login
294 avatarUrl
295 ... on User {
296 name
297 }
298 }
299 }
300 }
301 }
302 }
303}
304
305# Open pull requests whose head branch has one name, from whichever repository it lives in.
306query PullRequestHeads($owner: String!, $name: String!, $head: String!, $after: String) {
307 repository(owner: $owner, name: $name) {
308 pullRequests(first: 100, after: $after, states: [OPEN], headRefName: $head) {
309 pageInfo {
310 hasNextPage
311 endCursor
312 }
313 nodes {
314 number
315 headRefOid
316 isCrossRepository
317 headRepositoryOwner {
318 login
319 }
320 }
321 }
322 }
323}
324
325# The pull request's own node id, which is what a mutation against the pull request itself is
326# addressed by. Read only when one is being written: the conversation carries an id for every
327# remark in it, and the pull request is the one subject nothing in it names.
328query PullRequestNodeId($owner: String!, $name: String!, $number: Int!) {
329 repository(owner: $owner, name: $name) {
330 pullRequest(number: $number) {
331 id
332 }
333 }
334}
335
336# Where a client-given subject actually hangs: the pull request itself, or the pull request an
337# issue comment, a review comment, or a review belongs to. Read before a mutation reaches it, so a
338# subject named for one pull request cannot write on another's behalf.
339query PullRequestSubject($owner: String!, $name: String!, $number: Int!, $subjectId: ID!) {
340 repository(owner: $owner, name: $name) {
341 pullRequest(number: $number) {
342 id
343 }
344 }
345 node(id: $subjectId) {
346 id
347 ... on IssueComment {
348 pullRequest {
349 id
350 }
351 }
352 # Aliased apart: an issue comment's pull request is nullable, the other two are not.
353 ... on PullRequestReviewComment {
354 reviewCommentPullRequest: pullRequest {
355 id
356 }
357 }
358 ... on PullRequestReview {
359 reviewPullRequest: pullRequest {
360 id
361 }
362 }
363 }
364}
365
366# Core detail and write checks share one read of permissions and merge settings.
367query ViewerPermissions($owner: String!, $name: String!, $number: Int!) {
368 repository(owner: $owner, name: $name) {
369 mergeCommitAllowed
370 squashMergeAllowed
371 rebaseMergeAllowed
372 autoMergeAllowed
373 viewerPermission
374 pullRequest(number: $number) {
375 viewerCanUpdate
376 viewerDidAuthor
377 headRepository {
378 viewerPermission
379 }
380 }
381 }
382}
383
384# Who a review may be asked of, and who it has already been asked of, in one read.
385#
386# `assignableUsers` is the list GitHub's own reviewer picker is built from (everyone with access to
387# the repository) rather than `collaborators`, which the REST API refuses to anyone without push
388# access and which would therefore be empty for exactly the reader most likely to be looking.
389#
390# Teams are asked for only where one has already been requested, so a request to a team can be
391# taken back. The teams a repository could newly be sent to live on the owning organization and
392# need `read:org`, which a repository-scoped token need not carry, and a query GitHub refuses
393# fails whole, taking the people down with the teams.
394query ReviewerCandidates($owner: String!, $name: String!, $number: Int!) {
395 repository(owner: $owner, name: $name) {
396 assignableUsers(first: 100) {
397 pageInfo {
398 hasNextPage
399 }
400 nodes {
401 login
402 name
403 avatarUrl
404 }
405 }
406 pullRequest(number: $number) {
407 author {
408 login
409 }
410 reviewRequests(first: 100) {
411 nodes {
412 requestedReviewer {
413 ... on User {
414 login
415 name
416 avatarUrl
417 }
418 # Aliased apart from a person's: their nullability differs.
419 ... on Team {
420 slug
421 combinedSlug
422 teamName: name
423 teamAvatarUrl: avatarUrl
424 }
425 ... on Bot {
426 login
427 avatarUrl
428 }
429 }
430 }
431 }
432 }
433 }
434}
435
436query LabelCandidates($owner: String!, $name: String!, $number: Int!) {
437 repository(owner: $owner, name: $name) {
438 labels(first: 100, orderBy: { field: NAME, direction: ASC }) {
439 pageInfo {
440 hasNextPage
441 }
442 nodes {
443 name
444 color
445 description
446 }
447 }
448 pullRequest(number: $number) {
449 labels(first: 100) {
450 nodes {
451 name
452 }
453 }
454 }
455 }
456}
457
458# Which files of a pull request the signed-in account has cleared. GraphQL only, since the REST
459# files endpoint the patch is read from carries no viewed state, so this is a second read rather
460# than a wider version of the first.
461query PullRequestFilesViewed($owner: String!, $name: String!, $number: Int!, $after: String) {
462 repository(owner: $owner, name: $name) {
463 pullRequest(number: $number) {
464 files(first: 100, after: $after) {
465 pageInfo {
466 hasNextPage
467 endCursor
468 }
469 nodes {
470 path
471 viewerViewedState
472 }
473 }
474 }
475 }
476}
477
478# What a merge that rewrites its message reads first: GitHub's own message for the method, and
479# whether a merge queue will choose its own instead.
480query PullRequestMergeMessage(
481 $owner: String!
482 $name: String!
483 $number: Int!
484 $method: PullRequestMergeMethod!
485) {
486 repository(owner: $owner, name: $name) {
487 pullRequest(number: $number) {
488 isMergeQueueEnabled
489 headRefOid
490 viewerMergeBodyText(mergeType: $method)
491 }
492 }
493}
494
495# What `gh pr merge` and `gh pr update-branch` read before they act.
496query PullRequestActionState($owner: String!, $name: String!, $number: Int!, $headRef: String!) {
497 repository(owner: $owner, name: $name) {
498 pullRequest(number: $number) {
499 id
500 headRefOid
501 isMergeQueueEnabled
502 mergeStateStatus
503 baseRef {
504 compare(headRef: $headRef) {
505 behindBy
506 }
507 }
508 }
509 }
510}
511
512# What deleting a closed or merged pull request's source branch reads first: the branch, the
513# commit it should still point at, and the repository it lives in.
514query PullRequestBranchToDelete($owner: String!, $name: String!, $number: Int!) {
515 repository(owner: $owner, name: $name) {
516 pullRequest(number: $number) {
517 state
518 headRefName
519 baseRefName
520 headRefOid
521 headRepository {
522 id
523 }
524 }
525 }
526}
527
528# The source branch as its own repository holds it now, beside that repository's default branch,
529# so a branch that moved on or is the default is never deleted.
530query PullRequestSourceBranch($repositoryId: ID!, $ref: String!) {
531 node(id: $repositoryId) {
532 ... on Repository {
533 defaultBranchRef {
534 name
535 }
536 ref(qualifiedName: $ref) {
537 target {
538 oid
539 }
540 }
541 }
542 }
543}