mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-01-10 15:42:16 +01:00
feat: add files to compare (#6461)
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
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>
This commit is contained in:
parent
339814f3bc
commit
a2eb249766
4 changed files with 15 additions and 2 deletions
|
@ -5,6 +5,7 @@ package structs
|
||||||
|
|
||||||
// Compare represents a comparison between two commits.
|
// Compare represents a comparison between two commits.
|
||||||
type Compare struct {
|
type Compare struct {
|
||||||
TotalCommits int `json:"total_commits"` // Total number 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.
|
Commits []*Commit `json:"commits"` // List of commits in the comparison.
|
||||||
|
Files []*CommitAffectedFiles `json:"files"` // Total files modified in this comparison.
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ func CompareDiff(ctx *context.APIContext) {
|
||||||
files := ctx.FormString("files") == "" || ctx.FormBool("files")
|
files := ctx.FormString("files") == "" || ctx.FormBool("files")
|
||||||
|
|
||||||
apiCommits := make([]*api.Commit, 0, len(ci.Commits))
|
apiCommits := make([]*api.Commit, 0, len(ci.Commits))
|
||||||
|
apiFiles := []*api.CommitAffectedFiles{}
|
||||||
userCache := make(map[string]*user_model.User)
|
userCache := make(map[string]*user_model.User)
|
||||||
for i := 0; i < len(ci.Commits); i++ {
|
for i := 0; i < len(ci.Commits); i++ {
|
||||||
apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ci.Commits[i], userCache,
|
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
|
return
|
||||||
}
|
}
|
||||||
apiCommits = append(apiCommits, apiCommit)
|
apiCommits = append(apiCommits, apiCommit)
|
||||||
|
apiFiles = append(apiFiles, apiCommit.Files...)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, &api.Compare{
|
ctx.JSON(http.StatusOK, &api.Compare{
|
||||||
TotalCommits: len(ci.Commits),
|
TotalCommits: len(ci.Commits),
|
||||||
Commits: apiCommits,
|
Commits: apiCommits,
|
||||||
|
Files: apiFiles,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
7
templates/swagger/v1_json.tmpl
generated
7
templates/swagger/v1_json.tmpl
generated
|
@ -21379,6 +21379,13 @@
|
||||||
},
|
},
|
||||||
"x-go-name": "Commits"
|
"x-go-name": "Commits"
|
||||||
},
|
},
|
||||||
|
"files": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/CommitAffectedFiles"
|
||||||
|
},
|
||||||
|
"x-go-name": "Files"
|
||||||
|
},
|
||||||
"total_commits": {
|
"total_commits": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64",
|
"format": "int64",
|
||||||
|
|
|
@ -35,6 +35,7 @@ func TestAPICompareBranches(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, 2, apiResp.TotalCommits)
|
assert.Equal(t, 2, apiResp.TotalCommits)
|
||||||
assert.Len(t, apiResp.Commits, 2)
|
assert.Len(t, apiResp.Commits, 2)
|
||||||
|
assert.Len(t, apiResp.Files, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPICompareCommits(t *testing.T) {
|
func TestAPICompareCommits(t *testing.T) {
|
||||||
|
@ -54,4 +55,5 @@ func TestAPICompareCommits(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, 2, apiResp.TotalCommits)
|
assert.Equal(t, 2, apiResp.TotalCommits)
|
||||||
assert.Len(t, apiResp.Commits, 2)
|
assert.Len(t, apiResp.Commits, 2)
|
||||||
|
assert.Len(t, apiResp.Files, 3)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue