Skip to content

Commit

Permalink
fix: parse single version tag:N incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Nov 27, 2020
1 parent f83db49 commit aa62d6b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
24 changes: 20 additions & 4 deletions 1_parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func getCommit(git *client.GitClient, version string, isStart bool) (*object.Com
return nil, errors.WithStack(err)
}

if tag == nil {
return nil, nil
}

return tag.Commit, nil
} else if regShortHash.MatchString(version) {
return git.CommitByShort(version)
Expand Down Expand Up @@ -132,12 +136,24 @@ func Parse(git *client.GitClient, ranges string) (*Scope, error) {
versions = append(versions, "")
}
} else if len(versions) == 1 {
// make sure the length is always 2
var tag *client.Tag

tag, err := git.TagName(ranges)
if regTag.MatchString(ranges) {
matcher := regTag.FindStringSubmatch(ranges)

if err != nil {
return nil, errors.WithStack(err)
tagIndex, err := strconv.ParseInt(matcher[1], 10, 10)

if err != nil {
return nil, errors.WithStack(err)
}

if tag, err = git.TagN(int(tagIndex)); err != nil {
return nil, errors.WithStack(err)
}
} else {
if tag, err = git.TagName(ranges); err != nil {
return nil, errors.WithStack(err)
}
}

if tag != nil {
Expand Down
10 changes: 6 additions & 4 deletions 2_extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,29 @@ func Extract(g *client.GitClient, scope *parser.Scope) ([]*ExtractSplice, error)

splices = append(splices, splice)
} else {
splice := &ExtractSplice{
item := &ExtractSplice{
Name: "Unreleased",
}

internalLoop2:
for {
if index == len(commits) {
splices = append(splices, item)
break internalLoop2
}

nextCommit := commits[index]

if t := getTagOfCommit(scope.Tags, nextCommit); t != nil {
splices = append(splices, item)
break internalLoop2
}

if splice.Commit == nil {
splice.Commit = make([]*object.Commit, 0)
if item.Commit == nil {
item.Commit = make([]*object.Commit, 0)
}

splice.Commit = append(splice.Commit, nextCommit)
item.Commit = append(item.Commit, nextCommit)

index++
}
Expand Down

0 comments on commit aa62d6b

Please sign in to comment.