Skip to content

Commit 66f2210

Browse files
jolheiserlunny
andauthored
More commit info from API (#19252)
Signed-off-by: jolheiser <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent 74731c3 commit 66f2210

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

modules/convert/git_commit.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"code.gitea.io/gitea/modules/log"
1515
api "code.gitea.io/gitea/modules/structs"
1616
"code.gitea.io/gitea/modules/util"
17+
"code.gitea.io/gitea/services/gitdiff"
1718
)
1819

1920
// ToCommitUser convert a git.Signature to an api.CommitUser
@@ -146,6 +147,13 @@ func ToCommit(repo *repo_model.Repository, gitRepo *git.Repository, commit *git.
146147
}
147148
}
148149

150+
diff, err := gitdiff.GetDiff(gitRepo, &gitdiff.DiffOptions{
151+
AfterCommitID: commit.ID.String(),
152+
})
153+
if err != nil {
154+
return nil, err
155+
}
156+
149157
return &api.Commit{
150158
CommitMeta: &api.CommitMeta{
151159
URL: repo.APIURL() + "/git/commits/" + url.PathEscape(commit.ID.String()),
@@ -175,10 +183,16 @@ func ToCommit(repo *repo_model.Repository, gitRepo *git.Repository, commit *git.
175183
SHA: commit.ID.String(),
176184
Created: commit.Committer.When,
177185
},
186+
Verification: ToVerification(commit),
178187
},
179188
Author: apiAuthor,
180189
Committer: apiCommitter,
181190
Parents: apiParents,
182191
Files: affectedFileList,
192+
Stats: &api.CommitStats{
193+
Total: diff.TotalAddition + diff.TotalDeletion,
194+
Additions: diff.TotalAddition,
195+
Deletions: diff.TotalDeletion,
196+
},
183197
}, nil
184198
}

modules/structs/repo_commit.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ type CommitUser struct {
3232

3333
// RepoCommit contains information of a commit in the context of a repository.
3434
type RepoCommit struct {
35-
URL string `json:"url"`
36-
Author *CommitUser `json:"author"`
37-
Committer *CommitUser `json:"committer"`
38-
Message string `json:"message"`
39-
Tree *CommitMeta `json:"tree"`
35+
URL string `json:"url"`
36+
Author *CommitUser `json:"author"`
37+
Committer *CommitUser `json:"committer"`
38+
Message string `json:"message"`
39+
Tree *CommitMeta `json:"tree"`
40+
Verification *PayloadCommitVerification `json:"verification"`
41+
}
42+
43+
// CommitStats is statistics for a RepoCommit
44+
type CommitStats struct {
45+
Total int `json:"total"`
46+
Additions int `json:"additions"`
47+
Deletions int `json:"deletions"`
4048
}
4149

4250
// Commit contains information generated from a Git commit.
@@ -48,6 +56,7 @@ type Commit struct {
4856
Committer *User `json:"committer"`
4957
Parents []*CommitMeta `json:"parents"`
5058
Files []*CommitAffectedFiles `json:"files"`
59+
Stats *CommitStats `json:"stats"`
5160
}
5261

5362
// CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE

templates/swagger/v1_json.tmpl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13127,6 +13127,9 @@
1312713127
"type": "string",
1312813128
"x-go-name": "SHA"
1312913129
},
13130+
"stats": {
13131+
"$ref": "#/definitions/CommitStats"
13132+
},
1313013133
"url": {
1313113134
"type": "string",
1313213135
"x-go-name": "URL"
@@ -13182,6 +13185,28 @@
1318213185
},
1318313186
"x-go-package": "code.gitea.io/gitea/modules/structs"
1318413187
},
13188+
"CommitStats": {
13189+
"description": "CommitStats is statistics for a RepoCommit",
13190+
"type": "object",
13191+
"properties": {
13192+
"additions": {
13193+
"type": "integer",
13194+
"format": "int64",
13195+
"x-go-name": "Additions"
13196+
},
13197+
"deletions": {
13198+
"type": "integer",
13199+
"format": "int64",
13200+
"x-go-name": "Deletions"
13201+
},
13202+
"total": {
13203+
"type": "integer",
13204+
"format": "int64",
13205+
"x-go-name": "Total"
13206+
}
13207+
},
13208+
"x-go-package": "code.gitea.io/gitea/modules/structs"
13209+
},
1318513210
"CommitStatus": {
1318613211
"description": "CommitStatus holds a single status of a single Commit",
1318713212
"type": "object",
@@ -17137,6 +17162,9 @@
1713717162
"url": {
1713817163
"type": "string",
1713917164
"x-go-name": "URL"
17165+
},
17166+
"verification": {
17167+
"$ref": "#/definitions/PayloadCommitVerification"
1714017168
}
1714117169
},
1714217170
"x-go-package": "code.gitea.io/gitea/modules/structs"

0 commit comments

Comments
 (0)