Compare commits

..

No commits in common. "main" and "0.11.1" have entirely different histories.
main ... 0.11.1

3 changed files with 11 additions and 33 deletions

View File

@ -1,15 +1,3 @@
## 0.13.0 (2024-10-25)
### Feat
- :sparkles: use time.Time.Before() instead of Sub()
## 0.12.0 (2024-10-25)
### Feat
- :sparkles: use tagger.when to find latest tag
## 0.11.1 (2024-07-11) ## 0.11.1 (2024-07-11)
### Fix ### Fix

View File

@ -5,5 +5,5 @@ commitizen:
name: cz_conventional_commits name: cz_conventional_commits
tag_format: $version tag_format: $version
update_changelog_on_bump: true update_changelog_on_bump: true
version: 0.13.0 version: 0.11.1
version_scheme: semver version_scheme: semver

View File

@ -11,7 +11,7 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"time" "strings"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/transport/client" "github.com/go-git/go-git/v5/plumbing/transport/client"
@ -62,34 +62,28 @@ func FetchTags() func(repo *git.Repository) error {
} }
} }
func getLatestGitTag(options ...GetLatestGitTagOption) (string, error) { func getLatestGitTag(options ...GetLatestGitTagOption) (tag string, err error) {
var ( r, err := git.PlainOpen(".")
tag string
tagDate *time.Time
err error
)
repo, err := git.PlainOpen(".")
if err != nil { if err != nil {
return "", fmt.Errorf("error opening git repo at %s: %w", ".", err) return "", fmt.Errorf("error opening git repo at %s: %w", ".", err)
} }
for _, opt := range options { for _, opt := range options {
err := opt(repo) err := opt(r)
if err != nil { if err != nil {
return "", err return "", err
} }
} }
tags, err := repo.TagObjects() tagRefs, err := r.Tags()
if err != nil { if err != nil {
return "", fmt.Errorf("error getting git tags %w", err) return "", fmt.Errorf("error getting git tag refs %w", err)
} }
for { for {
t, err := tags.Next() r, err := tagRefs.Next()
if err == io.EOF { if err == io.EOF {
break break
@ -99,19 +93,15 @@ func getLatestGitTag(options ...GetLatestGitTagOption) (string, error) {
return "", fmt.Errorf("error iterating tags %w", err) return "", fmt.Errorf("error iterating tags %w", err)
} }
if tagDate != nil && t.Tagger.When.Before(*tagDate) { parts := strings.Split(string(r.Name()), "/")
continue tag = strings.Join(parts[2:], "/")
}
tagDate = &t.Tagger.When
tag = t.Name
} }
if tag == "" { if tag == "" {
return tag, fmt.Errorf("couldn't find any git tags") return tag, fmt.Errorf("couldn't find any git tags")
} }
return tag, err return
} }
func writeCard(path, schema string, card interface{}) { func writeCard(path, schema string, card interface{}) {