Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider vPrefix when retrieving the latest semver tag. #159

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading