diff --git a/modules/structs/repo_compare.go b/modules/structs/repo_compare.go index 8a12498705..6e77a813d3 100644 --- a/modules/structs/repo_compare.go +++ b/modules/structs/repo_compare.go @@ -5,6 +5,7 @@ package structs // Compare represents a comparison between two commits. type Compare struct { - TotalCommits int `json:"total_commits"` // Total number of commits in the comparison. - Commits []*Commit `json:"commits"` // List of commits in the comparison. + TotalCommits int `json:"total_commits"` // Total number of commits in the comparison. + Commits []*Commit `json:"commits"` // List of commits in the comparison. + Files []*CommitAffectedFiles `json:"files"` // Total files modified in this comparison. } diff --git a/routers/api/v1/repo/compare.go b/routers/api/v1/repo/compare.go index 429145c714..7781e996f5 100644 --- a/routers/api/v1/repo/compare.go +++ b/routers/api/v1/repo/compare.go @@ -77,6 +77,7 @@ func CompareDiff(ctx *context.APIContext) { files := ctx.FormString("files") == "" || ctx.FormBool("files") apiCommits := make([]*api.Commit, 0, len(ci.Commits)) + apiFiles := []*api.CommitAffectedFiles{} userCache := make(map[string]*user_model.User) for i := 0; i < len(ci.Commits); i++ { apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ci.Commits[i], userCache, @@ -90,10 +91,12 @@ func CompareDiff(ctx *context.APIContext) { return } apiCommits = append(apiCommits, apiCommit) + apiFiles = append(apiFiles, apiCommit.Files...) } ctx.JSON(http.StatusOK, &api.Compare{ TotalCommits: len(ci.Commits), Commits: apiCommits, + Files: apiFiles, }) } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 1feeebba98..f726176883 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -21379,6 +21379,13 @@ }, "x-go-name": "Commits" }, + "files": { + "type": "array", + "items": { + "$ref": "#/definitions/CommitAffectedFiles" + }, + "x-go-name": "Files" + }, "total_commits": { "type": "integer", "format": "int64", diff --git a/tests/integration/api_repo_compare_test.go b/tests/integration/api_repo_compare_test.go index 765d0cef08..d4b170e60e 100644 --- a/tests/integration/api_repo_compare_test.go +++ b/tests/integration/api_repo_compare_test.go @@ -35,6 +35,7 @@ func TestAPICompareBranches(t *testing.T) { assert.Equal(t, 2, apiResp.TotalCommits) assert.Len(t, apiResp.Commits, 2) + assert.Len(t, apiResp.Files, 3) } func TestAPICompareCommits(t *testing.T) { @@ -54,4 +55,5 @@ func TestAPICompareCommits(t *testing.T) { assert.Equal(t, 2, apiResp.TotalCommits) assert.Len(t, apiResp.Commits, 2) + assert.Len(t, apiResp.Files, 3) }