From 8967205dd7f2c30d55f79245494a43fce0546360 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Fri, 31 Oct 2014 10:49:34 -0700 Subject: [PATCH] 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. --- github/pulls.go | 4 ++-- github/pulls_test.go | 6 +++--- tests/integration/pulls_test.go | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 tests/integration/pulls_test.go diff --git a/github/pulls.go b/github/pulls.go index 017da75..307562d 100644 --- a/github/pulls.go +++ b/github/pulls.go @@ -169,7 +169,7 @@ func (s *PullRequestsService) Edit(owner string, repo string, number int, pull * // ListCommits lists the commits in 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, err := addOptions(u, opt) if err != nil { @@ -181,7 +181,7 @@ func (s *PullRequestsService) ListCommits(owner string, repo string, number int, return nil, nil, err } - commits := new([]Commit) + commits := new([]RepositoryCommit) resp, err := s.client.Do(req, commits) if err != nil { return nil, resp, err diff --git a/github/pulls_test.go b/github/pulls_test.go index 9307c4e..545c905 100644 --- a/github/pulls_test.go +++ b/github/pulls_test.go @@ -205,8 +205,8 @@ func TestPullRequestsService_ListCommits(t *testing.T) { t.Errorf("PullRequests.ListCommits returned error: %v", err) } - want := []Commit{ - Commit{ + want := []RepositoryCommit{ + { SHA: String("3"), Parents: []Commit{ Commit{ @@ -214,7 +214,7 @@ func TestPullRequestsService_ListCommits(t *testing.T) { }, }, }, - Commit{ + { SHA: String("2"), Parents: []Commit{ Commit{ diff --git a/tests/integration/pulls_test.go b/tests/integration/pulls_test.go new file mode 100644 index 0000000..50a3221 --- /dev/null +++ b/tests/integration/pulls_test.go @@ -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) + } +}