Browse Source

add Repositories.Merge method

Will Norris 12 years ago
parent
commit
68ec69e205
2 changed files with 84 additions and 0 deletions
  1. +37
    -0
      github/repos_merging.go
  2. +47
    -0
      github/repos_merging_test.go

+ 37
- 0
github/repos_merging.go View File

@ -0,0 +1,37 @@
// 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 (
"fmt"
)
// RepositoryMergeRequest represents a request to merge a branch in a
// repository.
type RepositoryMergeRequest struct {
Base *string `json:"base,omitempty"`
Head *string `json:"head,omitempty"`
CommitMessage *string `json:"commit_message,omitempty"`
}
// Merge a branch in the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/merging/#perform-a-merge
func (s *RepositoriesService) Merge(owner, repo string, request *RepositoryMergeRequest) (*RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/merges", owner, repo)
req, err := s.client.NewRequest("POST", u, request)
if err != nil {
return nil, nil, err
}
commit := new(RepositoryCommit)
resp, err := s.client.Do(req, commit)
if err != nil {
return nil, resp, err
}
return commit, resp, err
}

+ 47
- 0
github/repos_merging_test.go View File

@ -0,0 +1,47 @@
// 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 (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestRepositoriesService_Merge(t *testing.T) {
setup()
defer teardown()
input := &RepositoryMergeRequest{
Base: String("b"),
Head: String("h"),
CommitMessage: String("c"),
}
mux.HandleFunc("/repos/o/r/merges", func(w http.ResponseWriter, r *http.Request) {
v := new(RepositoryMergeRequest)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"sha":"s"}`)
})
commit, _, err := client.Repositories.Merge("o", "r", input)
if err != nil {
t.Errorf("Repositories.Merge returned error: %v", err)
}
want := &RepositoryCommit{SHA: String("s")}
if !reflect.DeepEqual(commit, want) {
t.Errorf("Repositories.Merge returned %+v, want %+v", commit, want)
}
}

Loading…
Cancel
Save