Skip to content

Commit 8da67b6

Browse files
committed
up: rename some const and method name, del qoute on exec tag -l
1 parent 017466f commit 8da67b6

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

cmd/chlog/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ func configCmd() {
6363
cmd.StringVar(&opts.excludes, "exclude", "", "exclude commit by keywords, multi split by comma")
6464
cmd.IntVar(&opts.tagType, "tag-type", 0, `get git tag name by tag type.
6565
Allowed:
66-
0 refname sort(<cyan>default</>)
67-
1 createordate sort
66+
0 ref-name sort(<cyan>default</>)
67+
1 creator date sort
6868
2 describe command;;t`)
6969

7070
cmd.AddArg("sha1", "The old git sha version. allow: tag name, commit id", true, nil)
@@ -160,8 +160,8 @@ func generate(cl *chlog.Changelog) error {
160160
gitArgs = append(gitArgs, "--no-merges")
161161
}
162162

163-
sha1 := repo.AutoMatchTagByTagType(opts.sha1, opts.tagType)
164-
sha2 := repo.AutoMatchTagByTagType(opts.sha2, opts.tagType)
163+
sha1 := repo.AutoMatchTagByType(opts.sha1, opts.tagType)
164+
sha2 := repo.AutoMatchTagByType(opts.sha2, opts.tagType)
165165
cliutil.Infof("Generate changelog: %s to %s\n", sha1, sha2)
166166

167167
cl.FetchGitLog(sha1, sha2, gitArgs...)

repo.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package gitw
22

33
import (
4-
"fmt"
54
"strings"
65

76
"github.com/gookit/goutil/arrutil"
@@ -18,11 +17,6 @@ const (
1817
cacheMaxTagVersion = "maxVersion"
1918
)
2019

21-
// CmdBuilder struct
22-
// type CmdBuilder struct {
23-
// Dir string
24-
// }
25-
2620
// RepoConfig struct
2721
type RepoConfig struct {
2822
DefaultBranch string
@@ -131,20 +125,20 @@ const (
131125
TagHead = "head"
132126
)
133127

134-
// type value constants for fetch tags
128+
// enum type value constants for fetch tags
135129
const (
136-
RefnameTagType int = iota
137-
CreatordateTagType
130+
RefNameTagType int = iota
131+
CreatorDateTagType
138132
DescribeTagType
139133
)
140134

141135
// AutoMatchTag by given sha or tag name
142136
func (r *Repo) AutoMatchTag(sha string) string {
143-
return r.AutoMatchTagByTagType(sha, RefnameTagType)
137+
return r.AutoMatchTagByType(sha, RefNameTagType)
144138
}
145139

146-
// AutoMatchTagByTagType by given sha or tag name
147-
func (r *Repo) AutoMatchTagByTagType(sha string, tagType int) string {
140+
// AutoMatchTagByType by given sha or tag name.
141+
func (r *Repo) AutoMatchTagByType(sha string, tagType int) string {
148142
switch strings.ToLower(sha) {
149143
case TagLast:
150144
return r.LargestTagByTagType(tagType)
@@ -187,8 +181,8 @@ func (r *Repo) LargestTagByTagType(tagType int) string {
187181

188182
tags := make([]string, 0, 2)
189183
switch tagType {
190-
case CreatordateTagType:
191-
tags = append(tags, r.TagsSortedByCreatordate()...)
184+
case CreatorDateTagType:
185+
tags = append(tags, r.TagsSortedByCreatorDate()...)
192186
case DescribeTagType:
193187
tags = append(tags, r.TagByDescribe(""))
194188
default:
@@ -221,8 +215,8 @@ func (r *Repo) TagSecondMax() string {
221215
func (r *Repo) TagSecondMaxByTagType(tagType int) string {
222216
tags := make([]string, 0, 2)
223217
switch tagType {
224-
case CreatordateTagType:
225-
tags = append(tags, r.TagsSortedByCreatordate()...)
218+
case CreatorDateTagType:
219+
tags = append(tags, r.TagsSortedByCreatorDate()...)
226220
case DescribeTagType:
227221
current := r.TagByDescribe("")
228222
if len(current) != 0 {
@@ -251,30 +245,36 @@ func (r *Repo) TagsSortedByRefName() []string {
251245
return OutputLines(str)
252246
}
253247

254-
// TagsSortedByCreatordate get repo tags list by creatordate sort
255-
func (r *Repo) TagsSortedByCreatordate() []string {
256-
str, err := r.gw.Tag("-l", "--sort=-creatordate", "--format=\"%(refname:strip=2)\"").Output()
248+
// TagsSortedByCreatorDate get repo tags list by creator date sort
249+
func (r *Repo) TagsSortedByCreatorDate() []string {
250+
str, err := r.gw.
251+
Tag("-l", "--sort=-creatordate", "--format=%(refname:strip=2)").
252+
Output()
253+
257254
if err != nil {
258255
r.setErr(err)
259256
return nil
260257
}
261258
return OutputLines(str)
262259
}
263260

264-
// TagByDescribe get tag by describe command
265-
func (r *Repo) TagByDescribe(current string) (str string) {
261+
// TagByDescribe get tag by describe command. if current not empty, will exclude it.
262+
func (r *Repo) TagByDescribe(current string) (ver string) {
266263
var err error
267264
if len(current) == 0 {
268-
str, err = r.gw.Describe("--tags", "--abbrev=0").Output()
265+
ver, err = r.gw.Describe("--tags", "--abbrev=0").Output()
269266
} else {
270-
str, err = r.gw.Describe("--tags", "--abbrev=0", fmt.Sprintf("tags/%s^", current)).Output()
267+
ver, err = r.gw.
268+
Describe("--tags", "--abbrev=0").
269+
Argf("tags/%s^", current).
270+
Output()
271271
}
272272

273273
if err != nil {
274274
r.setErr(err)
275275
return ""
276276
}
277-
return FirstLine(str)
277+
return FirstLine(ver)
278278
}
279279

280280
// Tags get repo tags list

repo_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ func TestRepo_Info(t *testing.T) {
7676
}
7777

7878
func TestRepo_AutoMatchTagByTagType(t *testing.T) {
79-
assert.Equal(t, "HEAD", repo.AutoMatchTagByTagType("head", 0))
80-
assert.Equal(t, "541fb9d", repo.AutoMatchTagByTagType("541fb9d", 0))
79+
assert.Equal(t, "HEAD", repo.AutoMatchTagByType("head", 0))
80+
assert.Equal(t, "541fb9d", repo.AutoMatchTagByType("541fb9d", 0))
8181
}
8282

83-
func TestRepo_TagsSortedByCreatordate(t *testing.T) {
84-
tags := repo.TagsSortedByCreatordate()
83+
func TestRepo_TagsSortedByCreatorDate(t *testing.T) {
84+
tags := repo.TagsSortedByCreatorDate()
8585
dump.P(tags)
8686
assert.NotEmpty(t, tags)
8787
}

0 commit comments

Comments
 (0)