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

Refs: https://codeberg.org/forgejo/forgejo/issues/2109
(cherry picked from commit 69fcf26dee0e6886460b533575f29e5b818bbc17)
(cherry picked from commit 1296f4d115e1441657cfdac53807743a8b7ca6ba)
(cherry picked from commit 119d10d9e277e7f738eba8087ce6cf4905e183e8)
(cherry picked from commit eb5b55b1b7438a40da2462401a95dfdff493b20d)
This commit is contained in:
Earl Warren 2024-01-11 12:32:18 +01:00
parent e658a6a9cd
commit bd1cea3f82
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
4 changed files with 141 additions and 13 deletions

View file

@ -1261,9 +1261,12 @@ func Routes() *web.Route {
Get(repo.GetPullReview). Get(repo.GetPullReview).
Delete(reqToken(), repo.DeletePullReview). Delete(reqToken(), repo.DeletePullReview).
Post(reqToken(), bind(api.SubmitPullReviewOptions{}), repo.SubmitPullReview) Post(reqToken(), bind(api.SubmitPullReviewOptions{}), repo.SubmitPullReview)
m.Combo("/comments"). m.Group("/comments", func() {
m.Combo("").
Get(repo.GetPullReviewComments). Get(repo.GetPullReviewComments).
Post(reqToken(), bind(api.CreatePullReviewCommentOptions{}), repo.CreatePullReviewComment) 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("/dismissals", reqToken(), bind(api.DismissPullReviewOptions{}), repo.DismissPullReview)
m.Post("/undismissals", reqToken(), repo.UnDismissPullReview) m.Post("/undismissals", reqToken(), repo.UnDismissPullReview)
}) })

View file

@ -208,6 +208,69 @@ func GetPullReviewComments(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, apiComments) 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 // CreatePullReviewComments add a new comment to a pull request review
func CreatePullReviewComment(ctx *context.APIContext) { func CreatePullReviewComment(ctx *context.APIContext) {
// swagger:operation POST /repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments repository repoCreatePullReviewComment // swagger:operation POST /repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments repository repoCreatePullReviewComment

View file

@ -11605,6 +11605,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": { "/repos/{owner}/{repo}/pulls/{index}/reviews/{id}/dismissals": {
"post": { "post": {
"produces": [ "produces": [

View file

@ -68,6 +68,7 @@ func TestAPIPullReviewCreateComment(t *testing.T) {
} }
newCommentBody := "first new line" 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{ req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/pulls/%d/reviews/%d/comments", repo.FullName(), pullIssue.Index, review.ID), &api.CreatePullReviewCommentOptions{
@ -76,24 +77,22 @@ func TestAPIPullReviewCreateComment(t *testing.T) {
OldLineNum: reviewLine, OldLineNum: reviewLine,
}).AddTokenAuth(token) }).AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var reviewComment *api.PullReviewComment
DecodeJSON(t, resp, &reviewComment) DecodeJSON(t, resp, &reviewComment)
assert.EqualValues(t, review.ID, reviewComment.ReviewID) 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) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var reviewComments []*api.PullReviewComment var comment api.PullReviewComment
DecodeJSON(t, resp, &reviewComments) DecodeJSON(t, resp, &comment)
assert.Len(t, reviewComments, 2) assert.EqualValues(t, reviewComment, comment)
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)
} }
{ {