Skip to content

Commit 94dde94

Browse files
pr comments
1 parent 951ffcd commit 94dde94

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

pkg/git/GitFormatter.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const _dl_ = "devtron_delimiter"
1212

1313
// GITFORMAT Refer git official doc for supported placeholders to add new fields
1414
// Need to make sure the output does not break the json structure which is ensured
15-
//by having the _dl_ delimiter which is later replaced by quotes
15+
// by having the _dl_ delimiter which is later replaced by quotes
1616
var GITFORMAT = "--pretty=format:{" +
1717
_dl_ + "commit" + _dl_ + ":" + _dl_ + "%H" + _dl_ + "," +
1818
_dl_ + "parent" + _dl_ + ":" + _dl_ + "%P" + _dl_ + "," +
@@ -57,7 +57,7 @@ func parseFormattedLogOutput(out string) ([]GitCommitFormat, error) {
5757
//replace the delimiter with quotes to make it parsable json
5858
logOut = strings.ReplaceAll(logOut, _dl_, `"`)
5959

60-
logOut = logOut[1 : len(logOut)-2] // trim surround characters (surrounding quotes and trailing com,a)
60+
logOut = logOut[1 : len(logOut)-2] // trim surround characters (surrounding quotes and trailing comma)
6161
logOut = fmt.Sprintf("[%s]", logOut) // Add []
6262

6363
var gitCommitFormattedList []GitCommitFormat
@@ -67,3 +67,25 @@ func parseFormattedLogOutput(out string) ([]GitCommitFormat, error) {
6767
}
6868
return gitCommitFormattedList, nil
6969
}
70+
71+
func (formattedCommit GitCommitFormat) transformToCommit() *Commit {
72+
return &Commit{
73+
Hash: &Hash{
74+
Long: formattedCommit.Commit,
75+
},
76+
Author: &Author{
77+
Name: formattedCommit.Author.Name,
78+
Email: formattedCommit.Author.Email,
79+
Date: formattedCommit.Author.Date,
80+
},
81+
Committer: &Committer{
82+
Name: formattedCommit.Commiter.Name,
83+
Email: formattedCommit.Commiter.Email,
84+
Date: formattedCommit.Commiter.Date,
85+
},
86+
Tag: &Tag{},
87+
Tree: &Tree{},
88+
Subject: formattedCommit.Subject,
89+
Body: formattedCommit.Body,
90+
}
91+
}

pkg/git/RepositoryManagerAnalytics.go

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,17 @@ func (impl RepositoryManagerAnalyticsImpl) ChangesSinceByRepositoryForAnalytics(
214214
GitChanges.FileStats = fileStats
215215
impl.logger.Debugw("computed files stats", "filestats", fileStats)
216216

217+
commits, err := impl.computeCommitDiff(gitCtx, checkoutPath, oldHash, newHash, repository)
218+
if err != nil {
219+
return nil, err
220+
}
221+
GitChanges.Commits = commits
222+
return GitChanges, nil
223+
}
224+
225+
func (impl RepositoryManagerAnalyticsImpl) computeCommitDiff(gitCtx GitContext, checkoutPath string, oldHash plumbing.Hash, newHash plumbing.Hash, repository *GitRepository) ([]*Commit, error) {
217226
var commitsCli, commitsGoGit []*Commit
227+
var err error
218228
if impl.configuration.UseGitCli || impl.configuration.AnalyticsDebug {
219229
commitsCli, err = impl.gitManager.LogMergeBase(gitCtx, checkoutPath, oldHash.String(), newHash.String())
220230
if err != nil {
@@ -234,15 +244,13 @@ func (impl RepositoryManagerAnalyticsImpl) ChangesSinceByRepositoryForAnalytics(
234244
}
235245
}
236246
if impl.configuration.AnalyticsDebug {
237-
impl.logOldestCommitComparison(commitsGoGit, commitsCli, checkoutPath, Old, New)
247+
impl.logOldestCommitComparison(commitsGoGit, commitsCli, checkoutPath, oldHash.String(), newHash.String())
238248
}
239249

240250
if !impl.configuration.UseGitCli {
241-
GitChanges.Commits = commitsGoGit
242-
} else {
243-
GitChanges.Commits = commitsCli
251+
return commitsGoGit, nil
244252
}
245-
return GitChanges, nil
253+
return commitsCli, nil
246254
}
247255

248256
func (impl RepositoryManagerAnalyticsImpl) logOldestCommitComparison(commitsGoGit []*Commit, commitsCli []*Commit, checkoutPath string, old string, new string) {
@@ -324,29 +332,8 @@ func processGitLogOutputForAnalytics(out string) ([]*Commit, error) {
324332
if err != nil {
325333
return gitCommits, err
326334
}
327-
328335
for _, formattedCommit := range gitCommitFormattedList {
329-
330-
cm := Commit{
331-
Hash: &Hash{
332-
Long: formattedCommit.Commit,
333-
},
334-
Author: &Author{
335-
Name: formattedCommit.Author.Name,
336-
Email: formattedCommit.Author.Email,
337-
Date: formattedCommit.Author.Date,
338-
},
339-
Committer: &Committer{
340-
Name: formattedCommit.Commiter.Name,
341-
Email: formattedCommit.Commiter.Email,
342-
Date: formattedCommit.Commiter.Date,
343-
},
344-
Tag: &Tag{},
345-
Tree: &Tree{},
346-
Subject: formattedCommit.Subject,
347-
Body: formattedCommit.Body,
348-
}
349-
gitCommits = append(gitCommits, &cm)
336+
gitCommits = append(gitCommits, formattedCommit.transformToCommit())
350337
}
351338
return gitCommits, nil
352339
}

0 commit comments

Comments
 (0)