Add Un-/DismissPullReview funcs (#489)

close #487

Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/489
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-committed-by: 6543 <6543@obermui.de>
This commit is contained in:
6543 2021-02-15 11:15:24 +08:00 committed by John Olheiser
parent 8947cd3b00
commit 95ed973c8d
2 changed files with 56 additions and 1 deletions

View file

@ -97,6 +97,11 @@ type SubmitPullReviewOptions struct {
Body string `json:"body"` Body string `json:"body"`
} }
// DismissPullReviewOptions are options to dismiss a pull review
type DismissPullReviewOptions struct {
Message string `json:"message"`
}
// ListPullReviewsOptions options for listing PullReviews // ListPullReviewsOptions options for listing PullReviews
type ListPullReviewsOptions struct { type ListPullReviewsOptions struct {
ListOptions ListOptions
@ -221,3 +226,31 @@ func (c *Client) SubmitPullReview(owner, repo string, index, id int64, opt Submi
jsonHeader, bytes.NewReader(body), r) jsonHeader, bytes.NewReader(body), r)
return r, resp, err return r, resp, err
} }
// DismissPullReview dismiss a review for a pull request
func (c *Client) DismissPullReview(owner, repo string, index, id int64, opt DismissPullReviewOptions) (*Response, error) {
if err := c.checkServerVersionGreaterThanOrEqual(version1_14_0); err != nil {
return nil, err
}
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
_, resp, err := c.getResponse("POST",
fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews/%d/dismissals", owner, repo, index, id),
jsonHeader, bytes.NewReader(body))
return resp, err
}
// UnDismissPullReview cancel to dismiss a review for a pull request
func (c *Client) UnDismissPullReview(owner, repo string, index, id int64) (*Response, error) {
if err := c.checkServerVersionGreaterThanOrEqual(version1_14_0); err != nil {
return nil, err
}
_, resp, err := c.getResponse("POST",
fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews/%d/undismissals", owner, repo, index, id),
jsonHeader, nil)
return resp, err
}

View file

@ -89,7 +89,7 @@ func TestPullReview(t *testing.T) {
// SubmitPullReview // SubmitPullReview
c.SetSudo("") c.SetSudo("")
r4, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{ r4, resp, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
Body: "...", Body: "...",
Comments: []CreatePullReviewComment{{ Comments: []CreatePullReviewComment{{
Path: "WOW-file", Path: "WOW-file",
@ -99,6 +99,7 @@ func TestPullReview(t *testing.T) {
}, },
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, resp)
r5, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{ r5, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
Body: "...", Body: "...",
Comments: []CreatePullReviewComment{{ Comments: []CreatePullReviewComment{{
@ -133,6 +134,27 @@ func TestPullReview(t *testing.T) {
} }
} }
r, _, err = c.GetPullReview(repo.Owner.UserName, repo.Name, pull.Index, r.ID)
assert.NoError(t, err)
assert.False(t, r.Dismissed)
// DismissPullReview
resp, err = c.DismissPullReview(repo.Owner.UserName, repo.Name, pull.Index, r.ID, DismissPullReviewOptions{Message: "stale"})
assert.NoError(t, err)
if assert.NotNil(t, resp) {
assert.EqualValues(t, 200, resp.StatusCode)
}
r, _, _ = c.GetPullReview(repo.Owner.UserName, repo.Name, pull.Index, r.ID)
assert.True(t, r.Dismissed)
// UnDismissPullReview
resp, err = c.UnDismissPullReview(repo.Owner.UserName, repo.Name, pull.Index, r.ID)
assert.NoError(t, err)
if assert.NotNil(t, resp) {
assert.EqualValues(t, 200, resp.StatusCode)
}
r, _, _ = c.GetPullReview(repo.Owner.UserName, repo.Name, pull.Index, r.ID)
assert.False(t, r.Dismissed)
} }
func preparePullReviewTest(t *testing.T, c *Client, repoName string) (*Repository, *PullRequest, *User, *User, bool) { func preparePullReviewTest(t *testing.T, c *Client, repoName string) (*Repository, *PullRequest, *User, *User, bool) {