-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add review request api #11355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
techknowlogick
merged 33 commits into
go-gitea:master
from
a1012112796:review_request_api
Oct 20, 2020
Merged
Add review request api #11355
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
d957b8f
Add review request api
a1012112796 b5c8f0a
Merge branch 'master' into review_request_api
a1012112796 7f877a3
make fmt
a1012112796 67ee5f2
Merge branch 'master' into review_request_api
a1012112796 1da62b1
fix bug
a1012112796 b69744d
fix test code
a1012112796 1f4eb57
fix typo
a1012112796 266c1c9
Merge branch 'master' into review_request_api
a1012112796 5ff74bd
Apply suggestion from code review @jonasfranz
a1012112796 233a446
Merge branch 'master' into review_request_api
a1012112796 59304f2
fix swagger ref
a1012112796 0c10a4d
fix typo
a1012112796 58ddaf6
Merge branch 'master' into review_request_api
a1012112796 ab85502
fix comment
a1012112796 28cdcd6
Merge branch 'master' into review_request_api
a1012112796 66498af
Change response message
a1012112796 c4c9817
Merge branch 'master' into review_request_api
a1012112796 a835527
Merge branch 'master' into review_request_api
a1012112796 b283e6f
chang response so some simplfy
a1012112796 8350955
Merge branch 'master' into review_request_api
a1012112796 dd21972
Add ErrIllLegalReviewRequest
a1012112796 d4e28c7
Merge branch 'master' into review_request_api
a1012112796 491a197
make fmt
a1012112796 49f8a4e
Apply suggestions from code review
a1012112796 6f989b2
Merge branch 'master' into review_request_api
a1012112796 c1b39aa
* Add team support
a1012112796 4ccc8a7
fix nit
a1012112796 ef9246d
fix test
a1012112796 134d8d0
Merge branch 'master' into review_request_api
a1012112796 0d85842
Apply suggestions from code review
a1012112796 9127291
Merge branch 'master' into review_request_api
zeripath 551fe18
update get api and add test
a1012112796 415dde7
Merge remote-tracking branch 'master' into review_request_api
a1012112796 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.