Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
noahdietz marked this conversation as resolved.
Show resolved Hide resolved
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)
}
}
}