Skip to content

Commit

Permalink
fix(pkg): properly support "!" for breaking changes.
Browse files Browse the repository at this point in the history
Moreover, "feat" is also a valid feature prefix name.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP authored and leodido committed Sep 26, 2023
1 parent 1a17f0e commit 0669e5f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
16 changes: 5 additions & 11 deletions pkg/releasenotes/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions pkg/releasenotes/releasenotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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: "",
Expand All @@ -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)
}

Expand All @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/releasenotes/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 0669e5f

Please sign in to comment.