Add ListPullRequestCommits (#530)
ref: https://github.com/go-gitea/gitea/pull/16300 Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/530 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Norwin <noerw@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
13d2d23dfc
commit
230fd25196
3 changed files with 25 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue