From e930b89df4916e6596f9073be8545e44f3e4abaa Mon Sep 17 00:00:00 2001 From: axetroy Date: Fri, 27 Nov 2020 10:21:35 +0800 Subject: [PATCH] refactor: improve the extractor --- 2_extractor/extractor.go | 66 ++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 44 deletions(-) diff --git a/2_extractor/extractor.go b/2_extractor/extractor.go index 055b1748..41daba3a 100644 --- a/2_extractor/extractor.go +++ b/2_extractor/extractor.go @@ -79,61 +79,39 @@ func Extract(g *client.GitClient, scope *parser.Scope) ([]*ExtractSplice, error) commit := commits[index] - if tag := getTagOfCommit(scope.Tags, commit); tag != nil { - splice := &ExtractSplice{ - Name: tag.Name, - Tag: tag, - Commit: make([]*object.Commit, 0), - } - splice.Commit = append(splice.Commit, commit) - index++ - internalLoop: - for { - if index == len(commits) { - break internalLoop - } - - nextCommit := commits[index] + item := &ExtractSplice{ + Name: "Unreleased", + Commit: make([]*object.Commit, 0), + } - if t := getTagOfCommit(scope.Tags, nextCommit); t != nil { - break internalLoop - } + item.Commit = append(item.Commit, commit) - splice.Commit = append(splice.Commit, nextCommit) + if tag := getTagOfCommit(scope.Tags, commit); tag != nil { + item.Tag = tag + item.Name = tag.Name + } - index++ - } + index++ - splices = append(splices, splice) - } else { - item := &ExtractSplice{ - Name: "Unreleased", + loop: + for { + if index == len(commits) { + break loop } - internalLoop2: - for { - if index == len(commits) { - splices = append(splices, item) - break internalLoop2 - } + nextCommit := commits[index] - nextCommit := commits[index] - - if t := getTagOfCommit(scope.Tags, nextCommit); t != nil { - splices = append(splices, item) - break internalLoop2 - } + if t := getTagOfCommit(scope.Tags, nextCommit); t != nil { + break loop + } - if item.Commit == nil { - item.Commit = make([]*object.Commit, 0) - } + item.Commit = append(item.Commit, nextCommit) - item.Commit = append(item.Commit, nextCommit) + index++ + } - index++ - } + splices = append(splices, item) - } } return splices, nil