[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>
This commit is contained in:
parent
c11db35aec
commit
cbe7f5296e
4 changed files with 62 additions and 11 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue