-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add review request api * add : POST /repos/{owner}/{repo}/pulls/{index}/requested_reviewers * Remove : DELET /repos/{owner}/{repo}/pulls/{index}/requested_reviewers * fix some request review bug * block delet request review by models/DeleteReview() Signed-off-by: a1012112796 <[email protected]> * make fmt * fix bug * fix test code * fix typo * Apply suggestion from code review @jonasfranz * fix swagger ref * fix typo Co-authored-by: Lauris BH <[email protected]> * fix comment * Change response message * chang response so some simplfy * Add ErrIllLegalReviewRequest fix some nits * make fmt * Apply suggestions from code review Co-authored-by: silverwind <[email protected]> * * Add team support * fix test * fix an known bug * fix nit * fix test * Apply suggestions from code review Co-authored-by: zeripath <[email protected]> * update get api and add test Co-authored-by: Lauris BH <[email protected]> Co-authored-by: silverwind <[email protected]> Co-authored-by: zeripath <[email protected]>
- Loading branch information
1 parent
b50448b
commit b985037
Showing
21 changed files
with
694 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,4 +122,110 @@ func TestAPIPullReview(t *testing.T) { | |
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) | ||
resp = session.MakeRequest(t, req, http.StatusNoContent) | ||
|
||
// test get review requests | ||
// to make it simple, use same api with get review | ||
pullIssue12 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 12}).(*models.Issue) | ||
assert.NoError(t, pullIssue12.LoadAttributes()) | ||
repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue12.RepoID}).(*models.Repository) | ||
|
||
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token) | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
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) | ||
assert.EqualValues(t, false, reviews[0].Stale) | ||
assert.EqualValues(t, true, reviews[0].Official) | ||
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) | ||
assert.EqualValues(t, false, reviews[1].Stale) | ||
assert.EqualValues(t, true, reviews[1].Official) | ||
assert.EqualValues(t, 1, reviews[1].Reviewer.ID) | ||
} | ||
|
||
func TestAPIPullReviewRequest(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
pullIssue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue) | ||
assert.NoError(t, pullIssue.LoadAttributes()) | ||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.RepoID}).(*models.Repository) | ||
|
||
// Test add Review Request | ||
session := loginUser(t, "user2") | ||
token := getTokenForLoggedInUser(t, session) | ||
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{"[email protected]", "user8"}, | ||
}) | ||
session.MakeRequest(t, req, http.StatusCreated) | ||
|
||
// 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"}, | ||
}) | ||
session.MakeRequest(t, req, http.StatusUnprocessableEntity) | ||
|
||
// 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"}, | ||
}) | ||
session.MakeRequest(t, req, http.StatusNotFound) | ||
|
||
// Test Remove Review Request | ||
session2 := loginUser(t, "user4") | ||
token2 := getTokenForLoggedInUser(t, session2) | ||
|
||
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"}, | ||
}) | ||
session.MakeRequest(t, req, http.StatusNoContent) | ||
|
||
// 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"}, | ||
}) | ||
session.MakeRequest(t, req, http.StatusUnprocessableEntity) | ||
|
||
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"}, | ||
}) | ||
session.MakeRequest(t, req, http.StatusNoContent) | ||
|
||
// Test team review request | ||
pullIssue12 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 12}).(*models.Issue) | ||
assert.NoError(t, pullIssue12.LoadAttributes()) | ||
repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue12.RepoID}).(*models.Repository) | ||
|
||
// 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"}, | ||
}) | ||
session.MakeRequest(t, req, http.StatusCreated) | ||
|
||
// 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"}, | ||
}) | ||
session.MakeRequest(t, req, http.StatusUnprocessableEntity) | ||
|
||
// 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"}, | ||
}) | ||
session.MakeRequest(t, req, http.StatusNotFound) | ||
|
||
// 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"}, | ||
}) | ||
session.MakeRequest(t, req, http.StatusNoContent) | ||
|
||
// 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{}) | ||
session.MakeRequest(t, req, http.StatusCreated) | ||
|
||
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{}) | ||
session.MakeRequest(t, req, http.StatusNoContent) | ||
} |
Binary file added
BIN
+814 Bytes
...gitea-repositories-meta/user3/repo3.git/objects/d2/2b4d4daa5be07329fcef6ed458f00cf3392da0
Binary file not shown.
Binary file added
BIN
+62 Bytes
...gitea-repositories-meta/user3/repo3.git/objects/ec/f0db3c1ec806522de4b491fb9a3c7457398c61
Binary file not shown.
Binary file added
BIN
+84 Bytes
...gitea-repositories-meta/user3/repo3.git/objects/ee/16d127df463aa491e08958120f2108b02468df
Binary file not shown.
1 change: 1 addition & 0 deletions
1
integrations/gitea-repositories-meta/user3/repo3.git/refs/heads/test_branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
d22b4d4daa5be07329fcef6ed458f00cf3392da0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.