forked from NYANDEV/forgejo
Backport #27483 by @msantos Fixes https://github.com/go-gitea/gitea/issues/27481 --- Patch tested: ```json [ { "url": "7664dcb441
", "sha": "7664dcb44167e0f9efd994e4ca6a9164694adc27", "created": "2023-10-06T09:57:08-04:00", "html_url": "7664dcb441
", ... "files": [ { "filename": "README.md", "status": "modified" } ], "stats": { "total": 2, "additions": 2, "deletions": 0 } } ] ``` Co-authored-by: Michael Santos <michael.santos@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
a1ee172fb0
commit
4c9f7d0710
5 changed files with 65 additions and 2 deletions
|
@ -36,6 +36,14 @@ func GetNote(ctx *context.APIContext) {
|
||||||
// description: a git ref or commit sha
|
// description: a git ref or commit sha
|
||||||
// type: string
|
// type: string
|
||||||
// required: true
|
// required: true
|
||||||
|
// - name: verification
|
||||||
|
// in: query
|
||||||
|
// description: include verification for every commit (disable for speedup, default 'true')
|
||||||
|
// type: boolean
|
||||||
|
// - name: files
|
||||||
|
// in: query
|
||||||
|
// description: include a list of affected files for every commit (disable for speedup, default 'true')
|
||||||
|
// type: boolean
|
||||||
// responses:
|
// responses:
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/Note"
|
// "$ref": "#/responses/Note"
|
||||||
|
@ -78,7 +86,15 @@ func getNote(ctx *context.APIContext, identifier string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil, convert.ToCommitOptions{Stat: true})
|
verification := ctx.FormString("verification") == "" || ctx.FormBool("verification")
|
||||||
|
files := ctx.FormString("files") == "" || ctx.FormBool("files")
|
||||||
|
|
||||||
|
cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil,
|
||||||
|
convert.ToCommitOptions{
|
||||||
|
Stat: true,
|
||||||
|
Verification: verification,
|
||||||
|
Files: files,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ToCommit", err)
|
ctx.Error(http.StatusInternalServerError, "ToCommit", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -1269,6 +1269,14 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
||||||
// in: query
|
// in: query
|
||||||
// description: page size of results
|
// description: page size of results
|
||||||
// type: integer
|
// type: integer
|
||||||
|
// - name: verification
|
||||||
|
// in: query
|
||||||
|
// description: include verification for every commit (disable for speedup, default 'true')
|
||||||
|
// type: boolean
|
||||||
|
// - name: files
|
||||||
|
// in: query
|
||||||
|
// description: include a list of affected files for every commit (disable for speedup, default 'true')
|
||||||
|
// type: boolean
|
||||||
// responses:
|
// responses:
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/CommitList"
|
// "$ref": "#/responses/CommitList"
|
||||||
|
@ -1322,9 +1330,17 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
||||||
end = totalNumberOfCommits
|
end = totalNumberOfCommits
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verification := ctx.FormString("verification") == "" || ctx.FormBool("verification")
|
||||||
|
files := ctx.FormString("files") == "" || ctx.FormBool("files")
|
||||||
|
|
||||||
apiCommits := make([]*api.Commit, 0, end-start)
|
apiCommits := make([]*api.Commit, 0, end-start)
|
||||||
for i := start; i < end; i++ {
|
for i := start; i < end; i++ {
|
||||||
apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, convert.ToCommitOptions{Stat: true})
|
apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache,
|
||||||
|
convert.ToCommitOptions{
|
||||||
|
Stat: true,
|
||||||
|
Verification: verification,
|
||||||
|
Files: files,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("toCommit", err)
|
ctx.ServerError("toCommit", err)
|
||||||
return
|
return
|
||||||
|
|
24
templates/swagger/v1_json.tmpl
generated
24
templates/swagger/v1_json.tmpl
generated
|
@ -5212,6 +5212,18 @@
|
||||||
"name": "sha",
|
"name": "sha",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "include verification for every commit (disable for speedup, default 'true')",
|
||||||
|
"name": "verification",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "include a list of affected files for every commit (disable for speedup, default 'true')",
|
||||||
|
"name": "files",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
@ -10458,6 +10470,18 @@
|
||||||
"description": "page size of results",
|
"description": "page size of results",
|
||||||
"name": "limit",
|
"name": "limit",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "include verification for every commit (disable for speedup, default 'true')",
|
||||||
|
"name": "verification",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "include a list of affected files for every commit (disable for speedup, default 'true')",
|
||||||
|
"name": "files",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|
|
@ -35,6 +35,11 @@ func TestAPIPullCommits(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, "5f22f7d0d95d614d25a5b68592adb345a4b5c7fd", commits[0].SHA)
|
assert.Equal(t, "5f22f7d0d95d614d25a5b68592adb345a4b5c7fd", commits[0].SHA)
|
||||||
assert.Equal(t, "4a357436d925b5c974181ff12a994538ddc5a269", commits[1].SHA)
|
assert.Equal(t, "4a357436d925b5c974181ff12a994538ddc5a269", commits[1].SHA)
|
||||||
|
|
||||||
|
assert.NotEmpty(t, commits[0].Files)
|
||||||
|
assert.NotEmpty(t, commits[1].Files)
|
||||||
|
assert.NotNil(t, commits[0].RepoCommit.Verification)
|
||||||
|
assert.NotNil(t, commits[1].RepoCommit.Verification)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add tests for already merged PR and closed PR
|
// TODO add tests for already merged PR and closed PR
|
||||||
|
|
|
@ -37,5 +37,7 @@ func TestAPIReposGitNotes(t *testing.T) {
|
||||||
var apiData api.Note
|
var apiData api.Note
|
||||||
DecodeJSON(t, resp, &apiData)
|
DecodeJSON(t, resp, &apiData)
|
||||||
assert.Equal(t, "This is a test note\n", apiData.Message)
|
assert.Equal(t, "This is a test note\n", apiData.Message)
|
||||||
|
assert.NotEmpty(t, apiData.Commit.Files)
|
||||||
|
assert.NotNil(t, apiData.Commit.RepoCommit.Verification)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue