More commit info from API (#19252)

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
tokarchuk/v1.17
John Olheiser 3 years ago committed by GitHub
parent 74731c3a5a
commit 66f2210fec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      modules/convert/git_commit.go
  2. 19
      modules/structs/repo_commit.go
  3. 28
      templates/swagger/v1_json.tmpl

@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/gitdiff"
) )
// ToCommitUser convert a git.Signature to an api.CommitUser // ToCommitUser convert a git.Signature to an api.CommitUser
@ -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{ return &api.Commit{
CommitMeta: &api.CommitMeta{ CommitMeta: &api.CommitMeta{
URL: repo.APIURL() + "/git/commits/" + url.PathEscape(commit.ID.String()), 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.
SHA: commit.ID.String(), SHA: commit.ID.String(),
Created: commit.Committer.When, Created: commit.Committer.When,
}, },
Verification: ToVerification(commit),
}, },
Author: apiAuthor, Author: apiAuthor,
Committer: apiCommitter, Committer: apiCommitter,
Parents: apiParents, Parents: apiParents,
Files: affectedFileList, Files: affectedFileList,
Stats: &api.CommitStats{
Total: diff.TotalAddition + diff.TotalDeletion,
Additions: diff.TotalAddition,
Deletions: diff.TotalDeletion,
},
}, nil }, nil
} }

@ -32,11 +32,19 @@ type CommitUser struct {
// RepoCommit contains information of a commit in the context of a repository. // RepoCommit contains information of a commit in the context of a repository.
type RepoCommit struct { type RepoCommit struct {
URL string `json:"url"` URL string `json:"url"`
Author *CommitUser `json:"author"` Author *CommitUser `json:"author"`
Committer *CommitUser `json:"committer"` Committer *CommitUser `json:"committer"`
Message string `json:"message"` Message string `json:"message"`
Tree *CommitMeta `json:"tree"` 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. // Commit contains information generated from a Git commit.
@ -48,6 +56,7 @@ type Commit struct {
Committer *User `json:"committer"` Committer *User `json:"committer"`
Parents []*CommitMeta `json:"parents"` Parents []*CommitMeta `json:"parents"`
Files []*CommitAffectedFiles `json:"files"` Files []*CommitAffectedFiles `json:"files"`
Stats *CommitStats `json:"stats"`
} }
// CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE // CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE

@ -13127,6 +13127,9 @@
"type": "string", "type": "string",
"x-go-name": "SHA" "x-go-name": "SHA"
}, },
"stats": {
"$ref": "#/definitions/CommitStats"
},
"url": { "url": {
"type": "string", "type": "string",
"x-go-name": "URL" "x-go-name": "URL"
@ -13182,6 +13185,28 @@
}, },
"x-go-package": "code.gitea.io/gitea/modules/structs" "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": { "CommitStatus": {
"description": "CommitStatus holds a single status of a single Commit", "description": "CommitStatus holds a single status of a single Commit",
"type": "object", "type": "object",
@ -17137,6 +17162,9 @@
"url": { "url": {
"type": "string", "type": "string",
"x-go-name": "URL" "x-go-name": "URL"
},
"verification": {
"$ref": "#/definitions/PayloadCommitVerification"
} }
}, },
"x-go-package": "code.gitea.io/gitea/modules/structs" "x-go-package": "code.gitea.io/gitea/modules/structs"

Loading…
Cancel
Save