History

[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

6543 committed 5 years ago

Commit cbe7f521 parent c11db354 files · +62 −11Browse files

Showing the changes to modules/convert/git_commit.go (1 of 4 files). Show all

Unified · Split

modules/convert/git_commit.go+15−0
@@ -131,6 +131,20 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] · 130 unmodified lines
131131 }
132132 }
133133
134+ // Retrieve files affected by the commit
135+ fileStatus, err := git.GetCommitFileStatus(repo.RepoPath(), commit.ID.String())
136+ if err != nil {
137+ return nil, err
138+ }
139+ affectedFileList := make([]*api.CommitAffectedFiles, 0, len(fileStatus.Added)+len(fileStatus.Removed)+len(fileStatus.Modified))
140+ for _, files := range [][]string{fileStatus.Added, fileStatus.Removed, fileStatus.Modified} {
141+ for _, filename := range files {
142+ affectedFileList = append(affectedFileList, &api.CommitAffectedFiles{
143+ Filename: filename,
144+ })
145+ }
146+ }
147+
134148 return &api.Commit{
135149 CommitMeta: &api.CommitMeta{
136150 URL: repo.APIURL() + "/git/commits/" + commit.ID.String(),
@@ -162,5 +176,6 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] · 25 unmodified lines
162176 Author: apiAuthor,
163177 Committer: apiCommitter,
164178 Parents: apiParents,
179+ Files: affectedFileList,
165180 }, nil
166181 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t