loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add files to compare (#6461)

Add the changed files between two commits to the response of the compare API, part of forgejo/forgejo#6460

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6461
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Angel Nunez Mencias <git@angelnu.com>
Co-committed-by: Angel Nunez Mencias <git@angelnu.com>

authored by

Angel Nunez Mencias
Angel Nunez Mencias
and committed by
Gusted
a2eb2497 339814f3

+15 -2
+3 -2
modules/structs/repo_compare.go
··· 5 5 6 6 // Compare represents a comparison between two commits. 7 7 type Compare struct { 8 - TotalCommits int `json:"total_commits"` // Total number of commits in the comparison. 9 - Commits []*Commit `json:"commits"` // List of commits in the comparison. 8 + TotalCommits int `json:"total_commits"` // Total number of commits in the comparison. 9 + Commits []*Commit `json:"commits"` // List of commits in the comparison. 10 + Files []*CommitAffectedFiles `json:"files"` // Total files modified in this comparison. 10 11 }
+3
routers/api/v1/repo/compare.go
··· 77 77 files := ctx.FormString("files") == "" || ctx.FormBool("files") 78 78 79 79 apiCommits := make([]*api.Commit, 0, len(ci.Commits)) 80 + apiFiles := []*api.CommitAffectedFiles{} 80 81 userCache := make(map[string]*user_model.User) 81 82 for i := 0; i < len(ci.Commits); i++ { 82 83 apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ci.Commits[i], userCache, ··· 90 91 return 91 92 } 92 93 apiCommits = append(apiCommits, apiCommit) 94 + apiFiles = append(apiFiles, apiCommit.Files...) 93 95 } 94 96 95 97 ctx.JSON(http.StatusOK, &api.Compare{ 96 98 TotalCommits: len(ci.Commits), 97 99 Commits: apiCommits, 100 + Files: apiFiles, 98 101 }) 99 102 }
+7
templates/swagger/v1_json.tmpl
··· 21379 21379 }, 21380 21380 "x-go-name": "Commits" 21381 21381 }, 21382 + "files": { 21383 + "type": "array", 21384 + "items": { 21385 + "$ref": "#/definitions/CommitAffectedFiles" 21386 + }, 21387 + "x-go-name": "Files" 21388 + }, 21382 21389 "total_commits": { 21383 21390 "type": "integer", 21384 21391 "format": "int64",
+2
tests/integration/api_repo_compare_test.go
··· 35 35 36 36 assert.Equal(t, 2, apiResp.TotalCommits) 37 37 assert.Len(t, apiResp.Commits, 2) 38 + assert.Len(t, apiResp.Files, 3) 38 39 } 39 40 40 41 func TestAPICompareCommits(t *testing.T) { ··· 54 55 55 56 assert.Equal(t, 2, apiResp.TotalCommits) 56 57 assert.Len(t, apiResp.Commits, 2) 58 + assert.Len(t, apiResp.Files, 3) 57 59 }