aboutsummaryrefslogtreecommitdiffstats
path: root/services/convert
diff options
context:
space:
mode:
Diffstat (limited to 'services/convert')
-rw-r--r--services/convert/git_commit.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/services/convert/git_commit.go b/services/convert/git_commit.go
index 20fb8c2565..119237e0ca 100644
--- a/services/convert/git_commit.go
+++ b/services/convert/git_commit.go
@@ -72,8 +72,14 @@ func ToPayloadCommit(ctx context.Context, repo *repo_model.Repository, c *git.Co
}
}
+type ToCommitOptions struct {
+ Stat bool
+ Verification bool
+ Files bool
+}
+
// ToCommit convert a git.Commit to api.Commit
-func ToCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, commit *git.Commit, userCache map[string]*user_model.User, stat bool) (*api.Commit, error) {
+func ToCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, commit *git.Commit, userCache map[string]*user_model.User, opts ToCommitOptions) (*api.Commit, error) {
var apiAuthor, apiCommitter *api.User
// Retrieve author and committer information
@@ -162,19 +168,24 @@ func ToCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Rep
SHA: commit.ID.String(),
Created: commit.Committer.When,
},
- Verification: ToVerification(ctx, commit),
},
Author: apiAuthor,
Committer: apiCommitter,
Parents: apiParents,
}
+ // Retrieve verification for commit
+ if opts.Verification {
+ res.RepoCommit.Verification = ToVerification(ctx, commit)
+ }
+
// Retrieve files affected by the commit
- if stat {
+ if opts.Files {
fileStatus, err := git.GetCommitFileStatus(gitRepo.Ctx, 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 {
@@ -184,6 +195,11 @@ func ToCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Rep
}
}
+ res.Files = affectedFileList
+ }
+
+ // Get diff stats for commit
+ if opts.Stat {
diff, err := gitdiff.GetDiff(gitRepo, &gitdiff.DiffOptions{
AfterCommitID: commit.ID.String(),
})
@@ -191,7 +207,6 @@ func ToCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Rep
return nil, err
}
- res.Files = affectedFileList
res.Stats = &api.CommitStats{
Total: diff.TotalAddition + diff.TotalDeletion,
Additions: diff.TotalAddition,