Browse Source

Add PullRequest branch fields Base and Head

Quinn Slack 11 years ago
parent
commit
d8cbc48267
2 changed files with 54 additions and 4 deletions
  1. +21
    -2
      github/pulls.go
  2. +33
    -2
      github/pulls_test.go

+ 21
- 2
github/pulls.go View File

@ -42,13 +42,23 @@ type PullRequest struct {
IssueURL *string `json:"issue_url,omitempty"` IssueURL *string `json:"issue_url,omitempty"`
StatusesURL *string `json:"statuses_url,omitempty"` StatusesURL *string `json:"statuses_url,omitempty"`
// TODO(willnorris): add head and base once we have a Commit struct defined somewhere
Head *PullRequestBranch `json:"head,omitempty"`
Base *PullRequestBranch `json:"base,omitempty"`
} }
func (p PullRequest) String() string { func (p PullRequest) String() string {
return Stringify(p) return Stringify(p)
} }
// PullRequestBranch represents a base or head branch in a GitHub pull request.
type PullRequestBranch struct {
Label *string `json:"label,omitempty"`
Ref *string `json:"ref,omitempty"`
SHA *string `json:"sha,omitempty"`
Repo *Repository `json:"repo,omitempty"`
User *User `json:"user,omitempty"`
}
// PullRequestListOptions specifies the optional parameters to the // PullRequestListOptions specifies the optional parameters to the
// PullRequestsService.List method. // PullRequestsService.List method.
type PullRequestListOptions struct { type PullRequestListOptions struct {
@ -109,10 +119,19 @@ func (s *PullRequestsService) Get(owner string, repo string, number int) (*PullR
return pull, resp, err return pull, resp, err
} }
// NewPullRequest represents a new pull request to be created.
type NewPullRequest struct {
Title *string `json:"title,omitempty"`
Head *string `json:"head,omitempty"`
Base *string `json:"base,omitempty"`
Body *string `json:"body,omitempty"`
Issue *int `json:"issue,omitempty"`
}
// Create a new pull request on the specified repository. // Create a new pull request on the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#create-a-pull-request // GitHub API docs: https://developer.github.com/v3/pulls/#create-a-pull-request
func (s *PullRequestsService) Create(owner string, repo string, pull *PullRequest) (*PullRequest, *Response, error) {
func (s *PullRequestsService) Create(owner string, repo string, pull *NewPullRequest) (*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo) u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo)
req, err := s.client.NewRequest("POST", u, pull) req, err := s.client.NewRequest("POST", u, pull)
if err != nil { if err != nil {


+ 33
- 2
github/pulls_test.go View File

@ -67,6 +67,37 @@ func TestPullRequestsService_Get(t *testing.T) {
} }
} }
func TestPullRequestsService_Get_headAndBase(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"number":1,"head":{"ref":"r2","repo":{"id":2}},"base":{"ref":"r1","repo":{"id":1}}}`)
})
pull, _, err := client.PullRequests.Get("o", "r", 1)
if err != nil {
t.Errorf("PullRequests.Get returned error: %v", err)
}
want := &PullRequest{
Number: Int(1),
Head: &PullRequestBranch{
Ref: String("r2"),
Repo: &Repository{ID: Int(2)},
},
Base: &PullRequestBranch{
Ref: String("r1"),
Repo: &Repository{ID: Int(1)},
},
}
if !reflect.DeepEqual(pull, want) {
t.Errorf("PullRequests.Get returned %+v, want %+v", pull, want)
}
}
func TestPullRequestsService_Get_invalidOwner(t *testing.T) { func TestPullRequestsService_Get_invalidOwner(t *testing.T) {
_, _, err := client.PullRequests.Get("%", "r", 1) _, _, err := client.PullRequests.Get("%", "r", 1)
testURLParseError(t, err) testURLParseError(t, err)
@ -76,10 +107,10 @@ func TestPullRequestsService_Create(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
input := &PullRequest{Title: String("t")}
input := &NewPullRequest{Title: String("t")}
mux.HandleFunc("/repos/o/r/pulls", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/pulls", func(w http.ResponseWriter, r *http.Request) {
v := new(PullRequest)
v := new(NewPullRequest)
json.NewDecoder(r.Body).Decode(v) json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST") testMethod(t, r, "POST")


Loading…
Cancel
Save