Open History to see the last commit
1# Reads of one pull request, or of the repository it belongs to.
2
3# Resolves a listing's authors to avatars, which no listing field carries.
4query ActorAvatars($ids: [ID!]!) {
5 nodes(ids: $ids) {
6 ... on User {
7 login
8 avatarUrl
9 }
10 ... on Bot {
11 login
12 avatarUrl
13 }
14 }
15}
16
17# A check context of the head commit. `isRequired` is asked for on github.com only (`$required`):
18# an older Enterprise server may not know it, and an unknown field fails the whole read.
19fragment CheckContext on StatusCheckRollupContext {
20 ... on StatusContext {
21 context
22 state
23 targetUrl
24 createdAt
25 description
26 isRequired(pullRequestNumber: $number) @include(if: $required)
27 }
28 ... on CheckRun {
29 name
30 status
31 conclusion
32 startedAt
33 completedAt
34 detailsUrl
35 isRequired(pullRequestNumber: $number) @include(if: $required)
36 checkSuite {
37 workflowRun {
38 workflow {
39 name
40 }
41 }
42 }
43 }
44}
45
46# The detail of a pull request with the viewer's standing on it. Pull refs let the comparison
47# (`$headRef` is `refs/pull/<number>/head`) share this read without first resolving a fork branch.
48query PullRequestCore(
49 $owner: String!
50 $name: String!
51 $number: Int!
52 $headRef: String!
53 $required: Boolean!
54) {
55 repository(owner: $owner, name: $name) {
56 mergeCommitAllowed
57 squashMergeAllowed
58 rebaseMergeAllowed
59 viewerPermission
60 pullRequest(number: $number) {
61 number
62 title
63 url
64 body
65 state
66 isDraft
67 mergeable
68 reviewDecision
69 additions
70 deletions
71 changedFiles
72 createdAt
73 updatedAt
74 mergedAt
75 closedAt
76 headRefName
77 baseRefName
78 headRefOid
79 isCrossRepository
80 headRepositoryOwner {
81 login
82 }
83 # The source branch's own repository and ref, which is what deleting the branch needs: write
84 # there, and a branch still to delete.
85 headRepository {
86 nameWithOwner
87 viewerPermission
88 }
89 headRef {
90 id
91 }
92 author {
93 login
94 avatarUrl
95 ... on User {
96 id
97 name
98 }
99 }
100 autoMergeRequest {
101 mergeMethod
102 }
103 viewerCanUpdate
104 viewerDidAuthor
105 viewerCanUpdateBranch
106 baseRef {
107 compare(headRef: $headRef) {
108 behindBy
109 }
110 }
111 reviewRequests(first: 100) {
112 nodes {
113 requestedReviewer {
114 ... on User {
115 login
116 name
117 }
118 ... on Bot {
119 login
120 }
121 # A team's name and avatar are nullable differently from a person's, so they travel
122 # under their own aliases. `combinedSlug` is the `org/slug` a reviewer row shows.
123 ... on Team {
124 slug
125 combinedSlug
126 teamName: name
127 teamAvatarUrl: avatarUrl
128 }
129 }
130 }
131 }
132 labels(first: 100) {
133 nodes {
134 name
135 color
136 }
137 }
138 commits(last: 1) {
139 nodes {
140 commit {
141 statusCheckRollup {
142 contexts(first: 100) {
143 nodes {
144 ...CheckContext
145 }
146 pageInfo {
147 hasNextPage
148 }
149 }
150 }
151 }
152 }
153 }
154 }
155 }
156}
157
158# Every check context of the head commit, a page at a time, for a rollup past one page.
159query PullRequestCheckContexts(
160 $owner: String!
161 $name: String!
162 $number: Int!
163 $required: Boolean!
164 $after: String
165) {
166 repository(owner: $owner, name: $name) {
167 pullRequest(number: $number) {
168 headRefOid
169 commits(last: 1) {
170 nodes {
171 commit {
172 statusCheckRollup {
173 contexts(first: 100, after: $after) {
174 nodes {
175 ...CheckContext
176 }
177 pageInfo {
178 hasNextPage
179 endCursor
180 }
181 }
182 }
183 }
184 }
185 }
186 }
187 }
188}
189
190query PullRequestPreview($owner: String!, $name: String!, $number: Int!) {
191 repository(owner: $owner, name: $name) {
192 pullRequest(number: $number) {
193 number
194 title
195 url
196 state
197 isDraft
198 createdAt
199 author {
200 login
201 avatarUrl
202 ... on User {
203 name
204 }
205 }
206 }
207 }
208}
209
210# The conversation a pull request carries outside its review threads: who opened it, its issue
211# comments, its reviews and its newest commits. The two remark connections page independently, so
212# each is switched on only while it has more to give; the first read (`$head`) asks for everything.
213query PullRequestActivity(
214 $owner: String!
215 $name: String!
216 $number: Int!
217 $head: Boolean!
218 $withComments: Boolean!
219 $commentsAfter: String
220 $withReviews: Boolean!
221 $reviewsAfter: String
222) {
223 repository(owner: $owner, name: $name) {
224 pullRequest(number: $number) {
225 author @include(if: $head) {
226 login
227 avatarUrl
228 ... on User {
229 name
230 }
231 }
232 commits(last: 100) @include(if: $head) {
233 nodes {
234 commit {
235 oid
236 messageHeadline
237 committedDate
238 authors(first: 10) {
239 nodes {
240 name
241 email
242 user {
243 login
244 }
245 }
246 }
247 }
248 }
249 }
250 comments(first: 100, after: $commentsAfter) @include(if: $withComments) {
251 pageInfo {
252 hasNextPage
253 endCursor
254 }
255 nodes {
256 id
257 body
258 createdAt
259 lastEditedAt
260 url
261 author {
262 login
263 avatarUrl
264 ... on User {
265 name
266 }
267 }
268 }
269 }
270 reviews(first: 100, after: $reviewsAfter) @include(if: $withReviews) {
271 pageInfo {
272 hasNextPage
273 endCursor
274 }
275 nodes {
276 id
277 body
278 state
279 submittedAt
280 lastEditedAt
281 url
282 author {
283 login
284 avatarUrl
285 ... on User {
286 name
287 }
288 }
289 }
290 }
291 }
292 }
293}
294
295# Open pull requests whose head branch has one name, from whichever repository it lives in.
296query PullRequestHeads($owner: String!, $name: String!, $head: String!, $after: String) {
297 repository(owner: $owner, name: $name) {
298 pullRequests(first: 100, after: $after, states: [OPEN], headRefName: $head) {
299 pageInfo {
300 hasNextPage
301 endCursor
302 }
303 nodes {
304 number
305 headRefOid
306 isCrossRepository
307 headRepositoryOwner {
308 login
309 }
310 }
311 }
312 }
313}
314
315# The pull request's own node id, which is what a mutation against the pull request itself is
316# addressed by. Read only when one is being written: the conversation carries an id for every
317# remark in it, and the pull request is the one subject nothing in it names.
318query PullRequestNodeId($owner: String!, $name: String!, $number: Int!) {
319 repository(owner: $owner, name: $name) {
320 pullRequest(number: $number) {
321 id
322 }
323 }
324}
325
326# Where a client-given subject actually hangs: the pull request itself, or the pull request an
327# issue comment, a review comment, or a review belongs to. Read before a mutation reaches it, so a
328# subject named for one pull request cannot write on another's behalf.
329query PullRequestSubject($owner: String!, $name: String!, $number: Int!, $subjectId: ID!) {
330 repository(owner: $owner, name: $name) {
331 pullRequest(number: $number) {
332 id
333 }
334 }
335 node(id: $subjectId) {
336 id
337 ... on IssueComment {
338 pullRequest {
339 id
340 }
341 }
342 # Aliased apart: an issue comment's pull request is nullable, the other two are not.
343 ... on PullRequestReviewComment {
344 reviewCommentPullRequest: pullRequest {
345 id
346 }
347 }
348 ... on PullRequestReview {
349 reviewPullRequest: pullRequest {
350 id
351 }
352 }
353 }
354}
355
356# Core detail and write checks share one read of permissions and merge settings.
357query ViewerPermissions($owner: String!, $name: String!, $number: Int!) {
358 repository(owner: $owner, name: $name) {
359 mergeCommitAllowed
360 squashMergeAllowed
361 rebaseMergeAllowed
362 viewerPermission
363 pullRequest(number: $number) {
364 viewerCanUpdate
365 viewerDidAuthor
366 headRepository {
367 viewerPermission
368 }
369 }
370 }
371}
372
373# Who a review may be asked of, and who it has already been asked of, in one read.
374#
375# `assignableUsers` is the list GitHub's own reviewer picker is built from (everyone with access to
376# the repository) rather than `collaborators`, which the REST API refuses to anyone without push
377# access and which would therefore be empty for exactly the reader most likely to be looking.
378#
379# Teams are asked for only where one has already been requested, so a request to a team can be
380# taken back. The teams a repository could newly be sent to live on the owning organization and
381# need `read:org`, which a repository-scoped token need not carry, and a query GitHub refuses
382# fails whole, taking the people down with the teams.
383query ReviewerCandidates($owner: String!, $name: String!, $number: Int!) {
384 repository(owner: $owner, name: $name) {
385 assignableUsers(first: 100) {
386 pageInfo {
387 hasNextPage
388 }
389 nodes {
390 login
391 name
392 avatarUrl
393 }
394 }
395 pullRequest(number: $number) {
396 author {
397 login
398 }
399 reviewRequests(first: 100) {
400 nodes {
401 requestedReviewer {
402 ... on User {
403 login
404 name
405 avatarUrl
406 }
407 # Aliased apart from a person's: their nullability differs.
408 ... on Team {
409 slug
410 combinedSlug
411 teamName: name
412 teamAvatarUrl: avatarUrl
413 }
414 ... on Bot {
415 login
416 avatarUrl
417 }
418 }
419 }
420 }
421 }
422 }
423}
424
425query LabelCandidates($owner: String!, $name: String!, $number: Int!) {
426 repository(owner: $owner, name: $name) {
427 labels(first: 100, orderBy: { field: NAME, direction: ASC }) {
428 pageInfo {
429 hasNextPage
430 }
431 nodes {
432 name
433 color
434 description
435 }
436 }
437 pullRequest(number: $number) {
438 labels(first: 100) {
439 nodes {
440 name
441 }
442 }
443 }
444 }
445}
446
447# Which files of a pull request the signed-in account has cleared. GraphQL only, since the REST
448# files endpoint the patch is read from carries no viewed state, so this is a second read rather
449# than a wider version of the first.
450query PullRequestFilesViewed($owner: String!, $name: String!, $number: Int!, $after: String) {
451 repository(owner: $owner, name: $name) {
452 pullRequest(number: $number) {
453 files(first: 100, after: $after) {
454 pageInfo {
455 hasNextPage
456 endCursor
457 }
458 nodes {
459 path
460 viewerViewedState
461 }
462 }
463 }
464 }
465}
466
467# What a merge that rewrites its message reads first: GitHub's own message for the method, and
468# whether a merge queue will choose its own instead.
469query PullRequestMergeMessage(
470 $owner: String!
471 $name: String!
472 $number: Int!
473 $method: PullRequestMergeMethod!
474) {
475 repository(owner: $owner, name: $name) {
476 pullRequest(number: $number) {
477 isMergeQueueEnabled
478 headRefOid
479 viewerMergeBodyText(mergeType: $method)
480 }
481 }
482}
483
484# What `gh pr merge` and `gh pr update-branch` read before they act.
485query PullRequestActionState($owner: String!, $name: String!, $number: Int!, $headRef: String!) {
486 repository(owner: $owner, name: $name) {
487 pullRequest(number: $number) {
488 id
489 headRefOid
490 isMergeQueueEnabled
491 mergeStateStatus
492 baseRef {
493 compare(headRef: $headRef) {
494 behindBy
495 }
496 }
497 }
498 }
499}
500
501# What deleting a closed or merged pull request's source branch reads first: the branch, the
502# commit it should still point at, and the repository it lives in.
503query PullRequestBranchToDelete($owner: String!, $name: String!, $number: Int!) {
504 repository(owner: $owner, name: $name) {
505 pullRequest(number: $number) {
506 state
507 headRefName
508 baseRefName
509 headRefOid
510 headRepository {
511 id
512 }
513 }
514 }
515}
516
517# The source branch as its own repository holds it now, beside that repository's default branch,
518# so a branch that moved on or is the default is never deleted.
519query PullRequestSourceBranch($repositoryId: ID!, $ref: String!) {
520 node(id: $repositoryId) {
521 ... on Repository {
522 defaultBranchRef {
523 name
524 }
525 ref(qualifiedName: $ref) {
526 target {
527 oid
528 }
529 }
530 }
531 }
532}