github.com/google/go-github/v49@v49.1.0/github/repos_merging.go (about) 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/en/rest/branches/branches#merge-a-branch 38 func (s *RepositoriesService) Merge(ctx context.Context, owner, repo string, request *RepositoryMergeRequest) (*RepositoryCommit, *Response, error) { 39 u := fmt.Sprintf("repos/%v/%v/merges", owner, repo) 40 req, err := s.client.NewRequest("POST", u, request) 41 if err != nil { 42 return nil, nil, err 43 } 44 45 commit := new(RepositoryCommit) 46 resp, err := s.client.Do(ctx, req, commit) 47 if err != nil { 48 return nil, resp, err 49 } 50 51 return commit, resp, nil 52 } 53 54 // MergeUpstream syncs a branch of a forked repository to keep it up-to-date 55 // with the upstream repository. 56 // 57 // GitHub API docs: https://docs.github.com/en/rest/branches/branches#sync-a-fork-branch-with-the-upstream-repository 58 func (s *RepositoriesService) MergeUpstream(ctx context.Context, owner, repo string, request *RepoMergeUpstreamRequest) (*RepoMergeUpstreamResult, *Response, error) { 59 u := fmt.Sprintf("repos/%v/%v/merge-upstream", owner, repo) 60 req, err := s.client.NewRequest("POST", u, request) 61 if err != nil { 62 return nil, nil, err 63 } 64 65 result := new(RepoMergeUpstreamResult) 66 resp, err := s.client.Do(ctx, req, result) 67 if err != nil { 68 return nil, resp, err 69 } 70 71 return result, resp, nil 72 }