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

Add files affected by a commit to gitea API -- similar to github #12413

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions modules/structs/repo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Commit struct {
Author *User `json:"author"`
Committer *User `json:"committer"`
Parents []*CommitMeta `json:"parents"`
Files []string `json:"files"`
lafriks marked this conversation as resolved.
Show resolved Hide resolved
}

// CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
Expand Down
9 changes: 9 additions & 0 deletions routers/api/v1/repo/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ func toCommit(ctx *context.APIContext, repo *models.Repository, commit *git.Comm
}
}

// Retrieve files affected by the commit
fileStatus, err := git.GetCommitFileStatus(repo.RepoPath(), commit.ID.String())
if err != nil {
return nil, err
}
affectedFiles := append(fileStatus.Added, fileStatus.Removed...)
affectedFiles = append(affectedFiles, fileStatus.Modified...)

return &api.Commit{
CommitMeta: &api.CommitMeta{
URL: repo.APIURL() + "/git/commits/" + commit.ID.String(),
Expand Down Expand Up @@ -307,5 +315,6 @@ func toCommit(ctx *context.APIContext, repo *models.Repository, commit *git.Comm
Author: apiAuthor,
Committer: apiCommitter,
Parents: apiParents,
Files: affectedFiles,
}, nil
}