Skip to content
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

More commit info from API #19252

Merged
merged 3 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules/convert/git_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/gitdiff"
)

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

diff, err := gitdiff.GetDiff(gitRepo, &gitdiff.DiffOptions{
AfterCommitID: commit.ID.String(),
})
if err != nil {
return nil, err
}

return &api.Commit{
CommitMeta: &api.CommitMeta{
URL: repo.APIURL() + "/git/commits/" + url.PathEscape(commit.ID.String()),
Expand Down Expand Up @@ -175,10 +183,16 @@ func ToCommit(repo *repo_model.Repository, gitRepo *git.Repository, commit *git.
SHA: commit.ID.String(),
Created: commit.Committer.When,
},
Verification: ToVerification(commit),
},
Author: apiAuthor,
Committer: apiCommitter,
Parents: apiParents,
Files: affectedFileList,
Stats: &api.CommitStats{
Total: diff.TotalAddition + diff.TotalDeletion,
Additions: diff.TotalAddition,
Deletions: diff.TotalDeletion,
},
}, nil
}
19 changes: 14 additions & 5 deletions modules/structs/repo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ type CommitUser struct {

// RepoCommit contains information of a commit in the context of a repository.
type RepoCommit struct {
URL string `json:"url"`
Author *CommitUser `json:"author"`
Committer *CommitUser `json:"committer"`
Message string `json:"message"`
Tree *CommitMeta `json:"tree"`
URL string `json:"url"`
Author *CommitUser `json:"author"`
Committer *CommitUser `json:"committer"`
Message string `json:"message"`
Tree *CommitMeta `json:"tree"`
Verification *PayloadCommitVerification `json:"verification"`
}

// CommitStats is statistics for a RepoCommit
type CommitStats struct {
Total int `json:"total"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
}

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

// CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
Expand Down
28 changes: 28 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13127,6 +13127,9 @@
"type": "string",
"x-go-name": "SHA"
},
"stats": {
"$ref": "#/definitions/CommitStats"
},
"url": {
"type": "string",
"x-go-name": "URL"
Expand Down Expand Up @@ -13182,6 +13185,28 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"CommitStats": {
"description": "CommitStats is statistics for a RepoCommit",
"type": "object",
"properties": {
"additions": {
"type": "integer",
"format": "int64",
"x-go-name": "Additions"
},
"deletions": {
"type": "integer",
"format": "int64",
"x-go-name": "Deletions"
},
"total": {
"type": "integer",
"format": "int64",
"x-go-name": "Total"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"CommitStatus": {
"description": "CommitStatus holds a single status of a single Commit",
"type": "object",
Expand Down Expand Up @@ -17137,6 +17162,9 @@
"url": {
"type": "string",
"x-go-name": "URL"
},
"verification": {
"$ref": "#/definitions/PayloadCommitVerification"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
Expand Down