[GITEA] GET /repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments/{comment}

Refs: https://codeberg.org/forgejo/forgejo/issues/2109
This commit is contained in:
Earl Warren 2024-01-11 12:32:18 +01:00
parent 258f156dbe
commit 69fcf26dee
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
4 changed files with 141 additions and 13 deletions

View file

@ -1250,9 +1250,12 @@ func Routes() *web.Route {
Get(repo.GetPullReview).
Delete(reqToken(), repo.DeletePullReview).
Post(reqToken(), bind(api.SubmitPullReviewOptions{}), repo.SubmitPullReview)
m.Combo("/comments").
m.Group("/comments", func() {
m.Combo("").
Get(repo.GetPullReviewComments).
Post(reqToken(), bind(api.CreatePullReviewCommentOptions{}), repo.CreatePullReviewComment)
m.Get("/{comment}", commentAssignment("comment"), repo.GetPullReviewComment)
})
m.Post("/dismissals", reqToken(), bind(api.DismissPullReviewOptions{}), repo.DismissPullReview)
m.Post("/undismissals", reqToken(), repo.UnDismissPullReview)
})

View file

@ -208,6 +208,69 @@ func GetPullReviewComments(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, apiComments)
}
// GetPullReviewComment get a pull review comment
func GetPullReviewComment(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments/{comment} repository repoGetPullReviewComment
// ---
// summary: Get a pull review comment
// produces:
// - application/json
// parameters:
// - name: owner
// in: path
// description: owner of the repo
// type: string
// required: true
// - name: repo
// in: path
// description: name of the repo
// type: string
// required: true
// - name: index
// in: path
// description: index of the pull request
// type: integer
// format: int64
// required: true
// - name: id
// in: path
// description: id of the review
// type: integer
// format: int64
// required: true
// - name: comment
// in: path
// description: id of the comment
// type: integer
// format: int64
// required: true
// responses:
// "200":
// "$ref": "#/responses/PullReviewComment"
// "403":
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
review, _, statusSet := prepareSingleReview(ctx)
if statusSet {
return
}
if err := ctx.Comment.LoadPoster(ctx); err != nil {
ctx.InternalServerError(err)
return
}
apiComment, err := convert.ToPullReviewComment(ctx, review, ctx.Comment, ctx.Doer)
if err != nil {
ctx.InternalServerError(err)
return
}
ctx.JSON(http.StatusOK, apiComment)
}
// CreatePullReviewComments add a new comment to a pull request review
func CreatePullReviewComment(ctx *context.APIContext) {
// swagger:operation POST /repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments repository repoCreatePullReviewComment

View file

@ -11602,6 +11602,69 @@
}
}
},
"/repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments/{comment}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Get a pull review comment",
"operationId": "repoGetPullReviewComment",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "index of the pull request",
"name": "index",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the review",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the comment",
"name": "comment",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"$ref": "#/responses/PullReviewComment"
},
"403": {
"$ref": "#/responses/forbidden"
},
"404": {
"$ref": "#/responses/notFound"
}
}
}
},
"/repos/{owner}/{repo}/pulls/{index}/reviews/{id}/dismissals": {
"post": {
"produces": [

View file

@ -87,6 +87,7 @@ func TestAPIPullReviewCreateComment(t *testing.T) {
}
newCommentBody := "first new line"
var reviewComment api.PullReviewComment
{
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/pulls/%d/reviews/%d/comments", repo.FullName(), pullIssue.Index, review.ID), &api.CreatePullReviewCommentOptions{
@ -95,24 +96,22 @@ func TestAPIPullReviewCreateComment(t *testing.T) {
OldLineNum: reviewLine,
}).AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var reviewComment *api.PullReviewComment
DecodeJSON(t, resp, &reviewComment)
assert.EqualValues(t, review.ID, reviewComment.ReviewID)
assert.EqualValues(t, newCommentBody, reviewComment.Body)
assert.EqualValues(t, reviewLine, reviewComment.OldLineNum)
assert.EqualValues(t, 0, reviewComment.LineNum)
assert.EqualValues(t, path, reviewComment.Path)
}
{
req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/pulls/%d/reviews/%d/comments", repo.FullName(), pullIssue.Index, review.ID).
req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/pulls/%d/reviews/%d/comments/%d", repo.FullName(), pullIssue.Index, review.ID, reviewComment.ID).
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var reviewComments []*api.PullReviewComment
DecodeJSON(t, resp, &reviewComments)
assert.Len(t, reviewComments, 2)
assert.EqualValues(t, existingCommentBody, reviewComments[0].Body)
assert.EqualValues(t, reviewComments[0].OldLineNum, reviewComments[1].OldLineNum)
assert.EqualValues(t, reviewComments[0].LineNum, reviewComments[1].LineNum)
assert.EqualValues(t, newCommentBody, reviewComments[1].Body)
assert.EqualValues(t, path, reviewComments[1].Path)
var comment api.PullReviewComment
DecodeJSON(t, resp, &comment)
assert.EqualValues(t, reviewComment, comment)
}
{