Skip to content
Snippets Groups Projects
Verified Commit 48a7528c authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: read log

parent a30ca8b2
Branches
Tags 0.2.1
No related merge requests found
......@@ -96,7 +96,8 @@ func executeCommand() {
case FixCommit:
command = "patch"
case OtherCommit:
fmt.Println("No changes found")
fmt.Println("No notable changes found.")
fmt.Println("If you want to force a version\nincrease, use the major, minor\nor patch command.")
os.Exit(0)
}
......
......@@ -7,6 +7,7 @@ import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/storer"
)
type CommitType int
......@@ -83,28 +84,43 @@ func getLatestTagCommit(r *git.Repository) (*object.Commit, error) {
}
func getCommitTypeSinceTag(r *git.Repository, tagCommit *object.Commit) (CommitType, error) {
cIter, err := r.Log(&git.LogOptions{From: tagCommit.Hash})
cIter, err := r.Log(&git.LogOptions{})
if err != nil {
return OtherCommit, fmt.Errorf("failed to get commit log: %v", err)
}
var commitType CommitType
found := false
err = cIter.ForEach(func(commit *object.Commit) error {
if commit.Hash == tagCommit.Hash {
found = true
return storer.ErrStop // stop iteration
}
if strings.HasPrefix(commit.Message, "feat:") {
commitType = FeatCommit
found = true
return storer.ErrStop // stop iteration
} else if strings.HasPrefix(commit.Message, "fix:") {
commitType = FixCommit
} else if containsBreakingChangeFooter(commit.Message) {
commitType = BreakingCommit
found = true
return storer.ErrStop // stop iteration
} else {
commitType = OtherCommit
}
return nil
})
if err != nil {
return OtherCommit, fmt.Errorf("failed to iterate over commit log: %v", err)
}
if !found {
return OtherCommit, fmt.Errorf("tag commit not found in commit log")
}
return commitType, nil
}
......
......@@ -212,6 +212,10 @@ func getVersion() (*semver.Version, error) {
}
func writeVersionToJson(version string) error {
if content == nil {
return fmt.Errorf("content is nil")
}
result, err := sjson.Set(string(content), arguments.Selector, version)
if err != nil {
return err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment