| 1 |
// Copyright 2014 The go-github AUTHORS. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package github |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"fmt" |
| 11 |
) |
| 12 |
|
| 13 |
// RepositoryMergeRequest represents a request to merge a branch in a |
| 14 |
// repository. |
| 15 |
type RepositoryMergeRequest struct { |
| 16 |
Base *string `json:"base,omitempty"` |
| 17 |
Head *string `json:"head,omitempty"` |
| 18 |
CommitMessage *string `json:"commit_message,omitempty"` |
| 19 |
} |
| 20 |
|
| 21 |
// RepoMergeUpstreamRequest represents a request to sync a branch of |
| 22 |
// a forked repository to keep it up-to-date with the upstream repository. |
| 23 |
type RepoMergeUpstreamRequest struct { |
| 24 |
Branch *string `json:"branch,omitempty"` |
| 25 |
} |
| 26 |
|
| 27 |
// RepoMergeUpstreamResult represents the result of syncing a branch of |
| 28 |
// a forked repository with the upstream repository. |
| 29 |
type RepoMergeUpstreamResult struct { |
| 30 |
Message *string `json:"message,omitempty"` |
| 31 |
MergeType *string `json:"merge_type,omitempty"` |
| 32 |
BaseBranch *string `json:"base_branch,omitempty"` |
| 33 |
} |
| 34 |
|
| 35 |
// Merge a branch in the specified repository. |
| 36 |
// |
| 37 |
// GitHub API docs: https://docs.github.com/rest/branches/branches#merge-a-branch |
| 38 |
// |
| 39 |
//meta:operation POST /repos/{owner}/{repo}/merges |
| 40 |
func (s *RepositoriesService) Merge(ctx context.Context, owner, repo string, request *RepositoryMergeRequest) (*RepositoryCommit, *Response, error) { |
| 41 |
u := fmt.Sprintf("repos/%v/%v/merges", owner, repo) |
| 42 |
req, err := s.client.NewRequest("POST", u, request) |
| 43 |
if err != nil { |
| 44 |
return nil, nil, err |
| 45 |
} |
| 46 |
|
| 47 |
commit := new(RepositoryCommit) |
| 48 |
resp, err := s.client.Do(ctx, req, commit) |
| 49 |
if err != nil { |
| 50 |
return nil, resp, err |
| 51 |
} |
| 52 |
|
| 53 |
return commit, resp, nil |
| 54 |
} |
| 55 |
|
| 56 |
// MergeUpstream syncs a branch of a forked repository to keep it up-to-date |
| 57 |
// with the upstream repository. |
| 58 |
// |
| 59 |
// GitHub API docs: https://docs.github.com/rest/branches/branches#sync-a-fork-branch-with-the-upstream-repository |
| 60 |
// |
| 61 |
//meta:operation POST /repos/{owner}/{repo}/merge-upstream |
| 62 |
func (s *RepositoriesService) MergeUpstream(ctx context.Context, owner, repo string, request *RepoMergeUpstreamRequest) (*RepoMergeUpstreamResult, *Response, error) { |
| 63 |
u := fmt.Sprintf("repos/%v/%v/merge-upstream", owner, repo) |
| 64 |
req, err := s.client.NewRequest("POST", u, request) |
| 65 |
if err != nil { |
| 66 |
return nil, nil, err |
| 67 |
} |
| 68 |
|
| 69 |
result := new(RepoMergeUpstreamResult) |
| 70 |
resp, err := s.client.Do(ctx, req, result) |
| 71 |
if err != nil { |
| 72 |
return nil, resp, err |
| 73 |
} |
| 74 |
|
| 75 |
return result, resp, nil |
| 76 |
} |