diff --git a/mergeable/plugin/plugin.go b/mergeable/plugin/plugin.go index d9bf53c..2da5cfc 100644 --- a/mergeable/plugin/plugin.go +++ b/mergeable/plugin/plugin.go @@ -229,8 +229,20 @@ func takeAction(ghc githubClient, org, repo string, num int, author string, hasL return nil } +func isMergeable(state *string) bool { + // returns true if state is nil or empty string + if state == nil || *state == "" { + return true + } + lstate := strings.ToLower(*state) + if lstate != "has_hooks" && lstate != "clean" && lstate != "unstable" { + return false + } + return true +} + func takeActionWithContext(ctx context.Context, ghc githubClient, org, repo string, num int, author string, hasLabel, mergeable bool, state *string) error { - if state != nil && *state != "" && *state != "HAS_HOOKS" && *state != "CLEAN" && *state != "UNSTABLE" { + if !isMergeable(state) { mergeable = false } if !mergeable { diff --git a/mergeable/plugin/plugin_test.go b/mergeable/plugin/plugin_test.go index 24544cf..b327bf0 100644 --- a/mergeable/plugin/plugin_test.go +++ b/mergeable/plugin/plugin_test.go @@ -655,3 +655,42 @@ func TestCache(t *testing.T) { } } } + +func Test_isMergeable(t *testing.T) { + emptyState := "" + blockedState := "BLOCKED" + lowerBlockedState := "blocked" + tests := []struct { + name string + state *string + want bool + }{ + { + name: "nil state", + state: nil, + want: true, + }, + { + name: "empty state", + state: &emptyState, + want: true, + }, + { + name: "blocked state", + state: &blockedState, + want: false, + }, + { + name: "lower blocked state", + state: &lowerBlockedState, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := isMergeable(tt.state); got != tt.want { + t.Errorf("isMergeable() = %v, want %v", got, tt.want) + } + }) + } +}