diff options
author | 6543 <6543@obermui.de> | 2021-02-07 15:43:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-07 15:43:40 +0100 |
commit | cbe7f5296e0400a6327b484cf78d6ffb93c9dd2c (patch) | |
tree | 9c6571cb33b8e3a1435697e776cce1dd53c91dfd /modules | |
parent | c11db35aec40e8e47ee8c678e508a7cdd06a2891 (diff) | |
download | gitea-cbe7f5296e0400a6327b484cf78d6ffb93c9dd2c.tar.gz gitea-cbe7f5296e0400a6327b484cf78d6ffb93c9dd2c.zip |
[API] Add affected files of commits to commit struct (#14579)
* Add files affected by a commit to gitea API -- similar to github
* Add files affected by a commit to gitea API
* Fix stupid error
* Fix other stupid typo
* Generate swagger tmpl
* Comply with convert to git commit refacto
* update swagger docs
* extend test
* format code
* Update integrations/api_repo_git_commits_test.go
* Update modules/convert/git_commit.go
Co-authored-by: Laurent Cahour <laurent.cahour@dont-nod.com>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/convert/git_commit.go | 15 | ||||
-rw-r--r-- | modules/structs/repo_commit.go | 16 |
2 files changed, 26 insertions, 5 deletions
diff --git a/modules/convert/git_commit.go b/modules/convert/git_commit.go index 87dfb51e70..4e30ec2c0b 100644 --- a/modules/convert/git_commit.go +++ b/modules/convert/git_commit.go @@ -131,6 +131,20 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] } } + // Retrieve files affected by the commit + fileStatus, err := git.GetCommitFileStatus(repo.RepoPath(), commit.ID.String()) + if err != nil { + return nil, err + } + affectedFileList := make([]*api.CommitAffectedFiles, 0, len(fileStatus.Added)+len(fileStatus.Removed)+len(fileStatus.Modified)) + for _, files := range [][]string{fileStatus.Added, fileStatus.Removed, fileStatus.Modified} { + for _, filename := range files { + affectedFileList = append(affectedFileList, &api.CommitAffectedFiles{ + Filename: filename, + }) + } + } + return &api.Commit{ CommitMeta: &api.CommitMeta{ URL: repo.APIURL() + "/git/commits/" + commit.ID.String(), @@ -162,5 +176,6 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] Author: apiAuthor, Committer: apiCommitter, Parents: apiParents, + Files: affectedFileList, }, nil } diff --git a/modules/structs/repo_commit.go b/modules/structs/repo_commit.go index b9607b185b..f5c5f1b940 100644 --- a/modules/structs/repo_commit.go +++ b/modules/structs/repo_commit.go @@ -42,11 +42,12 @@ type RepoCommit struct { // Commit contains information generated from a Git commit. type Commit struct { *CommitMeta - HTMLURL string `json:"html_url"` - RepoCommit *RepoCommit `json:"commit"` - Author *User `json:"author"` - Committer *User `json:"committer"` - Parents []*CommitMeta `json:"parents"` + HTMLURL string `json:"html_url"` + RepoCommit *RepoCommit `json:"commit"` + Author *User `json:"author"` + Committer *User `json:"committer"` + Parents []*CommitMeta `json:"parents"` + Files []*CommitAffectedFiles `json:"files"` } // CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE @@ -56,3 +57,8 @@ type CommitDateOptions struct { // swagger:strfmt date-time Committer time.Time `json:"committer"` } + +// CommitAffectedFiles store information about files affected by the commit +type CommitAffectedFiles struct { + Filename string `json:"filename"` +} |