Skip to content

Commit

Permalink
chore(internal/apidiff): check for bang breaking change indicator (#3840
Browse files Browse the repository at this point in the history
)

* chore(internal/apidiff): check for bang breaking change indicator

* fix breaking change tag

* add test for checkAllowBreakingChange
  • Loading branch information
noahdietz committed Mar 19, 2021
1 parent dd15ef6 commit a58a0e6
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/apidiff/apidiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func main() {
if err != nil {
log.Fatalln(err)
}
if strings.Contains(head, "BREAKING_CHANGE") {
log.Println("Not running apidiff because description contained tag BREAKING_CHANGE.")
if checkAllowBreakingChange(head) {
return
}

Expand Down Expand Up @@ -215,6 +214,23 @@ func diff(m manifest, modDir, imp, pkg, base string) (string, error) {
return out, err
}

func checkAllowBreakingChange(commit string) bool {
if strings.Contains(commit, "BREAKING CHANGE:") {
log.Println("Not running apidiff because description contained tag BREAKING_CHANGE.")
return true
}

split := strings.Split(commit, "\n")
for _, s := range split {
if strings.Contains(s, "!:") || strings.Contains(s, "!(") {
log.Println("Not running apidiff because description contained breaking change indicator '!'.")
return true
}
}

return false
}

func manualParent(m manifest, imp string) string {
pkg := strings.TrimPrefix(imp, rootMod)
split := strings.Split(pkg, "/")
Expand Down
65 changes: 65 additions & 0 deletions internal/apidiff/apidiff_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build linux darwin

package main

import "testing"

func TestCheckAllowBreakingChange(t *testing.T) {
for _, tst := range []struct {
name, msg string
want bool
}{
{
name: "disallow - no indicator",
msg: "feat: add foo",
want: false,
},
{
name: "allow - bang indicator",
msg: "feat!: remove foo",
want: true,
},
{
name: "allow - bang indicator pre-scope",
msg: "feat!(scope): remove foo",
want: true,
},
{
name: "allow - tag indicator",
msg: "BREAKING CHANGE: remove foo",
want: true,
},
{
name: "allow - multiline bang indicator",
msg: `feat: add foo
feat!: remove bar
chore: update dep`,
want: true,
},
{
name: "allow - multiline tag indicator",
msg: `feat: add foo
BREAKING CHANGE: remove bar
chore: update dep`,
want: true,
},
} {
if got := checkAllowBreakingChange(tst.msg); got != tst.want {
t.Errorf("%s: got %v want %v", tst.name, got, tst.want)
}
}
}

0 comments on commit a58a0e6

Please sign in to comment.