From 9af0c797b94418aaf7ad7b84f56051d1ca03b9af Mon Sep 17 00:00:00 2001 From: Axetroy Date: Sun, 10 Oct 2021 15:29:36 +0800 Subject: [PATCH] fix(deps): update github.com/release-lab/conventional-commit-parser@v0.1.8 --- go.mod | 2 +- go.sum | 2 + .../conventional-commit-parser/footer.go | 80 +++++++++++++ .../conventional-commit-parser/header.go | 42 +++++++ .../conventional-commit-parser/parser.go | 106 +----------------- vendor/modules.txt | 2 +- 6 files changed, 130 insertions(+), 104 deletions(-) create mode 100644 vendor/github.com/release-lab/conventional-commit-parser/footer.go create mode 100644 vendor/github.com/release-lab/conventional-commit-parser/header.go diff --git a/go.mod b/go.mod index d388c725..d06fd93a 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 github.com/go-git/go-git/v5 v5.4.2 github.com/pkg/errors v0.9.1 - github.com/release-lab/conventional-commit-parser v0.1.7 + github.com/release-lab/conventional-commit-parser v0.1.8 github.com/stretchr/testify v1.7.0 github.com/whilp/git-urls v1.0.0 ) diff --git a/go.sum b/go.sum index 4db17f22..56250fcd 100644 --- a/go.sum +++ b/go.sum @@ -239,6 +239,8 @@ github.com/release-lab/conventional-commit-parser v0.1.6 h1:GsmmsOBnYtuWubjaTkQY github.com/release-lab/conventional-commit-parser v0.1.6/go.mod h1:J56B1fNHAVNm5SynjINkz1mThTKqN0KQnFH54Fuz2KQ= github.com/release-lab/conventional-commit-parser v0.1.7 h1:aoyrKdOg3rDVhOci6kgqXzLFHV9AJLY58WHbgD3SQaQ= github.com/release-lab/conventional-commit-parser v0.1.7/go.mod h1:J56B1fNHAVNm5SynjINkz1mThTKqN0KQnFH54Fuz2KQ= +github.com/release-lab/conventional-commit-parser v0.1.8 h1:bXUj66k9pnVq5xAFUtsbyDcF8adXV4ZNgcrJT8hR3Z4= +github.com/release-lab/conventional-commit-parser v0.1.8/go.mod h1:J56B1fNHAVNm5SynjINkz1mThTKqN0KQnFH54Fuz2KQ= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= diff --git a/vendor/github.com/release-lab/conventional-commit-parser/footer.go b/vendor/github.com/release-lab/conventional-commit-parser/footer.go new file mode 100644 index 00000000..0cb9ad10 --- /dev/null +++ b/vendor/github.com/release-lab/conventional-commit-parser/footer.go @@ -0,0 +1,80 @@ +package conventionalcommitparser + +import ( + "regexp" + "strings" +) + +type Footer struct { + Tag string + Title string + Content string +} + +var ( + FOOTER_TAG_PATTERN = regexp.MustCompile(`(?i)^([a-z]+(-[a-z]+)*):\s?(.*)$`) + FOOTER_HASH_PATTERN = regexp.MustCompile(`^(?i)^([\w\-]+)\s+(#.*)`) + FOOTER_BREAKING_CHANGE_PATTERN = regexp.MustCompile(`^(BREAKING\sCHANGE):\s*(.*)$`) +) + +func paseFooterParagraph(txt string) Footer { + footer := Footer{} + + tagMatcher := FOOTER_TAG_PATTERN.FindStringSubmatch(txt) + breakingChangeMatcher := FOOTER_BREAKING_CHANGE_PATTERN.FindStringSubmatch(txt) + hashTagMatcher := FOOTER_HASH_PATTERN.FindStringSubmatch(txt) + + if len(breakingChangeMatcher) != 0 { + footer.Tag = strings.TrimSpace(breakingChangeMatcher[1]) + footer.Title = strings.TrimSpace(breakingChangeMatcher[2]) + } else if len(tagMatcher) != 0 { + footer.Tag = strings.TrimSpace(tagMatcher[1]) + footer.Title = strings.TrimSpace(tagMatcher[3]) + } else if len(hashTagMatcher) != 0 { + footer.Tag = strings.TrimSpace(hashTagMatcher[1]) + footer.Title = strings.TrimSpace(hashTagMatcher[2]) + } else { + footer.Tag = "" + footer.Title = txt + } + + return footer +} + +func isFooterParagraph(txt string) bool { + if FOOTER_BREAKING_CHANGE_PATTERN.MatchString(txt) { + return true + } + + if FOOTER_TAG_PATTERN.MatchString(txt) { + return true + } + + if FOOTER_HASH_PATTERN.MatchString(txt) { + return true + } + + return false +} + +func ParseFooter(txt string) Footer { + lines := splitToLines(txt) + + footer := Footer{} + + contents := make([]string, 0) + +lineLoop: + for index, line := range lines { + if index == 0 { + footer = paseFooterParagraph(line) + continue lineLoop + } else { + contents = append(contents, line) + } + } + + footer.Content = strings.TrimSpace(strings.Join(contents, "\n")) + + return footer +} diff --git a/vendor/github.com/release-lab/conventional-commit-parser/header.go b/vendor/github.com/release-lab/conventional-commit-parser/header.go new file mode 100644 index 00000000..7813b836 --- /dev/null +++ b/vendor/github.com/release-lab/conventional-commit-parser/header.go @@ -0,0 +1,42 @@ +package conventionalcommitparser + +import ( + "regexp" + "strings" +) + +type Header struct { + Type string + Scope string + Subject string + Important bool +} + +var ( + HEADER_PATTERN = regexp.MustCompile(`^(?i)([\s\w-]*)(\((.*)\))?(!?):\s+(.*)$`) + REVERT_HEADER_PATTERN = regexp.MustCompile(`^(?i)revert\s(.*)$`) +) + +func ParseHeader(txt string) Header { + headerMatchers := HEADER_PATTERN.FindStringSubmatch(txt) + revertHeaderMatchers := REVERT_HEADER_PATTERN.FindStringSubmatch(txt) + header := Header{} + + if len(headerMatchers) != 0 { // conventional commit + header.Type = strings.TrimSpace(strings.ToLower(headerMatchers[1])) + header.Scope = strings.TrimSpace(headerMatchers[3]) + header.Important = headerMatchers[4] == "!" + header.Subject = headerMatchers[5] + } else if len(revertHeaderMatchers) != 0 { // revert commit + subject := strings.Trim(revertHeaderMatchers[1], "\"") + subject = strings.Trim(subject, "'") + header.Type = "revert" + header.Subject = subject + } else { // commom commit + header.Type = "" + header.Scope = "" + header.Subject = txt + } + + return header +} diff --git a/vendor/github.com/release-lab/conventional-commit-parser/parser.go b/vendor/github.com/release-lab/conventional-commit-parser/parser.go index 077c286e..e29280ea 100644 --- a/vendor/github.com/release-lab/conventional-commit-parser/parser.go +++ b/vendor/github.com/release-lab/conventional-commit-parser/parser.go @@ -14,122 +14,24 @@ type Message struct { Footer []string } -type Header struct { - Type string - Scope string - Subject string - Important bool -} - -type Footer struct { - Tag string - Title string - Content string -} - var ( - EMPTY_LINE_PATTERN = regexp.MustCompile(`^\s*$`) - HEADER_PATTERN = regexp.MustCompile(`^(?:fixup!\s*)?(\w*)(\(([\w\$\.\*/-]*)\))?(!?):\s(.*)$`) - FOOTER_TAG_PATTERN = regexp.MustCompile(`(?i)^([a-z]+(-[a-z]+)*):\s?(.*)$`) - FOOTER_HASH_PATTERN = regexp.MustCompile(`^(?i)^([a-z][a-z]+)\s(((,\s*)?#\d+(,\s)?)+)$`) - FOOTER_BREAKING_CHANGE_PATTERN = regexp.MustCompile(`^(BREAKING\sCHANGE):\s?(.*)$`) - REVERT_HEADER_PATTERN = regexp.MustCompile(`^(?i)revert\s(.*)$`) - REVERT_BODY_PATTERN = regexp.MustCompile(`(?i)This\sreverts\scommit\s(\w+)\.?`) + EMPTY_LINE_PATTERN = regexp.MustCompile(`^\s*$`) + REVERT_BODY_PATTERN = regexp.MustCompile(`(?i)This\sreverts\scommit\s(\w+)\.?`) ) -func paseFooterParagraph(txt string) Footer { - footer := Footer{} - - tagMatcher := FOOTER_TAG_PATTERN.FindStringSubmatch(txt) - breakingChangeMatcher := FOOTER_BREAKING_CHANGE_PATTERN.FindStringSubmatch(txt) - hashTagMatcher := FOOTER_HASH_PATTERN.FindStringSubmatch(txt) - - if len(breakingChangeMatcher) != 0 { - footer.Tag = strings.TrimSpace(breakingChangeMatcher[1]) - footer.Title = strings.TrimSpace(breakingChangeMatcher[2]) - } else if len(tagMatcher) != 0 { - footer.Tag = strings.TrimSpace(tagMatcher[1]) - footer.Title = strings.TrimSpace(tagMatcher[3]) - } else if len(hashTagMatcher) != 0 { - footer.Tag = strings.TrimSpace(hashTagMatcher[1]) - footer.Title = strings.TrimSpace(hashTagMatcher[2]) - } else { - footer.Tag = "" - footer.Title = txt - } - - return footer -} - -func isFooterParagraph(txt string) bool { - if FOOTER_BREAKING_CHANGE_PATTERN.MatchString(txt) { - return true - } - - if FOOTER_TAG_PATTERN.MatchString(txt) { - return true - } - - if FOOTER_HASH_PATTERN.MatchString(txt) { - return true - } - - return false -} - func splitToLines(text string) []string { return strings.Split(strings.ReplaceAll(text, "\r\n", "\n"), "\n") } func (m Message) ParseHeader() Header { - headerMatchers := HEADER_PATTERN.FindStringSubmatch(m.Header) - revertHeaderMatchers := REVERT_HEADER_PATTERN.FindStringSubmatch(m.Header) - header := Header{} - - if len(headerMatchers) != 0 { // conventional commit - header.Type = strings.ToLower(headerMatchers[1]) - header.Scope = headerMatchers[3] - header.Important = headerMatchers[4] == "!" - header.Subject = headerMatchers[5] - } else if len(revertHeaderMatchers) != 0 { // revert commit - subject := strings.Trim(revertHeaderMatchers[1], "\"") - subject = strings.Trim(subject, "'") - header.Type = "revert" - header.Subject = subject - } else { // commom commit - header.Type = "" - header.Scope = "" - header.Subject = m.Header - } - - return header + return ParseHeader(m.Header) } func (m Message) ParseFooter() []Footer { footers := make([]Footer, 0) for _, m := range m.Footer { - lines := splitToLines(m) - - footer := Footer{} - - contents := make([]string, 0) - - lineLoop: - for index, line := range lines { - if index == 0 { - f := paseFooterParagraph(line) - footer.Tag = f.Tag - footer.Title = f.Title - continue lineLoop - } else { - contents = append(contents, line) - } - } - - footer.Content = strings.TrimSpace(strings.Join(contents, "\n")) - - footers = append(footers, footer) + footers = append(footers, ParseFooter(m)) } header := m.ParseHeader() diff --git a/vendor/modules.txt b/vendor/modules.txt index dbd16cfa..5066c75e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -173,7 +173,7 @@ github.com/pkg/errors # github.com/pmezard/go-difflib v1.0.0 ## explicit github.com/pmezard/go-difflib/difflib -# github.com/release-lab/conventional-commit-parser v0.1.7 +# github.com/release-lab/conventional-commit-parser v0.1.8 ## explicit; go 1.17 github.com/release-lab/conventional-commit-parser # github.com/sergi/go-diff v1.1.0