Skip to content

Commit

Permalink
handle caps states properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumatag committed Jul 6, 2022
1 parent 0ceb4dc commit 23e053d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mergeable/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 39 additions & 0 deletions mergeable/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}

0 comments on commit 23e053d

Please sign in to comment.