From bf35f510b4cac7b88634ccc5786460f456925f82 Mon Sep 17 00:00:00 2001 From: lkxed Date: Wed, 20 Apr 2022 12:46:59 +0800 Subject: [PATCH 1/4] Add support to sync a fork branch with the upstream repository. --- github/github-accessors.go | 32 ++++++++++++++ github/github-accessors_test.go | 40 ++++++++++++++++++ github/repos_merging_upstream.go | 45 ++++++++++++++++++++ github/repos_merging_upstream_test.go | 61 +++++++++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 github/repos_merging_upstream.go create mode 100644 github/repos_merging_upstream_test.go diff --git a/github/github-accessors.go b/github/github-accessors.go index 724e67f0d3..34781ef7ea 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -8678,6 +8678,30 @@ func (m *MembershipEvent) GetTeam() *Team { return m.Team } +// GetBaseBranch returns the BaseBranch field if it's non-nil, zero value otherwise. +func (m *MergeUpstreamResult) GetBaseBranch() string { + if m == nil || m.BaseBranch == nil { + return "" + } + return *m.BaseBranch +} + +// GetMergeType returns the MergeType field if it's non-nil, zero value otherwise. +func (m *MergeUpstreamResult) GetMergeType() string { + if m == nil || m.MergeType == nil { + return "" + } + return *m.MergeType +} + +// GetMessage returns the Message field if it's non-nil, zero value otherwise. +func (m *MergeUpstreamResult) GetMessage() string { + if m == nil || m.Message == nil { + return "" + } + return *m.Message +} + // GetText returns the Text field if it's non-nil, zero value otherwise. func (m *Message) GetText() string { if m == nil || m.Text == nil { @@ -15262,6 +15286,14 @@ func (r *RepositoryMergeRequest) GetHead() string { return *r.Head } +// GetBranch returns the Branch field if it's non-nil, zero value otherwise. +func (r *RepositoryMergeUpstreamRequest) GetBranch() string { + if r == nil || r.Branch == nil { + return "" + } + return *r.Branch +} + // GetPermission returns the Permission field if it's non-nil, zero value otherwise. func (r *RepositoryPermissionLevel) GetPermission() string { if r == nil || r.Permission == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 5ac8d7b9a6..a99eef8274 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -10158,6 +10158,36 @@ func TestMembershipEvent_GetTeam(tt *testing.T) { m.GetTeam() } +func TestMergeUpstreamResult_GetBaseBranch(tt *testing.T) { + var zeroValue string + m := &MergeUpstreamResult{BaseBranch: &zeroValue} + m.GetBaseBranch() + m = &MergeUpstreamResult{} + m.GetBaseBranch() + m = nil + m.GetBaseBranch() +} + +func TestMergeUpstreamResult_GetMergeType(tt *testing.T) { + var zeroValue string + m := &MergeUpstreamResult{MergeType: &zeroValue} + m.GetMergeType() + m = &MergeUpstreamResult{} + m.GetMergeType() + m = nil + m.GetMergeType() +} + +func TestMergeUpstreamResult_GetMessage(tt *testing.T) { + var zeroValue string + m := &MergeUpstreamResult{Message: &zeroValue} + m.GetMessage() + m = &MergeUpstreamResult{} + m.GetMessage() + m = nil + m.GetMessage() +} + func TestMessage_GetText(tt *testing.T) { var zeroValue string m := &Message{Text: &zeroValue} @@ -17797,6 +17827,16 @@ func TestRepositoryMergeRequest_GetHead(tt *testing.T) { r.GetHead() } +func TestRepositoryMergeUpstreamRequest_GetBranch(tt *testing.T) { + var zeroValue string + r := &RepositoryMergeUpstreamRequest{Branch: &zeroValue} + r.GetBranch() + r = &RepositoryMergeUpstreamRequest{} + r.GetBranch() + r = nil + r.GetBranch() +} + func TestRepositoryPermissionLevel_GetPermission(tt *testing.T) { var zeroValue string r := &RepositoryPermissionLevel{Permission: &zeroValue} diff --git a/github/repos_merging_upstream.go b/github/repos_merging_upstream.go new file mode 100644 index 0000000000..88c996523a --- /dev/null +++ b/github/repos_merging_upstream.go @@ -0,0 +1,45 @@ +// Copyright 2014 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 ( + "context" + "fmt" +) + +// RepositoryMergeUpstreamRequest represents a request to sync a branch of +// a forked repository to keep it up-to-date with the upstream repository. +type RepositoryMergeUpstreamRequest struct { + Branch *string `json:"branch,omitempty"` +} + +// MergeUpstreamResult represents the result of syncing a branch of +// a forked repository with the upstream repository. +type MergeUpstreamResult struct { + Message *string `json:"message,omitempty"` + MergeType *string `json:"merge_type,omitempty"` + BaseBranch *string `json:"base_branch,omitempty"` +} + +// MergeUpstream syncs a branch of a forked repository to keep it up-to-date +// with the upstream repository. +// +// GitHub API docs: https://docs.github.com/en/rest/reference/branches#sync-a-fork-branch-with-the-upstream-repository +func (s *RepositoriesService) MergeUpstream(ctx context.Context, owner, repo string, request *RepositoryMergeUpstreamRequest) (*MergeUpstreamResult, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/merge-upstream", owner, repo) + req, err := s.client.NewRequest("POST", u, request) + if err != nil { + return nil, nil, err + } + + result := new(MergeUpstreamResult) + resp, err := s.client.Do(ctx, req, result) + if err != nil { + return nil, resp, err + } + + return result, resp, nil +} diff --git a/github/repos_merging_upstream_test.go b/github/repos_merging_upstream_test.go new file mode 100644 index 0000000000..219ea1e79a --- /dev/null +++ b/github/repos_merging_upstream_test.go @@ -0,0 +1,61 @@ +// Copyright 2014 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 ( + "context" + "encoding/json" + "fmt" + "github.com/google/go-cmp/cmp" + "net/http" + "testing" +) + +func TestRepositoriesService_MergeUpstream(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := &RepositoryMergeUpstreamRequest{ + Branch: String("b"), + } + + mux.HandleFunc("/repos/o/r/merge-upstream", func(w http.ResponseWriter, r *http.Request) { + v := new(RepositoryMergeUpstreamRequest) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "POST") + if !cmp.Equal(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"merge_type":"m"}`) + }) + + ctx := context.Background() + result, _, err := client.Repositories.MergeUpstream(ctx, "o", "r", input) + if err != nil { + t.Errorf("Repositories.MergeUpstream returned error: %v", err) + } + + want := &MergeUpstreamResult{MergeType: String("m")} + if !cmp.Equal(result, want) { + t.Errorf("Repositories.MergeUpstream returned %+v, want %+v", result, want) + } + + const methodName = "MergeUpstream" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Repositories.MergeUpstream(ctx, "\n", "\n", input) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Repositories.MergeUpstream(ctx, "o", "r", input) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} From 68232fbabbcaced702f61f05b2c06160f114f540 Mon Sep 17 00:00:00 2001 From: lkxed Date: Wed, 20 Apr 2022 13:06:17 +0800 Subject: [PATCH 2/4] Change the year `2014` to `2022` in the standard header. --- github/repos_merging_upstream.go | 2 +- github/repos_merging_upstream_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/github/repos_merging_upstream.go b/github/repos_merging_upstream.go index 88c996523a..5d837853f9 100644 --- a/github/repos_merging_upstream.go +++ b/github/repos_merging_upstream.go @@ -1,4 +1,4 @@ -// Copyright 2014 The go-github AUTHORS. All rights reserved. +// Copyright 2022 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. diff --git a/github/repos_merging_upstream_test.go b/github/repos_merging_upstream_test.go index 219ea1e79a..426bd3823a 100644 --- a/github/repos_merging_upstream_test.go +++ b/github/repos_merging_upstream_test.go @@ -1,4 +1,4 @@ -// Copyright 2014 The go-github AUTHORS. All rights reserved. +// Copyright 2022 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. From bc4a0f0708350d77912519f96e0d1816e00187ba Mon Sep 17 00:00:00 2001 From: lkxed Date: Wed, 20 Apr 2022 21:39:36 +0800 Subject: [PATCH 3/4] Move my code to the existing `repos_merging.go` and `repos_merging_test.go` files. --- github/repos_merging.go | 34 +++++++++++++++ github/repos_merging_test.go | 46 ++++++++++++++++++++ github/repos_merging_upstream.go | 45 -------------------- github/repos_merging_upstream_test.go | 61 --------------------------- 4 files changed, 80 insertions(+), 106 deletions(-) delete mode 100644 github/repos_merging_upstream.go delete mode 100644 github/repos_merging_upstream_test.go diff --git a/github/repos_merging.go b/github/repos_merging.go index 7edda3efff..ed441dfcf4 100644 --- a/github/repos_merging.go +++ b/github/repos_merging.go @@ -18,6 +18,20 @@ type RepositoryMergeRequest struct { CommitMessage *string `json:"commit_message,omitempty"` } +// RepositoryMergeUpstreamRequest represents a request to sync a branch of +// a forked repository to keep it up-to-date with the upstream repository. +type RepositoryMergeUpstreamRequest struct { + Branch *string `json:"branch,omitempty"` +} + +// MergeUpstreamResult represents the result of syncing a branch of +// a forked repository with the upstream repository. +type MergeUpstreamResult struct { + Message *string `json:"message,omitempty"` + MergeType *string `json:"merge_type,omitempty"` + BaseBranch *string `json:"base_branch,omitempty"` +} + // Merge a branch in the specified repository. // // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#merge-a-branch @@ -36,3 +50,23 @@ func (s *RepositoriesService) Merge(ctx context.Context, owner, repo string, req return commit, resp, nil } + +// MergeUpstream syncs a branch of a forked repository to keep it up-to-date +// with the upstream repository. +// +// GitHub API docs: https://docs.github.com/en/rest/reference/branches#sync-a-fork-branch-with-the-upstream-repository +func (s *RepositoriesService) MergeUpstream(ctx context.Context, owner, repo string, request *RepositoryMergeUpstreamRequest) (*MergeUpstreamResult, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/merge-upstream", owner, repo) + req, err := s.client.NewRequest("POST", u, request) + if err != nil { + return nil, nil, err + } + + result := new(MergeUpstreamResult) + resp, err := s.client.Do(ctx, req, result) + if err != nil { + return nil, resp, err + } + + return result, resp, nil +} diff --git a/github/repos_merging_test.go b/github/repos_merging_test.go index 052631000a..ff98ba2503 100644 --- a/github/repos_merging_test.go +++ b/github/repos_merging_test.go @@ -80,3 +80,49 @@ func TestRepositoryMergeRequest_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } + +func TestRepositoriesService_MergeUpstream(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := &RepositoryMergeUpstreamRequest{ + Branch: String("b"), + } + + mux.HandleFunc("/repos/o/r/merge-upstream", func(w http.ResponseWriter, r *http.Request) { + v := new(RepositoryMergeUpstreamRequest) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "POST") + if !cmp.Equal(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"merge_type":"m"}`) + }) + + ctx := context.Background() + result, _, err := client.Repositories.MergeUpstream(ctx, "o", "r", input) + if err != nil { + t.Errorf("Repositories.MergeUpstream returned error: %v", err) + } + + want := &MergeUpstreamResult{MergeType: String("m")} + if !cmp.Equal(result, want) { + t.Errorf("Repositories.MergeUpstream returned %+v, want %+v", result, want) + } + + const methodName = "MergeUpstream" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Repositories.MergeUpstream(ctx, "\n", "\n", input) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Repositories.MergeUpstream(ctx, "o", "r", input) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} diff --git a/github/repos_merging_upstream.go b/github/repos_merging_upstream.go deleted file mode 100644 index 5d837853f9..0000000000 --- a/github/repos_merging_upstream.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2022 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 ( - "context" - "fmt" -) - -// RepositoryMergeUpstreamRequest represents a request to sync a branch of -// a forked repository to keep it up-to-date with the upstream repository. -type RepositoryMergeUpstreamRequest struct { - Branch *string `json:"branch,omitempty"` -} - -// MergeUpstreamResult represents the result of syncing a branch of -// a forked repository with the upstream repository. -type MergeUpstreamResult struct { - Message *string `json:"message,omitempty"` - MergeType *string `json:"merge_type,omitempty"` - BaseBranch *string `json:"base_branch,omitempty"` -} - -// MergeUpstream syncs a branch of a forked repository to keep it up-to-date -// with the upstream repository. -// -// GitHub API docs: https://docs.github.com/en/rest/reference/branches#sync-a-fork-branch-with-the-upstream-repository -func (s *RepositoriesService) MergeUpstream(ctx context.Context, owner, repo string, request *RepositoryMergeUpstreamRequest) (*MergeUpstreamResult, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/merge-upstream", owner, repo) - req, err := s.client.NewRequest("POST", u, request) - if err != nil { - return nil, nil, err - } - - result := new(MergeUpstreamResult) - resp, err := s.client.Do(ctx, req, result) - if err != nil { - return nil, resp, err - } - - return result, resp, nil -} diff --git a/github/repos_merging_upstream_test.go b/github/repos_merging_upstream_test.go deleted file mode 100644 index 426bd3823a..0000000000 --- a/github/repos_merging_upstream_test.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2022 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 ( - "context" - "encoding/json" - "fmt" - "github.com/google/go-cmp/cmp" - "net/http" - "testing" -) - -func TestRepositoriesService_MergeUpstream(t *testing.T) { - client, mux, _, teardown := setup() - defer teardown() - - input := &RepositoryMergeUpstreamRequest{ - Branch: String("b"), - } - - mux.HandleFunc("/repos/o/r/merge-upstream", func(w http.ResponseWriter, r *http.Request) { - v := new(RepositoryMergeUpstreamRequest) - json.NewDecoder(r.Body).Decode(v) - - testMethod(t, r, "POST") - if !cmp.Equal(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } - - fmt.Fprint(w, `{"merge_type":"m"}`) - }) - - ctx := context.Background() - result, _, err := client.Repositories.MergeUpstream(ctx, "o", "r", input) - if err != nil { - t.Errorf("Repositories.MergeUpstream returned error: %v", err) - } - - want := &MergeUpstreamResult{MergeType: String("m")} - if !cmp.Equal(result, want) { - t.Errorf("Repositories.MergeUpstream returned %+v, want %+v", result, want) - } - - const methodName = "MergeUpstream" - testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Repositories.MergeUpstream(ctx, "\n", "\n", input) - return err - }) - - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Repositories.MergeUpstream(ctx, "o", "r", input) - if got != nil { - t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) - } - return resp, err - }) -} From b763b6621de1378303a82b46af561197bf1bfb06 Mon Sep 17 00:00:00 2001 From: lkxed Date: Wed, 20 Apr 2022 23:43:58 +0800 Subject: [PATCH 4/4] change the prefix of type names to `RepoMergeUpstream` to be more self-consistent --- github/github-accessors.go | 64 +++++++++++++------------- github/github-accessors_test.go | 80 ++++++++++++++++----------------- github/repos_merging.go | 12 ++--- github/repos_merging_test.go | 6 +-- 4 files changed, 81 insertions(+), 81 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 34781ef7ea..24c2ada433 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -8678,30 +8678,6 @@ func (m *MembershipEvent) GetTeam() *Team { return m.Team } -// GetBaseBranch returns the BaseBranch field if it's non-nil, zero value otherwise. -func (m *MergeUpstreamResult) GetBaseBranch() string { - if m == nil || m.BaseBranch == nil { - return "" - } - return *m.BaseBranch -} - -// GetMergeType returns the MergeType field if it's non-nil, zero value otherwise. -func (m *MergeUpstreamResult) GetMergeType() string { - if m == nil || m.MergeType == nil { - return "" - } - return *m.MergeType -} - -// GetMessage returns the Message field if it's non-nil, zero value otherwise. -func (m *MergeUpstreamResult) GetMessage() string { - if m == nil || m.Message == nil { - return "" - } - return *m.Message -} - // GetText returns the Text field if it's non-nil, zero value otherwise. func (m *Message) GetText() string { if m == nil || m.Text == nil { @@ -13902,6 +13878,38 @@ func (r *RenameOrgResponse) GetURL() string { return *r.URL } +// GetBranch returns the Branch field if it's non-nil, zero value otherwise. +func (r *RepoMergeUpstreamRequest) GetBranch() string { + if r == nil || r.Branch == nil { + return "" + } + return *r.Branch +} + +// GetBaseBranch returns the BaseBranch field if it's non-nil, zero value otherwise. +func (r *RepoMergeUpstreamResult) GetBaseBranch() string { + if r == nil || r.BaseBranch == nil { + return "" + } + return *r.BaseBranch +} + +// GetMergeType returns the MergeType field if it's non-nil, zero value otherwise. +func (r *RepoMergeUpstreamResult) GetMergeType() string { + if r == nil || r.MergeType == nil { + return "" + } + return *r.MergeType +} + +// GetMessage returns the Message field if it's non-nil, zero value otherwise. +func (r *RepoMergeUpstreamResult) GetMessage() string { + if r == nil || r.Message == nil { + return "" + } + return *r.Message +} + // GetFrom returns the From field if it's non-nil, zero value otherwise. func (r *RepoName) GetFrom() string { if r == nil || r.From == nil { @@ -15286,14 +15294,6 @@ func (r *RepositoryMergeRequest) GetHead() string { return *r.Head } -// GetBranch returns the Branch field if it's non-nil, zero value otherwise. -func (r *RepositoryMergeUpstreamRequest) GetBranch() string { - if r == nil || r.Branch == nil { - return "" - } - return *r.Branch -} - // GetPermission returns the Permission field if it's non-nil, zero value otherwise. func (r *RepositoryPermissionLevel) GetPermission() string { if r == nil || r.Permission == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index a99eef8274..a4aab16d62 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -10158,36 +10158,6 @@ func TestMembershipEvent_GetTeam(tt *testing.T) { m.GetTeam() } -func TestMergeUpstreamResult_GetBaseBranch(tt *testing.T) { - var zeroValue string - m := &MergeUpstreamResult{BaseBranch: &zeroValue} - m.GetBaseBranch() - m = &MergeUpstreamResult{} - m.GetBaseBranch() - m = nil - m.GetBaseBranch() -} - -func TestMergeUpstreamResult_GetMergeType(tt *testing.T) { - var zeroValue string - m := &MergeUpstreamResult{MergeType: &zeroValue} - m.GetMergeType() - m = &MergeUpstreamResult{} - m.GetMergeType() - m = nil - m.GetMergeType() -} - -func TestMergeUpstreamResult_GetMessage(tt *testing.T) { - var zeroValue string - m := &MergeUpstreamResult{Message: &zeroValue} - m.GetMessage() - m = &MergeUpstreamResult{} - m.GetMessage() - m = nil - m.GetMessage() -} - func TestMessage_GetText(tt *testing.T) { var zeroValue string m := &Message{Text: &zeroValue} @@ -16187,6 +16157,46 @@ func TestRenameOrgResponse_GetURL(tt *testing.T) { r.GetURL() } +func TestRepoMergeUpstreamRequest_GetBranch(tt *testing.T) { + var zeroValue string + r := &RepoMergeUpstreamRequest{Branch: &zeroValue} + r.GetBranch() + r = &RepoMergeUpstreamRequest{} + r.GetBranch() + r = nil + r.GetBranch() +} + +func TestRepoMergeUpstreamResult_GetBaseBranch(tt *testing.T) { + var zeroValue string + r := &RepoMergeUpstreamResult{BaseBranch: &zeroValue} + r.GetBaseBranch() + r = &RepoMergeUpstreamResult{} + r.GetBaseBranch() + r = nil + r.GetBaseBranch() +} + +func TestRepoMergeUpstreamResult_GetMergeType(tt *testing.T) { + var zeroValue string + r := &RepoMergeUpstreamResult{MergeType: &zeroValue} + r.GetMergeType() + r = &RepoMergeUpstreamResult{} + r.GetMergeType() + r = nil + r.GetMergeType() +} + +func TestRepoMergeUpstreamResult_GetMessage(tt *testing.T) { + var zeroValue string + r := &RepoMergeUpstreamResult{Message: &zeroValue} + r.GetMessage() + r = &RepoMergeUpstreamResult{} + r.GetMessage() + r = nil + r.GetMessage() +} + func TestRepoName_GetFrom(tt *testing.T) { var zeroValue string r := &RepoName{From: &zeroValue} @@ -17827,16 +17837,6 @@ func TestRepositoryMergeRequest_GetHead(tt *testing.T) { r.GetHead() } -func TestRepositoryMergeUpstreamRequest_GetBranch(tt *testing.T) { - var zeroValue string - r := &RepositoryMergeUpstreamRequest{Branch: &zeroValue} - r.GetBranch() - r = &RepositoryMergeUpstreamRequest{} - r.GetBranch() - r = nil - r.GetBranch() -} - func TestRepositoryPermissionLevel_GetPermission(tt *testing.T) { var zeroValue string r := &RepositoryPermissionLevel{Permission: &zeroValue} diff --git a/github/repos_merging.go b/github/repos_merging.go index ed441dfcf4..a8d860742c 100644 --- a/github/repos_merging.go +++ b/github/repos_merging.go @@ -18,15 +18,15 @@ type RepositoryMergeRequest struct { CommitMessage *string `json:"commit_message,omitempty"` } -// RepositoryMergeUpstreamRequest represents a request to sync a branch of +// RepoMergeUpstreamRequest represents a request to sync a branch of // a forked repository to keep it up-to-date with the upstream repository. -type RepositoryMergeUpstreamRequest struct { +type RepoMergeUpstreamRequest struct { Branch *string `json:"branch,omitempty"` } -// MergeUpstreamResult represents the result of syncing a branch of +// RepoMergeUpstreamResult represents the result of syncing a branch of // a forked repository with the upstream repository. -type MergeUpstreamResult struct { +type RepoMergeUpstreamResult struct { Message *string `json:"message,omitempty"` MergeType *string `json:"merge_type,omitempty"` BaseBranch *string `json:"base_branch,omitempty"` @@ -55,14 +55,14 @@ func (s *RepositoriesService) Merge(ctx context.Context, owner, repo string, req // with the upstream repository. // // GitHub API docs: https://docs.github.com/en/rest/reference/branches#sync-a-fork-branch-with-the-upstream-repository -func (s *RepositoriesService) MergeUpstream(ctx context.Context, owner, repo string, request *RepositoryMergeUpstreamRequest) (*MergeUpstreamResult, *Response, error) { +func (s *RepositoriesService) MergeUpstream(ctx context.Context, owner, repo string, request *RepoMergeUpstreamRequest) (*RepoMergeUpstreamResult, *Response, error) { u := fmt.Sprintf("repos/%v/%v/merge-upstream", owner, repo) req, err := s.client.NewRequest("POST", u, request) if err != nil { return nil, nil, err } - result := new(MergeUpstreamResult) + result := new(RepoMergeUpstreamResult) resp, err := s.client.Do(ctx, req, result) if err != nil { return nil, resp, err diff --git a/github/repos_merging_test.go b/github/repos_merging_test.go index ff98ba2503..0275915b9b 100644 --- a/github/repos_merging_test.go +++ b/github/repos_merging_test.go @@ -85,12 +85,12 @@ func TestRepositoriesService_MergeUpstream(t *testing.T) { client, mux, _, teardown := setup() defer teardown() - input := &RepositoryMergeUpstreamRequest{ + input := &RepoMergeUpstreamRequest{ Branch: String("b"), } mux.HandleFunc("/repos/o/r/merge-upstream", func(w http.ResponseWriter, r *http.Request) { - v := new(RepositoryMergeUpstreamRequest) + v := new(RepoMergeUpstreamRequest) json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") @@ -107,7 +107,7 @@ func TestRepositoriesService_MergeUpstream(t *testing.T) { t.Errorf("Repositories.MergeUpstream returned error: %v", err) } - want := &MergeUpstreamResult{MergeType: String("m")} + want := &RepoMergeUpstreamResult{MergeType: String("m")} if !cmp.Equal(result, want) { t.Errorf("Repositories.MergeUpstream returned %+v, want %+v", result, want) }