Skip to content

Commit c22a89c

Browse files
committed
chore: quick update feat/genai at 2025-11-04 16:39:29
2 parents 91a967c + 1572a63 commit c22a89c

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

cmds/tagcmd/cmd.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tagcmd
33
import (
44
"context"
55
"fmt"
6+
"sort"
67
"strings"
78
"time"
89

@@ -12,6 +13,7 @@ import (
1213
"github.com/pubgo/funk/v2/errors"
1314
"github.com/pubgo/funk/v2/recovery"
1415
"github.com/pubgo/funk/v2/result"
16+
"github.com/samber/lo"
1517
"github.com/urfave/cli/v3"
1618
"github.com/yarlson/tap"
1719

@@ -62,19 +64,43 @@ func New() *cli.Command {
6264
utils.LogConfigAndBranch()
6365

6466
if flags.fastCommit {
65-
tagName := strings.TrimSpace(tap.Text(ctx, tap.TextOptions{
67+
tags := utils.GetAllGitTags(ctx)
68+
69+
sort.Slice(tags, func(i, j int) bool { return tags[i].GreaterThanOrEqual(tags[j]) })
70+
selectTags := lo.Map(tags, func(item *semver.Version, index int) tap.SelectOption[*semver.Version] {
71+
return tap.SelectOption[*semver.Version]{
72+
Value: item,
73+
Label: item.Original(),
74+
}
75+
})
76+
selectTags = lo.Chunk(selectTags, 10)[0]
77+
78+
tagResult := tap.Select[*semver.Version](ctx, tap.SelectOptions[*semver.Version]{
79+
Message: "git tag(enter):",
80+
Options: selectTags,
81+
})
82+
83+
if tagResult == nil {
84+
return nil
85+
}
86+
87+
tagName := tap.Text(ctx, tap.TextOptions{
6688
Message: "git tag(enter):",
67-
DefaultValue: "v0.0.1",
68-
Placeholder: "enter a tag",
89+
InitialValue: tagResult.Original(),
90+
DefaultValue: tagResult.Original(),
91+
Placeholder: "enter git tag",
6992
Validate: func(s string) error {
7093
if !strings.HasPrefix(s, "v") {
7194
return fmt.Errorf("tag name must start with v")
7295
}
7396

7497
_, err := semver.NewSemver(s)
98+
if err == nil {
99+
return nil
100+
}
75101
return fmt.Errorf("tag is invalid, tag=%s err=%w", s, err)
76102
},
77-
}))
103+
})
78104

79105
if tagName == "" {
80106
return fmt.Errorf("tag name is empty")

utils/util.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ func GetCurMaxVer(ctx context.Context) *semver.Version {
8484
}
8585

8686
func GetNextReleaseTag(tags []*semver.Version) *semver.Version {
87+
if len(tags) == 0 {
88+
return semver.Must(semver.NewSemver("v0.0.1"))
89+
}
90+
8791
var curMaxVer = typex.DoBlock1(func() *semver.Version {
8892
return lo.MaxBy(tags, func(a *semver.Version, b *semver.Version) bool { return a.Compare(b) > 0 })
8993
})
@@ -97,6 +101,10 @@ func GetNextReleaseTag(tags []*semver.Version) *semver.Version {
97101
}
98102

99103
func GetNextTag(pre string, tags []*semver.Version) *semver.Version {
104+
if len(tags) == 0 {
105+
return semver.Must(semver.NewSemver("v0.0.1"))
106+
}
107+
100108
var maxVer = GetNextGitMaxTag(tags)
101109
var curMaxVer = typex.DoBlock1(func() *semver.Version {
102110
tags = lo.Filter(tags, func(item *semver.Version, index int) bool { return strings.Contains(item.String(), pre) })
@@ -167,7 +175,7 @@ func GitPush(ctx context.Context, args ...string) string {
167175
output := result.Async(func() result.Result[string] { return ShellExecOutput(ctx, args...) })
168176
time.Sleep(time.Millisecond * 20)
169177

170-
spin := spinner.New(spinner.CharSets[35], 100*time.Millisecond, func(s *spinner.Spinner) { s.Prefix = "push git message: " })
178+
spin := spinner.New(spinner.CharSets[35], 100*time.Millisecond, func(s *spinner.Spinner) { s.Prefix = strings.Join(args, " ") + ":" })
171179
spin.Start()
172180
res := output.Await(ctx).Must()
173181
spin.Stop()

0 commit comments

Comments
 (0)