2020-05-02 05:50:51 +05:30
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-02 05:50:51 +05:30
|
|
|
|
2022-09-03 00:48:23 +05:30
|
|
|
package integration
|
2020-05-02 05:50:51 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2023-01-18 03:16:03 +05:30
|
|
|
auth_model "code.gitea.io/gitea/models/auth"
|
2022-06-13 15:07:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-12-10 06:57:50 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-16 14:23:21 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-07-24 21:33:58 +05:30
|
|
|
"code.gitea.io/gitea/modules/json"
|
2020-05-02 05:50:51 +05:30
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2022-09-03 00:48:23 +05:30
|
|
|
"code.gitea.io/gitea/tests"
|
2021-07-24 21:33:58 +05:30
|
|
|
|
2020-05-02 05:50:51 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIPullReview(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-08-16 07:52:25 +05:30
|
|
|
pullIssue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 3})
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.NoError(t, pullIssue.LoadAttributes(db.DefaultContext))
|
2022-08-16 07:52:25 +05:30
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue.RepoID})
|
2020-05-02 05:50:51 +05:30
|
|
|
|
|
|
|
// test ListPullReviews
|
|
|
|
session := loginUser(t, "user2")
|
2023-01-18 03:16:03 +05:30
|
|
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
|
2020-05-02 05:50:51 +05:30
|
|
|
req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token)
|
2022-12-02 09:09:42 +05:30
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
2020-05-02 05:50:51 +05:30
|
|
|
|
|
|
|
var reviews []*api.PullReview
|
|
|
|
DecodeJSON(t, resp, &reviews)
|
|
|
|
if !assert.Len(t, reviews, 6) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, r := range reviews {
|
|
|
|
assert.EqualValues(t, pullIssue.HTMLURL(), r.HTMLPullURL)
|
|
|
|
}
|
|
|
|
assert.EqualValues(t, 8, reviews[3].ID)
|
|
|
|
assert.EqualValues(t, "APPROVED", reviews[3].State)
|
|
|
|
assert.EqualValues(t, 0, reviews[3].CodeCommentsCount)
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.True(t, reviews[3].Stale)
|
|
|
|
assert.False(t, reviews[3].Official)
|
2020-05-02 05:50:51 +05:30
|
|
|
|
|
|
|
assert.EqualValues(t, 10, reviews[5].ID)
|
|
|
|
assert.EqualValues(t, "REQUEST_CHANGES", reviews[5].State)
|
|
|
|
assert.EqualValues(t, 1, reviews[5].CodeCommentsCount)
|
2020-09-18 03:03:23 +05:30
|
|
|
assert.EqualValues(t, -1, reviews[5].Reviewer.ID) // ghost user
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.False(t, reviews[5].Stale)
|
|
|
|
assert.True(t, reviews[5].Official)
|
2020-05-02 05:50:51 +05:30
|
|
|
|
|
|
|
// test GetPullReview
|
|
|
|
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, reviews[3].ID, token)
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2020-05-02 05:50:51 +05:30
|
|
|
var review api.PullReview
|
|
|
|
DecodeJSON(t, resp, &review)
|
|
|
|
assert.EqualValues(t, *reviews[3], review)
|
|
|
|
|
|
|
|
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls/%d/reviews/%d?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, reviews[5].ID, token)
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2020-05-02 05:50:51 +05:30
|
|
|
DecodeJSON(t, resp, &review)
|
|
|
|
assert.EqualValues(t, *reviews[5], review)
|
|
|
|
|
|
|
|
// test GetPullReviewComments
|
2022-08-16 07:52:25 +05:30
|
|
|
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 7})
|
2020-05-02 05:50:51 +05:30
|
|
|
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d/comments?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, 10, token)
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2020-05-02 05:50:51 +05:30
|
|
|
var reviewComments []*api.PullReviewComment
|
|
|
|
DecodeJSON(t, resp, &reviewComments)
|
|
|
|
assert.Len(t, reviewComments, 1)
|
2021-03-28 05:07:51 +05:30
|
|
|
assert.EqualValues(t, "Ghost", reviewComments[0].Poster.UserName)
|
2020-05-02 05:50:51 +05:30
|
|
|
assert.EqualValues(t, "a review from a deleted user", reviewComments[0].Body)
|
|
|
|
assert.EqualValues(t, comment.ID, reviewComments[0].ID)
|
|
|
|
assert.EqualValues(t, comment.UpdatedUnix, reviewComments[0].Updated.Unix())
|
|
|
|
assert.EqualValues(t, comment.HTMLURL(), reviewComments[0].HTMLURL)
|
|
|
|
|
|
|
|
// test CreatePullReview
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{
|
|
|
|
Body: "body1",
|
|
|
|
// Event: "" # will result in PENDING
|
2022-01-20 23:16:10 +05:30
|
|
|
Comments: []api.CreatePullReviewComment{
|
|
|
|
{
|
|
|
|
Path: "README.md",
|
|
|
|
Body: "first new line",
|
|
|
|
OldLineNum: 0,
|
|
|
|
NewLineNum: 1,
|
|
|
|
}, {
|
|
|
|
Path: "README.md",
|
|
|
|
Body: "first old line",
|
|
|
|
OldLineNum: 1,
|
|
|
|
NewLineNum: 0,
|
|
|
|
}, {
|
|
|
|
Path: "iso-8859-1.txt",
|
|
|
|
Body: "this line contains a non-utf-8 character",
|
|
|
|
OldLineNum: 0,
|
|
|
|
NewLineNum: 1,
|
|
|
|
},
|
2020-05-02 05:50:51 +05:30
|
|
|
},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2020-05-02 05:50:51 +05:30
|
|
|
DecodeJSON(t, resp, &review)
|
|
|
|
assert.EqualValues(t, 6, review.ID)
|
|
|
|
assert.EqualValues(t, "PENDING", review.State)
|
2020-06-18 19:37:09 +05:30
|
|
|
assert.EqualValues(t, 3, review.CodeCommentsCount)
|
2020-05-02 05:50:51 +05:30
|
|
|
|
|
|
|
// test SubmitPullReview
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token), &api.SubmitPullReviewOptions{
|
|
|
|
Event: "APPROVED",
|
|
|
|
Body: "just two nits",
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2020-05-02 05:50:51 +05:30
|
|
|
DecodeJSON(t, resp, &review)
|
|
|
|
assert.EqualValues(t, 6, review.ID)
|
|
|
|
assert.EqualValues(t, "APPROVED", review.State)
|
2020-06-18 19:37:09 +05:30
|
|
|
assert.EqualValues(t, 3, review.CodeCommentsCount)
|
2020-05-02 05:50:51 +05:30
|
|
|
|
2021-02-11 23:02:25 +05:30
|
|
|
// test dismiss review
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d/dismissals?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token), &api.DismissPullReviewOptions{
|
|
|
|
Message: "test",
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2021-02-11 23:02:25 +05:30
|
|
|
DecodeJSON(t, resp, &review)
|
|
|
|
assert.EqualValues(t, 6, review.ID)
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.True(t, review.Dismissed)
|
2021-02-11 23:02:25 +05:30
|
|
|
|
|
|
|
// test dismiss review
|
|
|
|
req = NewRequest(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d/undismissals?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token))
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2021-02-11 23:02:25 +05:30
|
|
|
DecodeJSON(t, resp, &review)
|
|
|
|
assert.EqualValues(t, 6, review.ID)
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.False(t, review.Dismissed)
|
2021-02-11 23:02:25 +05:30
|
|
|
|
2020-05-02 05:50:51 +05:30
|
|
|
// test DeletePullReview
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{
|
|
|
|
Body: "just a comment",
|
|
|
|
Event: "COMMENT",
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2020-05-02 05:50:51 +05:30
|
|
|
DecodeJSON(t, resp, &review)
|
|
|
|
assert.EqualValues(t, "COMMENT", review.State)
|
|
|
|
assert.EqualValues(t, 0, review.CodeCommentsCount)
|
|
|
|
req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token)
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusNoContent)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
2021-06-25 03:35:51 +05:30
|
|
|
// test CreatePullReview Comment without body but with comments
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{
|
|
|
|
// Body: "",
|
|
|
|
Event: "COMMENT",
|
2022-01-20 23:16:10 +05:30
|
|
|
Comments: []api.CreatePullReviewComment{
|
|
|
|
{
|
|
|
|
Path: "README.md",
|
|
|
|
Body: "first new line",
|
|
|
|
OldLineNum: 0,
|
|
|
|
NewLineNum: 1,
|
|
|
|
}, {
|
|
|
|
Path: "README.md",
|
|
|
|
Body: "first old line",
|
|
|
|
OldLineNum: 1,
|
|
|
|
NewLineNum: 0,
|
|
|
|
},
|
2021-06-25 03:35:51 +05:30
|
|
|
},
|
|
|
|
})
|
|
|
|
var commentReview api.PullReview
|
|
|
|
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2021-06-25 03:35:51 +05:30
|
|
|
DecodeJSON(t, resp, &commentReview)
|
|
|
|
assert.EqualValues(t, "COMMENT", commentReview.State)
|
|
|
|
assert.EqualValues(t, 2, commentReview.CodeCommentsCount)
|
|
|
|
assert.EqualValues(t, "", commentReview.Body)
|
|
|
|
assert.EqualValues(t, false, commentReview.Dismissed)
|
|
|
|
|
|
|
|
// test CreatePullReview Comment with body but without comments
|
|
|
|
commentBody := "This is a body of the comment."
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{
|
|
|
|
Body: commentBody,
|
|
|
|
Event: "COMMENT",
|
|
|
|
Comments: []api.CreatePullReviewComment{},
|
|
|
|
})
|
|
|
|
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2021-06-25 03:35:51 +05:30
|
|
|
DecodeJSON(t, resp, &commentReview)
|
|
|
|
assert.EqualValues(t, "COMMENT", commentReview.State)
|
|
|
|
assert.EqualValues(t, 0, commentReview.CodeCommentsCount)
|
|
|
|
assert.EqualValues(t, commentBody, commentReview.Body)
|
|
|
|
assert.EqualValues(t, false, commentReview.Dismissed)
|
|
|
|
|
|
|
|
// test CreatePullReview Comment without body and no comments
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{
|
|
|
|
Body: "",
|
|
|
|
Event: "COMMENT",
|
|
|
|
Comments: []api.CreatePullReviewComment{},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusUnprocessableEntity)
|
2021-06-25 03:35:51 +05:30
|
|
|
errMap := make(map[string]interface{})
|
|
|
|
json.Unmarshal(resp.Body.Bytes(), &errMap)
|
|
|
|
assert.EqualValues(t, "review event COMMENT requires a body or a comment", errMap["message"].(string))
|
|
|
|
|
2020-10-20 23:48:25 +05:30
|
|
|
// test get review requests
|
|
|
|
// to make it simple, use same api with get review
|
2022-08-16 07:52:25 +05:30
|
|
|
pullIssue12 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 12})
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.NoError(t, pullIssue12.LoadAttributes(db.DefaultContext))
|
2022-08-16 07:52:25 +05:30
|
|
|
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID})
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token)
|
2022-12-02 09:09:42 +05:30
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
2020-10-20 23:48:25 +05:30
|
|
|
DecodeJSON(t, resp, &reviews)
|
|
|
|
assert.EqualValues(t, 11, reviews[0].ID)
|
|
|
|
assert.EqualValues(t, "REQUEST_REVIEW", reviews[0].State)
|
|
|
|
assert.EqualValues(t, 0, reviews[0].CodeCommentsCount)
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.False(t, reviews[0].Stale)
|
|
|
|
assert.True(t, reviews[0].Official)
|
2020-10-20 23:48:25 +05:30
|
|
|
assert.EqualValues(t, "test_team", reviews[0].ReviewerTeam.Name)
|
|
|
|
|
|
|
|
assert.EqualValues(t, 12, reviews[1].ID)
|
|
|
|
assert.EqualValues(t, "REQUEST_REVIEW", reviews[1].State)
|
|
|
|
assert.EqualValues(t, 0, reviews[0].CodeCommentsCount)
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.False(t, reviews[1].Stale)
|
|
|
|
assert.True(t, reviews[1].Official)
|
2020-10-20 23:48:25 +05:30
|
|
|
assert.EqualValues(t, 1, reviews[1].Reviewer.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPIPullReviewRequest(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-08-16 07:52:25 +05:30
|
|
|
pullIssue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 3})
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.NoError(t, pullIssue.LoadAttributes(db.DefaultContext))
|
2022-08-16 07:52:25 +05:30
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue.RepoID})
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// Test add Review Request
|
|
|
|
session := loginUser(t, "user2")
|
2023-01-18 03:16:03 +05:30
|
|
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
|
2020-10-20 23:48:25 +05:30
|
|
|
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.PullReviewRequestOptions{
|
|
|
|
Reviewers: []string{"user4@example.com", "user8"},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusCreated)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// poster of pr can't be reviewer
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.PullReviewRequestOptions{
|
|
|
|
Reviewers: []string{"user1"},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusUnprocessableEntity)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// test user not exist
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.PullReviewRequestOptions{
|
|
|
|
Reviewers: []string{"testOther"},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusNotFound)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// Test Remove Review Request
|
|
|
|
session2 := loginUser(t, "user4")
|
2023-01-18 03:16:03 +05:30
|
|
|
token2 := getTokenForLoggedInUser(t, session2, auth_model.AccessTokenScopeRepo)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token2), &api.PullReviewRequestOptions{
|
|
|
|
Reviewers: []string{"user4"},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusNoContent)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// doer is not admin
|
|
|
|
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token2), &api.PullReviewRequestOptions{
|
|
|
|
Reviewers: []string{"user8"},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusUnprocessableEntity)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.PullReviewRequestOptions{
|
|
|
|
Reviewers: []string{"user8"},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusNoContent)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// Test team review request
|
2022-08-16 07:52:25 +05:30
|
|
|
pullIssue12 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 12})
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.NoError(t, pullIssue12.LoadAttributes(db.DefaultContext))
|
2022-08-16 07:52:25 +05:30
|
|
|
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID})
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// Test add Team Review Request
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{
|
|
|
|
TeamReviewers: []string{"team1", "owners"},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusCreated)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// Test add Team Review Request to not allowned
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{
|
|
|
|
TeamReviewers: []string{"test_team"},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusUnprocessableEntity)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// Test add Team Review Request to not exist
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{
|
|
|
|
TeamReviewers: []string{"not_exist_team"},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusNotFound)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// Test Remove team Review Request
|
|
|
|
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{
|
|
|
|
TeamReviewers: []string{"team1"},
|
|
|
|
})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusNoContent)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
// empty request test
|
|
|
|
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusCreated)
|
2020-10-20 23:48:25 +05:30
|
|
|
|
|
|
|
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{})
|
2022-12-02 09:09:42 +05:30
|
|
|
MakeRequest(t, req, http.StatusNoContent)
|
2020-05-02 05:50:51 +05:30
|
|
|
}
|