Skip to content

Commit e712df5

Browse files
authored
fix(internal/gapicgen): move breaking change indicator if present (#5452)
This was discovered processing 8e91ed1. If a scope is present to be compliant with conventional commits the bang must be after the scope.
1 parent 93ccb57 commit e712df5

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

internal/gapicgen/git/git.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ func FormatChanges(changes []*ChangeInfo, onlyGapicChanges bool) string {
5959
if i := strings.Index(titleParts[0], "("); i > 0 {
6060
titleParts[0] = titleParts[0][:i]
6161
}
62-
titleParts[0] = fmt.Sprintf("%s(%s)", titleParts[0], c.Package)
62+
63+
var breakChangeIndicator string
64+
if strings.HasSuffix(titleParts[0], "!") {
65+
// If the change is marked as breaking we need to move the
66+
// bang to after the added scope.
67+
titleParts[0] = titleParts[0][:len(titleParts[0])-1]
68+
breakChangeIndicator = "!"
69+
}
70+
titleParts[0] = fmt.Sprintf("%s(%s)%s", titleParts[0], c.Package, breakChangeIndicator)
6371
}
6472
title = strings.Join(titleParts, ":")
6573
}

internal/gapicgen/git/git_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ func TestFormatChanges(t *testing.T) {
7373
changes: []*ChangeInfo{{Title: "fix: foo", Body: "bar", Package: "baz"}},
7474
want: "\nChanges:\n\nfix(baz): foo\n bar\n\n",
7575
},
76+
{
77+
name: "with package, breaking change",
78+
changes: []*ChangeInfo{{Title: "feat!: foo", Body: "bar", Package: "baz"}},
79+
want: "\nChanges:\n\nfeat(baz)!: foo\n bar\n\n",
80+
},
7681
{
7782
name: "multiple changes",
7883
changes: []*ChangeInfo{{Title: "fix: foo", Body: "bar", Package: "foo"}, {Title: "fix: baz", Body: "bar"}},

0 commit comments

Comments
 (0)