Browse Source

add support for merge method and repository squash settings

Closes #437.
Closes #446.

Change-Id: I7a9bd0717310ef016b2695fe0e5cffb8e8b86ff8
Garrett Squire 9 years ago
committed by Glenn Lewis
parent
commit
575b0b3756
5 changed files with 25 additions and 7 deletions
  1. +1
    -0
      github/github.go
  2. +8
    -3
      github/pulls.go
  3. +1
    -1
      github/pulls_test.go
  4. +12
    -2
      github/repos.go
  5. +3
    -1
      github/repos_test.go

+ 1
- 0
github/github.go View File

@ -68,6 +68,7 @@ const (
mediaTypeReactionsPreview = "application/vnd.github.squirrel-girl-preview"
// https://developer.github.com/changes/2016-04-01-squash-api-preview/
// https://developer.github.com/changes/2016-09-26-pull-request-merge-api-update/
mediaTypeSquashPreview = "application/vnd.github.polaris-preview+json"
// https://developer.github.com/changes/2016-04-04-git-signing-api-preview/


+ 8
- 3
github/pulls.go View File

@ -253,12 +253,16 @@ type PullRequestMergeResult struct {
// PullRequestOptions lets you define how a pull request will be merged.
type PullRequestOptions struct {
Squash bool
CommitTitle string
// The merge method to use. Possible values include: "merge", "squash", and "rebase" with the default being merge.
MergeMethod string
}
type pullRequestMergeRequest struct {
CommitMessage *string `json:"commit_message"`
Squash *bool `json:"squash,omitempty"`
CommitTitle *string `json:"commit_title,omitempty"`
MergeMethod *string `json:"merge_method,omitempty"`
}
// Merge a pull request (Merge Button™).
@ -269,7 +273,8 @@ func (s *PullRequestsService) Merge(owner string, repo string, number int, commi
pullRequestBody := &pullRequestMergeRequest{CommitMessage: &commitMessage}
if options != nil {
pullRequestBody.Squash = &options.Squash
pullRequestBody.CommitTitle = &options.CommitTitle
pullRequestBody.MergeMethod = &options.MergeMethod
}
req, err := s.client.NewRequest("PUT", u, pullRequestBody)


+ 1
- 1
github/pulls_test.go View File

@ -363,7 +363,7 @@ func TestPullRequestsService_Merge(t *testing.T) {
}`)
})
options := &PullRequestOptions{Squash: true}
options := &PullRequestOptions{MergeMethod: "rebase"}
merge, _, err := client.PullRequests.Merge("o", "r", 1, "merging pull request", options)
if err != nil {
t.Errorf("PullRequests.Merge returned error: %v", err)


+ 12
- 2
github/repos.go View File

@ -5,7 +5,10 @@
package github
import "fmt"
import (
"fmt"
"strings"
)
// RepositoriesService handles communication with the repository related
// methods of the GitHub API.
@ -46,6 +49,9 @@ type Repository struct {
Source *Repository `json:"source,omitempty"`
Organization *Organization `json:"organization,omitempty"`
Permissions *map[string]bool `json:"permissions,omitempty"`
AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"`
AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"`
AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"`
// Only provided when using RepositoriesService.Get while in preview
License *License `json:"license,omitempty"`
@ -286,7 +292,8 @@ func (s *RepositoriesService) Get(owner, repo string) (*Repository, *Response, e
// TODO: remove custom Accept header when the license support fully launches
// https://developer.github.com/v3/licenses/#get-a-repositorys-license
req.Header.Set("Accept", mediaTypeLicensesPreview)
acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeSquashPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
repository := new(Repository)
resp, err := s.client.Do(req, repository)
@ -330,6 +337,9 @@ func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (
return nil, nil, err
}
// TODO: Remove this preview header after API is fully vetted.
req.Header.Add("Accept", mediaTypeSquashPreview)
r := new(Repository)
resp, err := s.client.Do(req, r)
if err != nil {


+ 3
- 1
github/repos_test.go View File

@ -10,6 +10,7 @@ import (
"fmt"
"net/http"
"reflect"
"strings"
"testing"
)
@ -225,9 +226,10 @@ func TestRepositoriesService_Get(t *testing.T) {
setup()
defer teardown()
acceptHeader := []string{mediaTypeLicensesPreview, mediaTypeSquashPreview}
mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeLicensesPreview)
testHeader(t, r, "Accept", strings.Join(acceptHeader, ", "))
fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`)
})


Loading…
Cancel
Save