Skip to content

Commit 4c9f7d0

Browse files
GiteaBotmsantossilverwindwxiaoguang
authored
api: GetPullRequestCommits: return file list (go-gitea#27483) (go-gitea#27539)
Backport go-gitea#27483 by @msantos Fixes go-gitea#27481 --- Patch tested: ```json [ { "url": "http://100.115.92.198:9292/api/v1/repos/msantos/test/git/commits/7664dcb44167e0f9efd994e4ca6a9164694adc27", "sha": "7664dcb44167e0f9efd994e4ca6a9164694adc27", "created": "2023-10-06T09:57:08-04:00", "html_url": "http://100.115.92.198:9292/msantos/test/commit/7664dcb44167e0f9efd994e4ca6a9164694adc27", ... "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>
1 parent a1ee172 commit 4c9f7d0

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

routers/api/v1/repo/notes.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ func GetNote(ctx *context.APIContext) {
3636
// description: a git ref or commit sha
3737
// type: string
3838
// required: true
39+
// - name: verification
40+
// in: query
41+
// description: include verification for every commit (disable for speedup, default 'true')
42+
// type: boolean
43+
// - name: files
44+
// in: query
45+
// description: include a list of affected files for every commit (disable for speedup, default 'true')
46+
// type: boolean
3947
// responses:
4048
// "200":
4149
// "$ref": "#/responses/Note"
@@ -78,7 +86,15 @@ func getNote(ctx *context.APIContext, identifier string) {
7886
return
7987
}
8088

81-
cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil, convert.ToCommitOptions{Stat: true})
89+
verification := ctx.FormString("verification") == "" || ctx.FormBool("verification")
90+
files := ctx.FormString("files") == "" || ctx.FormBool("files")
91+
92+
cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil,
93+
convert.ToCommitOptions{
94+
Stat: true,
95+
Verification: verification,
96+
Files: files,
97+
})
8298
if err != nil {
8399
ctx.Error(http.StatusInternalServerError, "ToCommit", err)
84100
return

routers/api/v1/repo/pull.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,14 @@ func GetPullRequestCommits(ctx *context.APIContext) {
12691269
// in: query
12701270
// description: page size of results
12711271
// type: integer
1272+
// - name: verification
1273+
// in: query
1274+
// description: include verification for every commit (disable for speedup, default 'true')
1275+
// type: boolean
1276+
// - name: files
1277+
// in: query
1278+
// description: include a list of affected files for every commit (disable for speedup, default 'true')
1279+
// type: boolean
12721280
// responses:
12731281
// "200":
12741282
// "$ref": "#/responses/CommitList"
@@ -1322,9 +1330,17 @@ func GetPullRequestCommits(ctx *context.APIContext) {
13221330
end = totalNumberOfCommits
13231331
}
13241332

1333+
verification := ctx.FormString("verification") == "" || ctx.FormBool("verification")
1334+
files := ctx.FormString("files") == "" || ctx.FormBool("files")
1335+
13251336
apiCommits := make([]*api.Commit, 0, end-start)
13261337
for i := start; i < end; i++ {
1327-
apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, convert.ToCommitOptions{Stat: true})
1338+
apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache,
1339+
convert.ToCommitOptions{
1340+
Stat: true,
1341+
Verification: verification,
1342+
Files: files,
1343+
})
13281344
if err != nil {
13291345
ctx.ServerError("toCommit", err)
13301346
return

templates/swagger/v1_json.tmpl

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/api_pull_commits_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ func TestAPIPullCommits(t *testing.T) {
3535

3636
assert.Equal(t, "5f22f7d0d95d614d25a5b68592adb345a4b5c7fd", commits[0].SHA)
3737
assert.Equal(t, "4a357436d925b5c974181ff12a994538ddc5a269", commits[1].SHA)
38+
39+
assert.NotEmpty(t, commits[0].Files)
40+
assert.NotEmpty(t, commits[1].Files)
41+
assert.NotNil(t, commits[0].RepoCommit.Verification)
42+
assert.NotNil(t, commits[1].RepoCommit.Verification)
3843
}
3944

4045
// TODO add tests for already merged PR and closed PR

tests/integration/api_repo_git_notes_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ func TestAPIReposGitNotes(t *testing.T) {
3737
var apiData api.Note
3838
DecodeJSON(t, resp, &apiData)
3939
assert.Equal(t, "This is a test note\n", apiData.Message)
40+
assert.NotEmpty(t, apiData.Commit.Files)
41+
assert.NotNil(t, apiData.Commit.RepoCommit.Verification)
4042
})
4143
}

0 commit comments

Comments
 (0)