From c47c44e83b42d174a91a70f5689cd5ad6b5ad573 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Fri, 6 Oct 2023 10:02:27 -0400 Subject: [PATCH 1/5] api: GetPullRequestCommits: return file list Fixes https://github.com/go-gitea/gitea/issues/27481 --- routers/api/v1/repo/pull.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 586f3385b1883..3bd2703e2ad23 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1330,7 +1330,7 @@ func GetPullRequestCommits(ctx *context.APIContext) { apiCommits := make([]*api.Commit, 0, end-start) 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, Files: true}) if err != nil { ctx.ServerError("toCommit", err) return From 6ee08bc2e2fc92ea8573ab76455fdbca4b469464 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Fri, 6 Oct 2023 15:48:13 -0400 Subject: [PATCH 2/5] TestAPIPullCommits: check request returns file list --- tests/integration/api_pull_commits_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/integration/api_pull_commits_test.go b/tests/integration/api_pull_commits_test.go index 0bcfb906845a4..b0a242927713d 100644 --- a/tests/integration/api_pull_commits_test.go +++ b/tests/integration/api_pull_commits_test.go @@ -35,6 +35,9 @@ func TestAPIPullCommits(t *testing.T) { assert.Equal(t, "5f22f7d0d95d614d25a5b68592adb345a4b5c7fd", commits[0].SHA) assert.Equal(t, "4a357436d925b5c974181ff12a994538ddc5a269", commits[1].SHA) + + assert.NotEmpty(t, commits[0].Files) + assert.NotEmpty(t, commits[1].Files) } // TODO add tests for already merged PR and closed PR From a7f4d338dce92fcd0780b726d54d9dd193f01097 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Sat, 7 Oct 2023 10:21:46 -0400 Subject: [PATCH 3/5] api: pull/notes: optionally disable fields Update the pulls and notes endpoints: * reenable returning files and verification * optionally disable using a parameter --- routers/api/v1/repo/notes.go | 10 +++++++++- routers/api/v1/repo/pull.go | 10 +++++++++- tests/integration/api_pull_commits_test.go | 2 ++ tests/integration/api_repo_git_notes_test.go | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/repo/notes.go b/routers/api/v1/repo/notes.go index 1bd66101f0d68..ce11c3f9a6453 100644 --- a/routers/api/v1/repo/notes.go +++ b/routers/api/v1/repo/notes.go @@ -78,7 +78,15 @@ func getNote(ctx *context.APIContext, identifier string) { 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 { ctx.Error(http.StatusInternalServerError, "ToCommit", err) return diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 3bd2703e2ad23..0c25b169e48e7 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1328,9 +1328,17 @@ func GetPullRequestCommits(ctx *context.APIContext) { end = totalNumberOfCommits } + verification := ctx.FormString("verification") == "" || ctx.FormBool("verification") + files := ctx.FormString("files") == "" || ctx.FormBool("files") + apiCommits := make([]*api.Commit, 0, end-start) for i := start; i < end; i++ { - apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, convert.ToCommitOptions{Stat: true, Files: true}) + apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, + convert.ToCommitOptions{ + Stat: true, + Verification: verification, + Files: files, + }) if err != nil { ctx.ServerError("toCommit", err) return diff --git a/tests/integration/api_pull_commits_test.go b/tests/integration/api_pull_commits_test.go index b0a242927713d..ad0cb0329ccd9 100644 --- a/tests/integration/api_pull_commits_test.go +++ b/tests/integration/api_pull_commits_test.go @@ -38,6 +38,8 @@ func TestAPIPullCommits(t *testing.T) { 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 diff --git a/tests/integration/api_repo_git_notes_test.go b/tests/integration/api_repo_git_notes_test.go index 30846f235fd78..a7327d932748f 100644 --- a/tests/integration/api_repo_git_notes_test.go +++ b/tests/integration/api_repo_git_notes_test.go @@ -37,5 +37,7 @@ func TestAPIReposGitNotes(t *testing.T) { var apiData api.Note DecodeJSON(t, resp, &apiData) assert.Equal(t, "This is a test note\n", apiData.Message) + assert.NotEmpty(t, apiData.Commit.Files) + assert.NotNil(t, apiData.Commit.RepoCommit.Verification) }) } From 7efc24793b820ec759fe68168263147a33ecb052 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Sun, 8 Oct 2023 07:30:07 -0400 Subject: [PATCH 4/5] doc: notes/pull: add endpoint parameters Endpoint parameter docs updated using https://github.com/go-gitea/gitea/commit/1dd83dbb917d55bd253001646d6743f247a4d98b --- routers/api/v1/repo/notes.go | 8 ++++++++ routers/api/v1/repo/pull.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/routers/api/v1/repo/notes.go b/routers/api/v1/repo/notes.go index ce11c3f9a6453..0b259703deaaf 100644 --- a/routers/api/v1/repo/notes.go +++ b/routers/api/v1/repo/notes.go @@ -36,6 +36,14 @@ func GetNote(ctx *context.APIContext) { // description: a git ref or commit sha // type: string // 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: // "200": // "$ref": "#/responses/Note" diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 0c25b169e48e7..6fcc5267cf1d0 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1275,6 +1275,14 @@ func GetPullRequestCommits(ctx *context.APIContext) { // in: query // description: page size of results // 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: // "200": // "$ref": "#/responses/CommitList" From fa5f7fa4b00fe3e2101d5b202bb5979ef90df14c Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Sun, 8 Oct 2023 10:33:59 -0400 Subject: [PATCH 5/5] doc: regenerate swagger --- templates/swagger/v1_json.tmpl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index abe579ac826c1..2389ec3beee33 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -5239,6 +5239,18 @@ "name": "sha", "in": "path", "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": { @@ -10521,6 +10533,18 @@ "description": "page size of results", "name": "limit", "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": {