Browse Source

fix return type of PullRequests.ListCommits

this method actually returns RepositoryCommits (go-github's term for
this, not GitHub's) rather than Commits.  They are very, very close in
structure (which is likely why this has gone unnoticed for so long), one
of the primary differences being that RepositoryCommits exposes the
GitHub identity of the commit author and committer if possible.
Will Norris 12 years ago
parent
commit
8967205dd7
3 changed files with 28 additions and 5 deletions
  1. +2
    -2
      github/pulls.go
  2. +3
    -3
      github/pulls_test.go
  3. +23
    -0
      tests/integration/pulls_test.go

+ 2
- 2
github/pulls.go View File

@ -169,7 +169,7 @@ func (s *PullRequestsService) Edit(owner string, repo string, number int, pull *
// ListCommits lists the commits in a pull request. // ListCommits lists the commits in a pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request // GitHub API docs: https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request
func (s *PullRequestsService) ListCommits(owner string, repo string, number int, opt *ListOptions) ([]Commit, *Response, error) {
func (s *PullRequestsService) ListCommits(owner string, repo string, number int, opt *ListOptions) ([]RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/commits", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/commits", owner, repo, number)
u, err := addOptions(u, opt) u, err := addOptions(u, opt)
if err != nil { if err != nil {
@ -181,7 +181,7 @@ func (s *PullRequestsService) ListCommits(owner string, repo string, number int,
return nil, nil, err return nil, nil, err
} }
commits := new([]Commit)
commits := new([]RepositoryCommit)
resp, err := s.client.Do(req, commits) resp, err := s.client.Do(req, commits)
if err != nil { if err != nil {
return nil, resp, err return nil, resp, err


+ 3
- 3
github/pulls_test.go View File

@ -205,8 +205,8 @@ func TestPullRequestsService_ListCommits(t *testing.T) {
t.Errorf("PullRequests.ListCommits returned error: %v", err) t.Errorf("PullRequests.ListCommits returned error: %v", err)
} }
want := []Commit{
Commit{
want := []RepositoryCommit{
{
SHA: String("3"), SHA: String("3"),
Parents: []Commit{ Parents: []Commit{
Commit{ Commit{
@ -214,7 +214,7 @@ func TestPullRequestsService_ListCommits(t *testing.T) {
}, },
}, },
}, },
Commit{
{
SHA: String("2"), SHA: String("2"),
Parents: []Commit{ Parents: []Commit{
Commit{ Commit{


+ 23
- 0
tests/integration/pulls_test.go View File

@ -0,0 +1,23 @@
// 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 tests
import "testing"
func TestPullRequests_ListCommits(t *testing.T) {
commits, _, err := client.PullRequests.ListCommits("google", "go-github", 2, nil)
if err != nil {
t.Fatalf("PullRequests.ListCommits() returned error: %v", err)
}
if got, want := len(commits), 3; got != want {
t.Fatalf("PullRequests.ListCommits() returned %d commits, want %d", got, want)
}
if got, want := *commits[0].Author.Login, "sqs"; got != want {
t.Fatalf("PullRequests.ListCommits()[0].Author.Login returned %v, want %v", got, want)
}
}

Loading…
Cancel
Save