Merge pull request #46 from Nightapes/fix/commits

refactor(internal/git): revert list commits changes
This commit is contained in:
Felix Wiedmann
2020-11-11 16:01:03 +01:00
committed by GitHub

View File

@@ -134,7 +134,7 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) {
return nil, err return nil, err
} }
var commits []shared.Commit commits := make(map[string]shared.Commit)
var foundEnd bool var foundEnd bool
err = cIter.ForEach(func(c *object.Commit) error { err = cIter.ForEach(func(c *object.Commit) error {
@@ -147,55 +147,25 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) {
if !foundEnd { if !foundEnd {
log.Tracef("Found commit with hash %s", c.Hash.String()) log.Tracef("Found commit with hash %s", c.Hash.String())
commit := shared.Commit{ commits[c.Hash.String()] = shared.Commit{
Message: c.Message, Message: c.Message,
Author: c.Committer.Name, Author: c.Committer.Name,
Hash: c.Hash.String(), Hash: c.Hash.String(),
} }
commits = append(commits, commit)
if len(c.ParentHashes) == 2 {
parent, err := g.Repository.CommitObject(c.ParentHashes[1])
if err == nil {
commit := shared.Commit{
Message: parent.Message,
Author: parent.Committer.Name,
Hash: parent.Hash.String(),
}
commits = append(commits, commit)
log.Tracef("Found parent check for merge commits for hash %s", c.ParentHashes[1].String())
commits = append(commits, g.getParents(parent)...)
}
}
} }
return nil return nil
}) })
if err != nil { if err != nil {
return commits, errors.Wrap(err, "Could not read commits, check git clone depth in your ci") return nil, errors.Wrap(err, "Could not read commits, check git clone depth in your ci")
} }
return commits, nil l := make([]shared.Commit, 0)
}
func (g *GitUtil) getParents(current *object.Commit) []shared.Commit { for _, value := range commits {
commits := make([]shared.Commit, 0) l = append(l, value)
for _, i2 := range current.ParentHashes {
parent, err := g.Repository.CommitObject(i2)
if err != nil {
continue
}
commit := shared.Commit{
Message: parent.Message,
Author: parent.Committer.Name,
Hash: parent.Hash.String(),
}
commits = append(commits, commit)
if len(parent.ParentHashes) == 1 {
commits = append(commits, g.getParents(parent)...)
}
} }
return commits
return l, nil
} }