Skip to content

Commit c368ee1

Browse files
authored
Disable updates if there is no whitelist or blacklist (#61)
1 parent 0809cf2 commit c368ee1

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

bulldozer/update.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import (
2828
func ShouldUpdatePR(ctx context.Context, pullCtx pull.Context, updateConfig UpdateConfig) (bool, error) {
2929
logger := zerolog.Ctx(ctx)
3030

31+
if !updateConfig.Blacklist.Enabled() && !updateConfig.Whitelist.Enabled() {
32+
return false, nil
33+
}
34+
3135
if updateConfig.Blacklist.Enabled() {
3236
blacklisted, reason, err := IsPRBlacklisted(ctx, pullCtx, updateConfig.Blacklist)
3337
if err != nil {

bulldozer/update_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2018 Palantir Technologies, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package bulldozer
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"testing"
21+
22+
"github.com/stretchr/testify/require"
23+
24+
"github.com/palantir/bulldozer/pull"
25+
"github.com/palantir/bulldozer/pull/pulltest"
26+
)
27+
28+
func TestShouldUpdatePR(t *testing.T) {
29+
ctx := context.Background()
30+
testMatrix := []struct {
31+
blacklistEnabled bool
32+
blacklisted bool
33+
whitelistEnabled bool
34+
whitelisted bool
35+
expectingUpdate bool
36+
}{
37+
{false, false, false, false, false},
38+
{false, false, false, true, false},
39+
{false, false, true, false, false},
40+
{false, false, true, true, true},
41+
{false, true, false, false, false},
42+
{false, true, false, true, false},
43+
{false, true, true, false, false},
44+
{false, true, true, true, true},
45+
{true, false, false, false, true},
46+
{true, false, false, true, true},
47+
{true, false, true, false, false},
48+
{true, false, true, true, true},
49+
{true, true, false, false, false},
50+
{true, true, false, true, false},
51+
{true, true, true, false, false},
52+
{true, true, true, true, false},
53+
}
54+
55+
for ndx, testCase := range testMatrix {
56+
pullCtx, updateConfig := generateUpdateTestCase(testCase.blacklistEnabled, testCase.blacklisted, testCase.whitelistEnabled, testCase.whitelisted)
57+
updating, err := ShouldUpdatePR(ctx, pullCtx, updateConfig)
58+
require.NoError(t, err)
59+
msg := fmt.Sprintf("case %d - blacklistEnabled=%t blacklisted=%t whitelistEnabled=%t whitelisted=%t -> doUpdate=%t",
60+
ndx, testCase.blacklistEnabled, testCase.blacklisted, testCase.whitelistEnabled, testCase.whitelisted, testCase.expectingUpdate)
61+
require.Equal(t, testCase.expectingUpdate, updating, msg)
62+
}
63+
}
64+
func generateUpdateTestCase(blacklistable bool, blacklisted bool, whitelistable bool, whitelisted bool) (pull.Context, UpdateConfig) {
65+
updateConfig := UpdateConfig{}
66+
pullCtx := pulltest.MockPullContext{}
67+
68+
if blacklistable {
69+
updateConfig.Blacklist.Labels = append(updateConfig.Blacklist.Labels, "blacklist")
70+
}
71+
72+
if blacklisted {
73+
pullCtx.LabelValue = append(pullCtx.LabelValue, "blacklist")
74+
}
75+
76+
if whitelistable {
77+
updateConfig.Whitelist.Labels = append(updateConfig.Whitelist.Labels, "whitelist")
78+
}
79+
80+
if whitelisted {
81+
pullCtx.LabelValue = append(pullCtx.LabelValue, "whitelist")
82+
}
83+
84+
return &pullCtx, updateConfig
85+
}

0 commit comments

Comments
 (0)