Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathpulls.go
More file actions
Latest commit
638 lines (554 loc) · 24 KB
/
Copy pathpulls.go
File metadata and controls
638 lines (554 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
// Copyright 2013 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"bytes"
"context"
"errors"
"fmt"
)
// PullRequestsService handles communication with the pull request related
// methods of the GitHub API.
//
// GitHub API docs: https://docs.github.com/rest/pulls?apiVersion=2022-11-28
typePullRequestsServiceservice
// PullRequestAutoMerge represents the "auto_merge" response for a PullRequest.
typePullRequestAutoMergestruct {
EnabledBy*User`json:"enabled_by,omitempty"`
MergeMethod*string`json:"merge_method,omitempty"`
CommitTitle*string`json:"commit_title,omitempty"`
CommitMessage*string`json:"commit_message,omitempty"`
}
// PullRequest represents a GitHub pull request on a repository.
typePullRequeststruct {
ID*int64`json:"id,omitempty"`
Number*int`json:"number,omitempty"`
State*string`json:"state,omitempty"`
Locked*bool`json:"locked,omitempty"`
Title*string`json:"title,omitempty"`
Body*string`json:"body,omitempty"`
CreatedAt*Timestamp`json:"created_at,omitempty"`
UpdatedAt*Timestamp`json:"updated_at,omitempty"`
ClosedAt*Timestamp`json:"closed_at,omitempty"`
MergedAt*Timestamp`json:"merged_at,omitempty"`
Labels []*Label`json:"labels,omitempty"`
User*User`json:"user,omitempty"`
Draft*bool`json:"draft,omitempty"`
URL*string`json:"url,omitempty"`
HTMLURL*string`json:"html_url,omitempty"`
IssueURL*string`json:"issue_url,omitempty"`
StatusesURL*string`json:"statuses_url,omitempty"`
DiffURL*string`json:"diff_url,omitempty"`
PatchURL*string`json:"patch_url,omitempty"`
CommitsURL*string`json:"commits_url,omitempty"`
CommentsURL*string`json:"comments_url,omitempty"`
ReviewCommentsURL*string`json:"review_comments_url,omitempty"`
ReviewCommentURL*string`json:"review_comment_url,omitempty"`
Assignee*User`json:"assignee,omitempty"`
Assignees []*User`json:"assignees,omitempty"`
Milestone*Milestone`json:"milestone,omitempty"`
// AuthorAssociation is the pull request author's relationship to the repository.
// Possible values are "COLLABORATOR", "CONTRIBUTOR", "FIRST_TIMER", "FIRST_TIME_CONTRIBUTOR", "MEMBER", "OWNER", or "NONE".
//
// Deprecated: GitHub will remove this field from Events API payloads on October 7, 2025.
// Use the Pull Requests REST API endpoint to retrieve this information.
// See: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
AuthorAssociation*string`json:"author_association,omitempty"`
NodeID*string`json:"node_id,omitempty"`
RequestedReviewers []*User`json:"requested_reviewers,omitempty"`
AutoMerge*PullRequestAutoMerge`json:"auto_merge,omitempty"`
// These fields are not populated by the List operation.
Merged*bool`json:"merged,omitempty"`
Mergeable*bool`json:"mergeable,omitempty"`
MergeableState*string`json:"mergeable_state,omitempty"`
Rebaseable*bool`json:"rebaseable,omitempty"`
MergedBy*User`json:"merged_by,omitempty"`
MergeCommitSHA*string`json:"merge_commit_sha,omitempty"`
Comments*int`json:"comments,omitempty"`
Commits*int`json:"commits,omitempty"`
Additions*int`json:"additions,omitempty"`
Deletions*int`json:"deletions,omitempty"`
ChangedFiles*int`json:"changed_files,omitempty"`
MaintainerCanModify*bool`json:"maintainer_can_modify,omitempty"`
ReviewComments*int`json:"review_comments,omitempty"`
// RequestedTeams is populated as part of the PullRequestEvent.
// See, https://docs.github.com/developers/webhooks-and-events/github-event-types#pullrequestevent for an example.
RequestedTeams []*Team`json:"requested_teams,omitempty"`
Links*PRLinks`json:"_links,omitempty"`
Head*PullRequestBranch`json:"head,omitempty"`
Base*PullRequestBranch`json:"base,omitempty"`
Stack*PullRequestStack`json:"stack,omitempty"`
// ActiveLockReason is populated only when LockReason is provided while locking the pull request.
// Possible values are: "off-topic", "too heated", "resolved", and "spam".
ActiveLockReason*string`json:"active_lock_reason,omitempty"`
}
func (pPullRequest) String() string {
returnStringify(p)
}
// PRLink represents a single link object from GitHub pull request _links.
typePRLinkstruct {
HRef*string`json:"href,omitempty"`
}
// PRLinks represents the "_links" object in a GitHub pull request.
typePRLinksstruct {
Self*PRLink`json:"self,omitempty"`
HTML*PRLink`json:"html,omitempty"`
Issue*PRLink`json:"issue,omitempty"`
Comments*PRLink`json:"comments,omitempty"`
ReviewComments*PRLink`json:"review_comments,omitempty"`
ReviewComment*PRLink`json:"review_comment,omitempty"`
Commits*PRLink`json:"commits,omitempty"`
Statuses*PRLink`json:"statuses,omitempty"`
}
// PullRequestBranch represents a base or head branch in a GitHub pull request.
typePullRequestBranchstruct {
Label*string`json:"label,omitempty"`
Ref*string`json:"ref,omitempty"`
SHA*string`json:"sha,omitempty"`
Repo*Repository`json:"repo,omitempty"`
User*User`json:"user,omitempty"`
}
// PullRequestStack represents the stack a pull request belongs to, in
// repositories that use stacked pull requests. Base reports the branch the
// entire stack ultimately targets, which can differ from the pull request's own
// Base branch (the branch below it in the stack).
typePullRequestStackstruct {
// Base is the base of the stack: the branch the entire stack ultimately targets.
Base*PullRequestStackBase`json:"base"`
// Size is the total number of pull requests in the stack.
Size*int`json:"size,omitempty"`
// Position is the one-based position of this pull request within the stack,
// where 1 is the bottom of the stack.
Position*int`json:"position,omitempty"`
// ID is the ID of the stack that this pull request belongs to.
ID*int64`json:"id,omitempty"`
// Number is the number of the stack that this pull request belongs to.
Number*int`json:"number,omitempty"`
}
// PullRequestStackBase represents the base of a stacked pull request's stack:
// the branch the entire stack ultimately targets.
typePullRequestStackBasestruct {
Refstring`json:"ref"`
SHAstring`json:"sha"`
}
// PullRequestListOptions specifies the optional parameters to the
// PullRequestsService.List method.
typePullRequestListOptionsstruct {
// State filters pull requests based on their state. Possible values are:
// open, closed, all. Default is "open".
Statestring`url:"state,omitempty"`
// Head filters pull requests by head user and branch name in the format of:
// "user:ref-name".
Headstring`url:"head,omitempty"`
// Base filters pull requests by base branch name.
Basestring`url:"base,omitempty"`
// Sort specifies how to sort pull requests. Possible values are: created,
// updated, popularity, long-running. Default is "created".
Sortstring`url:"sort,omitempty"`
// Direction in which to sort pull requests. Possible values are: asc, desc.
// If Sort is "created" or not specified, Default is "desc"; otherwise, Default
// is "asc"
Directionstring`url:"direction,omitempty"`
ListOptions
}
// List the pull requests for the specified repository.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests
//
//meta:operation GET /repos/{owner}/{repo}/pulls
func (s*PullRequestsService) List(ctx context.Context, owner, repostring, opts*PullRequestListOptions) ([]*PullRequest, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls", owner, repo)
u, err:=addOptions(u, opts)
iferr!=nil {
returnnil, nil, err
}
req, err:=s.client.NewRequest(ctx, "GET", u, nil)
iferr!=nil {
returnnil, nil, err
}
varpulls []*PullRequest
resp, err:=s.client.Do(req, &pulls)
iferr!=nil {
returnnil, resp, err
}
returnpulls, resp, nil
}
// ListPullRequestsWithCommit returns pull requests associated with a commit SHA
// or branch name.
//
// The results may include open and closed pull requests. If the commit SHA is
// not present in the repository's default branch, the result will only include
// open pull requests.
//
// GitHub API docs: https://docs.github.com/rest/commits/commits?apiVersion=2022-11-28#list-pull-requests-associated-with-a-commit
//
//meta:operation GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls
func (s*PullRequestsService) ListPullRequestsWithCommit(ctx context.Context, owner, repo, shastring, opts*ListOptions) ([]*PullRequest, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/commits/%v/pulls", owner, repo, sha)
u, err:=addOptions(u, opts)
iferr!=nil {
returnnil, nil, err
}
req, err:=s.client.NewRequest(ctx, "GET", u, nil)
iferr!=nil {
returnnil, nil, err
}
req.Header.Set("Accept", mediaTypeListPullsOrBranchesForCommitPreview)
varpulls []*PullRequest
resp, err:=s.client.Do(req, &pulls)
iferr!=nil {
returnnil, resp, err
}
returnpulls, resp, nil
}
// Get a single pull request.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
//
//meta:operation GET /repos/{owner}/{repo}/pulls/{pull_number}
func (s*PullRequestsService) Get(ctx context.Context, owner, repostring, numberint) (*PullRequest, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls/%v", owner, repo, number)
req, err:=s.client.NewRequest(ctx, "GET", u, nil)
iferr!=nil {
returnnil, nil, err
}
varpull*PullRequest
resp, err:=s.client.Do(req, &pull)
iferr!=nil {
returnnil, resp, err
}
returnpull, resp, nil
}
// GetRaw gets a single pull request in raw (diff or patch) format.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
//
//meta:operation GET /repos/{owner}/{repo}/pulls/{pull_number}
func (s*PullRequestsService) GetRaw(ctx context.Context, owner, repostring, numberint, optsRawOptions) (string, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls/%v", owner, repo, number)
req, err:=s.client.NewRequest(ctx, "GET", u, nil)
iferr!=nil {
return"", nil, err
}
switchopts.Type {
caseDiff:
req.Header.Set("Accept", mediaTypeV3Diff)
casePatch:
req.Header.Set("Accept", mediaTypeV3Patch)
default:
return"", nil, fmt.Errorf("unsupported raw type %v", opts.Type)
}
varbuf bytes.Buffer
resp, err:=s.client.Do(req, &buf)
iferr!=nil {
return"", resp, err
}
returnbuf.String(), resp, nil
}
// CreatePullRequest represents a request to create a pull request.
typeCreatePullRequeststruct {
Title*string`json:"title,omitempty"`
// The name of the branch where your changes are implemented. For
// cross-repository pull requests in the same network, namespace head with
// a user like this: username:branch.
Headstring`json:"head"`
HeadRepo*string`json:"head_repo,omitempty"`
// The name of the branch you want the changes pulled into. This should be
// an existing branch on the current repository. You cannot submit a pull
// request to one repository that requests a merge to a base of another
// repository.
Basestring`json:"base"`
Body*string`json:"body,omitempty"`
Issue*int`json:"issue,omitempty"`
MaintainerCanModify*bool`json:"maintainer_can_modify,omitempty"`
Draft*bool`json:"draft,omitempty"`
}
// Create a new pull request on the specified repository.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#create-a-pull-request
//
//meta:operation POST /repos/{owner}/{repo}/pulls
func (s*PullRequestsService) Create(ctx context.Context, owner, repostring, bodyCreatePullRequest) (*PullRequest, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls", owner, repo)
req, err:=s.client.NewRequest(ctx, "POST", u, body)
iferr!=nil {
returnnil, nil, err
}
varp*PullRequest
resp, err:=s.client.Do(req, &p)
iferr!=nil {
returnnil, resp, err
}
returnp, resp, nil
}
// PullRequestBranchUpdateOptions specifies the optional parameters to the
// PullRequestsService.UpdateBranch method.
typePullRequestBranchUpdateOptionsstruct {
// ExpectedHeadSHA specifies the most recent commit on the pull request's branch.
// Default value is the SHA of the pull request's current HEAD ref.
ExpectedHeadSHA*string`json:"expected_head_sha,omitempty"`
}
// PullRequestBranchUpdateResponse specifies the response of pull request branch update.
typePullRequestBranchUpdateResponsestruct {
Message*string`json:"message,omitempty"`
URL*string`json:"url,omitempty"`
}
// UpdateBranch updates the pull request branch with latest upstream changes.
//
// This method might return an AcceptedError and a status code of
// 202. This is because this is the status that GitHub returns to signify that
// it has now scheduled the update of the pull request branch in a background task.
// A follow up request, after a delay of a second or so, should result
// in a successful request.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request-branch
//
//meta:operation PUT /repos/{owner}/{repo}/pulls/{pull_number}/update-branch
func (s*PullRequestsService) UpdateBranch(ctx context.Context, owner, repostring, numberint, body*PullRequestBranchUpdateOptions) (*PullRequestBranchUpdateResponse, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls/%v/update-branch", owner, repo, number)
req, err:=s.client.NewRequest(ctx, "PUT", u, body)
iferr!=nil {
returnnil, nil, err
}
req.Header.Set("Accept", mediaTypeUpdatePullRequestBranchPreview)
varp*PullRequestBranchUpdateResponse
resp, err:=s.client.Do(req, &p)
iferr!=nil {
returnnil, resp, err
}
returnp, resp, nil
}
typepullRequestUpdatestruct {
Title*string`json:"title,omitempty"`
Body*string`json:"body,omitempty"`
State*string`json:"state,omitempty"`
Base*string`json:"base,omitempty"`
MaintainerCanModify*bool`json:"maintainer_can_modify,omitempty"`
}
// Edit a pull request.
// pull must not be nil.
//
// The following fields are editable: Title, Body, State, Base.Ref and MaintainerCanModify.
// Base.Ref updates the base branch of the pull request.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request
//
//meta:operation PATCH /repos/{owner}/{repo}/pulls/{pull_number}
func (s*PullRequestsService) Edit(ctx context.Context, owner, repostring, numberint, pull*PullRequest) (*PullRequest, *Response, error) {
ifpull==nil {
returnnil, nil, errors.New("pull must be provided")
}
u:=fmt.Sprintf("repos/%v/%v/pulls/%v", owner, repo, number)
update:=&pullRequestUpdate{
Title: pull.Title,
Body: pull.Body,
State: pull.State,
MaintainerCanModify: pull.MaintainerCanModify,
}
// avoid updating the base branch when closing the Pull Request
// - otherwise the GitHub API server returns a "Validation Failed" error:
// "Cannot change base branch of closed pull request".
ifpull.Base!=nil&&pull.GetState() !="closed" {
update.Base=pull.Base.Ref
}
req, err:=s.client.NewRequest(ctx, "PATCH", u, update)
iferr!=nil {
returnnil, nil, err
}
varp*PullRequest
resp, err:=s.client.Do(req, &p)
iferr!=nil {
returnnil, resp, err
}
returnp, resp, nil
}
// ListCommits lists the commits in a pull request.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#list-commits-on-a-pull-request
//
//meta:operation GET /repos/{owner}/{repo}/pulls/{pull_number}/commits
func (s*PullRequestsService) ListCommits(ctx context.Context, owner, repostring, numberint, opts*ListOptions) ([]*RepositoryCommit, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls/%v/commits", owner, repo, number)
u, err:=addOptions(u, opts)
iferr!=nil {
returnnil, nil, err
}
req, err:=s.client.NewRequest(ctx, "GET", u, nil)
iferr!=nil {
returnnil, nil, err
}
varcommits []*RepositoryCommit
resp, err:=s.client.Do(req, &commits)
iferr!=nil {
returnnil, resp, err
}
returncommits, resp, nil
}
// ListFiles lists the files in a pull request.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests-files
//
//meta:operation GET /repos/{owner}/{repo}/pulls/{pull_number}/files
func (s*PullRequestsService) ListFiles(ctx context.Context, owner, repostring, numberint, opts*ListOptions) ([]*CommitFile, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls/%v/files", owner, repo, number)
u, err:=addOptions(u, opts)
iferr!=nil {
returnnil, nil, err
}
req, err:=s.client.NewRequest(ctx, "GET", u, nil)
iferr!=nil {
returnnil, nil, err
}
varcommitFiles []*CommitFile
resp, err:=s.client.Do(req, &commitFiles)
iferr!=nil {
returnnil, resp, err
}
returncommitFiles, resp, nil
}
// IsMerged checks if a pull request has been merged.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#check-if-a-pull-request-has-been-merged
//
//meta:operation GET /repos/{owner}/{repo}/pulls/{pull_number}/merge
func (s*PullRequestsService) IsMerged(ctx context.Context, owner, repostring, numberint) (bool, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls/%v/merge", owner, repo, number)
req, err:=s.client.NewRequest(ctx, "GET", u, nil)
iferr!=nil {
returnfalse, nil, err
}
resp, err:=s.client.Do(req, nil)
merged, err:=parseBoolResponse(err)
returnmerged, resp, err
}
// PullRequestMergeResult represents the result of merging a pull request.
typePullRequestMergeResultstruct {
SHA*string`json:"sha,omitempty"`
Merged*bool`json:"merged,omitempty"`
Message*string`json:"message,omitempty"`
}
// PullRequestOptions lets you define how a pull request will be merged.
typePullRequestOptionsstruct {
CommitTitlestring// Title for the automatic commit message. (Optional.)
SHAstring// SHA that pull request head must match to allow merge. (Optional.)
// The merge method to use. Possible values include: "merge", "squash", and "rebase" with the default being merge. (Optional.)
MergeMethodstring
// If false, an empty string commit message will use the default commit message. If true, an empty string commit message will be used.
DontDefaultIfBlankbool
}
typepullRequestMergeRequeststruct {
CommitMessage*string`json:"commit_message,omitempty"`
CommitTitlestring`json:"commit_title,omitempty"`
MergeMethodstring`json:"merge_method,omitempty"`
SHAstring`json:"sha,omitempty"`
}
// PullRequestMergeAsyncRequest represents a request to merge a pull request asynchronously.
typePullRequestMergeAsyncRequeststruct {
// MergeMethod is the merge method: merge, squash, or rebase. Not supported on merge_queue actions.
MergeMethod*string`json:"merge_method,omitempty"`
// MergeAction is how to merge: default, direct_merge, or merge_queue.
MergeAction*string`json:"merge_action,omitempty"`
// CommitTitle is the title for the automatic commit message. Not supported on merge_queue actions.
CommitTitle*string`json:"commit_title,omitempty"`
// CommitMessage is extra detail to append to the automatic commit message. Not supported on merge_queue actions.
CommitMessage*string`json:"commit_message,omitempty"`
// SHA that the pull request head must match to allow the merge.
SHA*string`json:"sha,omitempty"`
}
// PullRequestMergeAsyncResult represents the current state of an asynchronous merge request.
typePullRequestMergeAsyncResultstruct {
Status*string`json:"status,omitempty"`
Details*PullRequestMergeAsyncDetails`json:"details,omitempty"`
}
// PullRequestMergeAsyncDetails represents details for the current state of a PullRequestMergeAsyncResult.
typePullRequestMergeAsyncDetailsstruct {
Message*string`json:"message,omitempty"`
UUID*string`json:"uuid,omitempty"`
MergeMethod*string`json:"merge_method,omitempty"`
MergeAction*string`json:"merge_action,omitempty"`
ExpectedHeadSHA*string`json:"expected_head_sha,omitempty"`
SHA*string`json:"sha,omitempty"`
}
// Merge a pull request.
// commitMessage is an extra detail to append to automatic commit message.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#merge-a-pull-request
//
//meta:operation PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge
func (s*PullRequestsService) Merge(ctx context.Context, owner, repostring, numberint, commitMessagestring, options*PullRequestOptions) (*PullRequestMergeResult, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls/%v/merge", owner, repo, number)
varpullRequestBodypullRequestMergeRequest
ifcommitMessage!="" {
pullRequestBody.CommitMessage=&commitMessage
}
ifoptions!=nil {
pullRequestBody.CommitTitle=options.CommitTitle
pullRequestBody.MergeMethod=options.MergeMethod
pullRequestBody.SHA=options.SHA
ifoptions.DontDefaultIfBlank&&commitMessage=="" {
pullRequestBody.CommitMessage=&commitMessage
}
}
req, err:=s.client.NewRequest(ctx, "PUT", u, &pullRequestBody)
iferr!=nil {
returnnil, nil, err
}
varmergeResult*PullRequestMergeResult
resp, err:=s.client.Do(req, &mergeResult)
iferr!=nil {
returnnil, resp, err
}
returnmergeResult, resp, nil
}
// MergeAsync merges a pull request asynchronously. For stacked pull requests,
// this also merges everything below it in the stack. This is the required
// method for merging stacked pull requests; the legacy Merge method cannot be
// used for stacks.
//
// This endpoint typically returns a 202 Accepted status along with the initial
// AsyncMergeResult, since the merge is processed asynchronously. Because this
// is an explicitly asynchronous call, the returned status code is not treated
// as an error here.
//
// A pending response includes a UUID in PullRequestMergeAsyncResult.Details.UUID
// that must be passed to GetMergeAsyncResult to poll for the outcome.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#merge-a-pull-request-asynchronously
//
//meta:operation PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge-async
func (s*PullRequestsService) MergeAsync(ctx context.Context, owner, repostring, numberint, bodyPullRequestMergeAsyncRequest) (*PullRequestMergeAsyncResult, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls/%v/merge-async", owner, repo, number)
req, err:=s.client.NewRequest(ctx, "PUT", u, body)
iferr!=nil {
returnnil, nil, err
}
varresult*PullRequestMergeAsyncResult
resp, err:=s.client.Do(req, &result)
iferr!=nil {
returnnil, resp, err
}
returnresult, resp, nil
}
// GetMergeAsyncResult fetches the current result of an asynchronous merge
// request, identified by the uuid returned when the merge was submitted via
// MergeAsync. Poll this method until the returned status is no longer
// "pending". Results are retained for 24 hours after their most recent update.
//
// GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#get-the-result-of-an-asynchronous-merge
//
//meta:operation GET /repos/{owner}/{repo}/pulls/{pull_number}/merge-async/{uuid}
func (s*PullRequestsService) GetMergeAsyncResult(ctx context.Context, owner, repostring, numberint, uuidstring) (*PullRequestMergeAsyncResult, *Response, error) {
u:=fmt.Sprintf("repos/%v/%v/pulls/%v/merge-async/%v", owner, repo, number, uuid)
req, err:=s.client.NewRequest(ctx, "GET", u, nil)
iferr!=nil {
returnnil, nil, err
}
varresult*PullRequestMergeAsyncResult
resp, err:=s.client.Do(req, &result)
iferr!=nil {
returnnil, resp, err
}
returnresult, resp, nil
}