You've already forked go-semantic-release
fix(internal/git): check merge commits and collect parent commits for changelog
This commit is contained in:
@@ -138,11 +138,13 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) {
|
|||||||
var foundEnd bool
|
var foundEnd bool
|
||||||
|
|
||||||
err = cIter.ForEach(func(c *object.Commit) error {
|
err = cIter.ForEach(func(c *object.Commit) error {
|
||||||
|
|
||||||
if c.Hash.String() == lastTagHash {
|
if c.Hash.String() == lastTagHash {
|
||||||
log.Debugf("Found commit with hash %s, will stop here", c.Hash.String())
|
log.Debugf("Found commit with hash %s, will stop here", c.Hash.String())
|
||||||
foundEnd = true
|
foundEnd = true
|
||||||
return storer.ErrStop
|
return storer.ErrStop
|
||||||
}
|
}
|
||||||
|
|
||||||
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{
|
commit := shared.Commit{
|
||||||
@@ -151,6 +153,22 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) {
|
|||||||
Hash: c.Hash.String(),
|
Hash: c.Hash.String(),
|
||||||
}
|
}
|
||||||
commits = append(commits, commit)
|
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
|
||||||
})
|
})
|
||||||
@@ -161,3 +179,23 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) {
|
|||||||
|
|
||||||
return commits, nil
|
return commits, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GitUtil) getParents(current *object.Commit) []shared.Commit {
|
||||||
|
commits := make([]shared.Commit, 0)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user