From 0669e5f3b21492c11c2db43cd6e267566f5880f3 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Tue, 26 Sep 2023 10:58:41 +0200 Subject: [PATCH] fix(pkg): properly support "!" for breaking changes. Moreover, "feat" is also a valid feature prefix name. Signed-off-by: Federico Di Pierro --- pkg/releasenotes/print.go | 16 +++++----------- pkg/releasenotes/releasenotes.go | 14 +++++++++----- pkg/releasenotes/statistics.go | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/pkg/releasenotes/print.go b/pkg/releasenotes/print.go index 66101fc..43aae2f 100644 --- a/pkg/releasenotes/print.go +++ b/pkg/releasenotes/print.go @@ -80,24 +80,18 @@ func (notes ReleaseNotes) Print(milestone string) error { var none []ReleaseNote for _, n := range notes { switch n.Typology { + case "BREAKING CHANGE": + breaking = append(breaking, n) case "fix": fixes = append(fixes, n) - break case "rule": rules = append(rules, n) - break - case "BREAKING CHANGE": - breaking = append(breaking, n) - break - case "new": + case "new", "feat": majors = append(majors, n) - break case "none": none = append(none, n) - break default: minors = append(minors, n) - break } } @@ -138,8 +132,8 @@ func (s *Statistics) Print() error { table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) table.SetCenterSeparator("|") - table.Append([]string{"Not user-facing", strconv.FormatInt(s.totalNone, 10)}) - table.Append([]string{"Release note", strconv.FormatInt(s.total-s.totalNone, 10)}) + table.Append([]string{"Not user-facing", strconv.FormatInt(s.nonFacing, 10)}) + table.Append([]string{"Release note", strconv.FormatInt(s.total-s.nonFacing, 10)}) table.Append([]string{"Total", strconv.FormatInt(s.total, 10)}) table.Render() // Send output diff --git a/pkg/releasenotes/releasenotes.go b/pkg/releasenotes/releasenotes.go index 74a9299..6b8a94b 100644 --- a/pkg/releasenotes/releasenotes.go +++ b/pkg/releasenotes/releasenotes.go @@ -13,7 +13,7 @@ import ( var ( releaseNoteRegexp = regexp.MustCompile("(?s)```release-note(.+?)```") - typologyRegexp = regexp.MustCompile(`(?m)(.+?)(\((.+)\))?: ?(.*)`) + typologyRegexp = regexp.MustCompile(`(?m)(.+?)(\((.+)\))?(!)?: ?(.*)`) ) const defaultGitHubBaseURI = "https://github.com" @@ -78,7 +78,7 @@ func (c *Client) Get(org, repo, branch, milestone string) (ReleaseNotes, *Statis var releaseNotes []ReleaseNote s := &Statistics{ total: 0, - totalNone: 0, + nonFacing: 0, authors: make(map[string]int64), } for _, p := range prs { @@ -106,8 +106,8 @@ func (c *Client) Get(org, repo, branch, milestone string) (ReleaseNotes, *Statis continue } note := strings.TrimSpace(res[1]) - if note == "NONE" || note == "none" { - s.totalNone++ + if strings.EqualFold(note, "NONE") { + s.nonFacing++ rn := ReleaseNote{ Typology: "none", Scope: "", @@ -120,11 +120,12 @@ func (c *Client) Get(org, repo, branch, milestone string) (ReleaseNotes, *Statis releaseNotes = append(releaseNotes, rn) continue } + notes := strings.Split(note, "\n") for _, n := range notes { n = strings.Trim(n, "\r") matches := typologyRegexp.FindStringSubmatch(n) - if len(matches) < 5 { + if len(matches) < 6 { return nil, nil, fmt.Errorf("error extracting type from release note, pr: %d", num) } @@ -137,6 +138,9 @@ func (c *Client) Get(org, repo, branch, milestone string) (ReleaseNotes, *Statis Author: fmt.Sprintf("@%s", p.GetUser().GetLogin()), AuthorURL: p.GetUser().GetHTMLURL(), } + if matches[4] == "!" { + rn.Typology = "BREAKING CHANGE" + } releaseNotes = append(releaseNotes, rn) } } diff --git a/pkg/releasenotes/statistics.go b/pkg/releasenotes/statistics.go index 4e63e86..91235cf 100644 --- a/pkg/releasenotes/statistics.go +++ b/pkg/releasenotes/statistics.go @@ -3,6 +3,6 @@ package releasenotes // Statistics represents counters about the merged in PRs. type Statistics struct { total int64 - totalNone int64 + nonFacing int64 authors map[string]int64 }