Skip to content

Commit

Permalink
Merge pull request #159 from k1LoW/consider-v-prefix
Browse files Browse the repository at this point in the history
Consider vPrefix when retrieving the latest semver tag.
  • Loading branch information
Songmu authored Oct 18, 2023
2 parents 1330a88 + ca5724f commit 4f96684
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tagpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ type tagpr struct {

func (tp *tagpr) latestSemverTag() string {
vers := (&gitsemvers.Semvers{GitPath: tp.gitPath}).VersionStrings()
if len(vers) > 0 {
return vers[0]
vPrefix := (tp.cfg.vPrefix != nil && *tp.cfg.vPrefix)
for _, v := range vers {
if strings.HasPrefix(v, "v") == vPrefix {
return v
}
}
return ""
}
Expand Down
29 changes: 29 additions & 0 deletions tagpr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,35 @@ func TestGeneratenNextLabels(t *testing.T) {
}
}

func TestLatestSemverTag(t *testing.T) {
tests := []struct {
name string
vPrefix bool
wantVer bool
}{
{"github.com/Songmu/tagpr has a semver tag with 'v' prefix", true, true},
{"github.com/Songmu/tagpr has no semver tag without 'v' prefix", false, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tp, err := newTagPR(context.Background(), &commander{
gitPath: "git", outStream: os.Stdout, errStream: os.Stderr, dir: "."},
)
if err != nil {
t.Error(err)
return
}
tp.cfg = &config{
vPrefix: &tt.vPrefix,
}
got := tp.latestSemverTag()
if (got != "") != tt.wantVer {
t.Errorf("got: %s, wantVer: %t", got, tt.wantVer)
}
})
}
}

func newGithubLabel(name *string) *github.Label {
return &github.Label{
ID: new(int64),
Expand Down

0 comments on commit 4f96684

Please sign in to comment.