Add ListPullRequestCommits #530

Merged
lunny merged 1 commits from 6543/go-sdk:repoGetPullRequestCommits into master 2021-07-03 12:29:51 +00:00
3 changed files with 25 additions and 0 deletions

View File

@ -285,6 +285,24 @@ func (c *Client) GetPullRequestDiff(owner, repo string, index int64) ([]byte, *R
return c.getPullRequestDiffOrPatch(owner, repo, "diff", index)
}
// ListPullRequestCommitsOptions options for listing pull requests
type ListPullRequestCommitsOptions struct {
ListOptions
}
// ListPullRequestCommits list commits for a pull request
func (c *Client) ListPullRequestCommits(owner, repo string, index int64, opt ListPullRequestCommitsOptions) ([]*Commit, *Response, error) {
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
return nil, nil, err
}
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/pulls/%d/commits", owner, repo, index))
opt.setDefaults()
commits := make([]*Commit, 0, opt.PageSize)
link.RawQuery = opt.getURLQuery().Encode()
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &commits)
return commits, resp, err
}
// fixPullHeadSha is a workaround for https://github.com/go-gitea/gitea/issues/12675
// When no head sha is available, this is because the branch got deleted in the base repo.
// pr.Head.Ref points in this case not to the head repo branch name, but the base repo ref,

View File

@ -63,6 +63,12 @@ func TestPull(t *testing.T) {
assert.NoError(t, err)
assert.True(t, len(patch) > len(diff))
commits, _, err := c.ListPullRequestCommits(c.username, repoName, pullUpdateFile.Index, ListPullRequestCommitsOptions{})
assert.NoError(t, err)
if assert.Len(t, commits, 1) && assert.Len(t, commits[0].Files, 1) {
assert.EqualValues(t, "LICENSE", commits[0].Files[0].Filename)
}
// test Update pull
pr, _, err := c.GetPullRequest(user.UserName, repoName, pullUpdateFile.Index)
assert.NoError(t, err)

View File

@ -45,6 +45,7 @@ var (
version1_12_0, _ = version.NewVersion("1.12.0")
version1_13_0, _ = version.NewVersion("1.13.0")
version1_14_0, _ = version.NewVersion("1.14.0")
version1_15_0, _ = version.NewVersion("1.15.0")
)
// checkServerVersionGreaterThanOrEqual is internally used to speed up things and ignore issues with prerelease