Skip to content

api: GetPullRequestCommits: return file list #27483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 9, 2023
10 changes: 9 additions & 1 deletion routers/api/v1/repo/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
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
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/api_pull_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ 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)
assert.NotNil(t, commits[0].RepoCommit.Verification)
assert.NotNil(t, commits[1].RepoCommit.Verification)
}

// TODO add tests for already merged PR and closed PR
2 changes: 2 additions & 0 deletions tests/integration/api_repo_git_notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}