Skip to content

Commit

Permalink
Disable updates if there is no whitelist or blacklist (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcampanini authored Nov 14, 2018
1 parent 0809cf2 commit c368ee1
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bulldozer/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import (
func ShouldUpdatePR(ctx context.Context, pullCtx pull.Context, updateConfig UpdateConfig) (bool, error) {
logger := zerolog.Ctx(ctx)

if !updateConfig.Blacklist.Enabled() && !updateConfig.Whitelist.Enabled() {
return false, nil
}

if updateConfig.Blacklist.Enabled() {
blacklisted, reason, err := IsPRBlacklisted(ctx, pullCtx, updateConfig.Blacklist)
if err != nil {
Expand Down
85 changes: 85 additions & 0 deletions bulldozer/update_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2018 Palantir Technologies, Inc.
//
// 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.

package bulldozer

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/require"

"github.com/palantir/bulldozer/pull"
"github.com/palantir/bulldozer/pull/pulltest"
)

func TestShouldUpdatePR(t *testing.T) {
ctx := context.Background()
testMatrix := []struct {
blacklistEnabled bool
blacklisted bool
whitelistEnabled bool
whitelisted bool
expectingUpdate bool
}{
{false, false, false, false, false},
{false, false, false, true, false},
{false, false, true, false, false},
{false, false, true, true, true},
{false, true, false, false, false},
{false, true, false, true, false},
{false, true, true, false, false},
{false, true, true, true, true},
{true, false, false, false, true},
{true, false, false, true, true},
{true, false, true, false, false},
{true, false, true, true, true},
{true, true, false, false, false},
{true, true, false, true, false},
{true, true, true, false, false},
{true, true, true, true, false},
}

for ndx, testCase := range testMatrix {
pullCtx, updateConfig := generateUpdateTestCase(testCase.blacklistEnabled, testCase.blacklisted, testCase.whitelistEnabled, testCase.whitelisted)
updating, err := ShouldUpdatePR(ctx, pullCtx, updateConfig)
require.NoError(t, err)
msg := fmt.Sprintf("case %d - blacklistEnabled=%t blacklisted=%t whitelistEnabled=%t whitelisted=%t -> doUpdate=%t",
ndx, testCase.blacklistEnabled, testCase.blacklisted, testCase.whitelistEnabled, testCase.whitelisted, testCase.expectingUpdate)
require.Equal(t, testCase.expectingUpdate, updating, msg)
}
}
func generateUpdateTestCase(blacklistable bool, blacklisted bool, whitelistable bool, whitelisted bool) (pull.Context, UpdateConfig) {
updateConfig := UpdateConfig{}
pullCtx := pulltest.MockPullContext{}

if blacklistable {
updateConfig.Blacklist.Labels = append(updateConfig.Blacklist.Labels, "blacklist")
}

if blacklisted {
pullCtx.LabelValue = append(pullCtx.LabelValue, "blacklist")
}

if whitelistable {
updateConfig.Whitelist.Labels = append(updateConfig.Whitelist.Labels, "whitelist")
}

if whitelisted {
pullCtx.LabelValue = append(pullCtx.LabelValue, "whitelist")
}

return &pullCtx, updateConfig
}

0 comments on commit c368ee1

Please sign in to comment.