Add Create/Delete ReviewRequests (#493)
close #439 Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/493 Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
b0ee740ed0
commit
a968e32ca1
2 changed files with 67 additions and 5 deletions
|
@ -102,6 +102,12 @@ type DismissPullReviewOptions struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PullReviewRequestOptions are options to add or remove pull review requests
|
||||||
|
type PullReviewRequestOptions struct {
|
||||||
|
Reviewers []string `json:"reviewers"`
|
||||||
|
TeamReviewers []string `json:"team_reviewers"`
|
||||||
|
}
|
||||||
|
|
||||||
// ListPullReviewsOptions options for listing PullReviews
|
// ListPullReviewsOptions options for listing PullReviews
|
||||||
type ListPullReviewsOptions struct {
|
type ListPullReviewsOptions struct {
|
||||||
ListOptions
|
ListOptions
|
||||||
|
@ -227,6 +233,38 @@ func (c *Client) SubmitPullReview(owner, repo string, index, id int64, opt Submi
|
||||||
return r, resp, err
|
return r, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateReviewRequests create review requests to an pull request
|
||||||
|
func (c *Client) CreateReviewRequests(owner, repo string, index int64, opt PullReviewRequestOptions) (*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/requested_reviewers", owner, repo, index),
|
||||||
|
jsonHeader, bytes.NewReader(body))
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteReviewRequests delete review requests to an pull request
|
||||||
|
func (c *Client) DeleteReviewRequests(owner, repo string, index int64, opt PullReviewRequestOptions) (*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("DELETE",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/pulls/%d/requested_reviewers", owner, repo, index),
|
||||||
|
jsonHeader, bytes.NewReader(body))
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
// DismissPullReview dismiss a review for a pull request
|
// DismissPullReview dismiss a review for a pull request
|
||||||
func (c *Client) DismissPullReview(owner, repo string, index, id int64, opt DismissPullReviewOptions) (*Response, error) {
|
func (c *Client) DismissPullReview(owner, repo string, index, id int64, opt DismissPullReviewOptions) (*Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_14_0); err != nil {
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_14_0); err != nil {
|
||||||
|
|
|
@ -20,8 +20,6 @@ func TestPullReview(t *testing.T) {
|
||||||
if !success {
|
if !success {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer c.AdminDeleteUser(reviewer.UserName)
|
|
||||||
defer c.AdminDeleteUser(submitter.UserName)
|
|
||||||
|
|
||||||
// CreatePullReview
|
// CreatePullReview
|
||||||
r1, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
|
r1, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{
|
||||||
|
@ -64,9 +62,7 @@ func TestPullReview(t *testing.T) {
|
||||||
// ListPullReviews
|
// ListPullReviews
|
||||||
c.SetSudo("")
|
c.SetSudo("")
|
||||||
rl, _, err := c.ListPullReviews(repo.Owner.UserName, repo.Name, pull.Index, ListPullReviewsOptions{})
|
rl, _, err := c.ListPullReviews(repo.Owner.UserName, repo.Name, pull.Index, ListPullReviewsOptions{})
|
||||||
if !assert.NoError(t, err) {
|
assert.NoError(t, err)
|
||||||
return
|
|
||||||
}
|
|
||||||
assert.Len(t, rl, 3)
|
assert.Len(t, rl, 3)
|
||||||
for i := range rl {
|
for i := range rl {
|
||||||
assert.EqualValues(t, pull.HTMLURL, rl[i].HTMLPullURL)
|
assert.EqualValues(t, pull.HTMLURL, rl[i].HTMLPullURL)
|
||||||
|
@ -155,6 +151,34 @@ func TestPullReview(t *testing.T) {
|
||||||
}
|
}
|
||||||
r, _, _ = c.GetPullReview(repo.Owner.UserName, repo.Name, pull.Index, r.ID)
|
r, _, _ = c.GetPullReview(repo.Owner.UserName, repo.Name, pull.Index, r.ID)
|
||||||
assert.False(t, r.Dismissed)
|
assert.False(t, r.Dismissed)
|
||||||
|
|
||||||
|
rl, _, err = c.ListPullReviews(repo.Owner.UserName, repo.Name, pull.Index, ListPullReviewsOptions{})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, rl, 3)
|
||||||
|
|
||||||
|
c.SetSudo(submitter.UserName)
|
||||||
|
resp, err = c.CreateReviewRequests(repo.Owner.UserName, repo.Name, pull.Index, PullReviewRequestOptions{Reviewers: []string{reviewer.UserName}})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, resp)
|
||||||
|
|
||||||
|
rl, _, _ = c.ListPullReviews(repo.Owner.UserName, repo.Name, pull.Index, ListPullReviewsOptions{})
|
||||||
|
if assert.Len(t, rl, 4) {
|
||||||
|
assert.EqualValues(t, ReviewStateRequestReview, rl[3].State)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.SetSudo(reviewer.UserName)
|
||||||
|
resp, err = c.DeleteReviewRequests(repo.Owner.UserName, repo.Name, pull.Index, PullReviewRequestOptions{Reviewers: []string{reviewer.UserName}})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, resp)
|
||||||
|
|
||||||
|
rl, _, _ = c.ListPullReviews(repo.Owner.UserName, repo.Name, pull.Index, ListPullReviewsOptions{})
|
||||||
|
assert.Len(t, rl, 3)
|
||||||
|
|
||||||
|
c.SetSudo("")
|
||||||
|
_, err = c.AdminDeleteUser(reviewer.UserName)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
_, err = c.AdminDeleteUser(submitter.UserName)
|
||||||
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
Loading…
Reference in a new issue