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

Check that MergeableState is clean for mergeable #163

Merged
merged 2 commits into from
Jan 3, 2025
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
8 changes: 6 additions & 2 deletions pkg/condition_ismergeable.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ func IsMergeableCondition() Condition {
if err != nil {
return false, fmt.Errorf("mergeable is not set in config")
}

// Check both the mergeable state and the mergeable flag
isMergeable := target.ghPR.GetMergeable() && target.ghPR.GetMergeableState() == "clean"

if b {
return target.ghPR.GetMergeable(), nil
return isMergeable, nil
}
return !target.ghPR.GetMergeable(), nil
return !isMergeable, nil
},
}
}
17 changes: 17 additions & 0 deletions pkg/labeler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,22 @@ func TestHandleEvent(t *testing.T) {
initialLabels: []string{"Meh"},
expectedLabels: []string{"Meh", "ShouldAppear"},
},
{
event: "pull_request",
payloads: []string{"create_pr_mergeable_not_clean"},
name: "Don't add label when PR is mergeable but state is not clean",
config: LabelerConfigV1{
Version: 1,
Labels: []LabelMatcher{
{
Label: "CanMerge",
Mergeable: "True",
},
},
},
initialLabels: []string{},
expectedLabels: []string{},
},
}

for _, tc := range testCases {
Expand All @@ -1059,6 +1075,7 @@ func TestHandleEvent(t *testing.T) {
fmt.Printf("Test `%s`: failed to load %s\n", tc.name, file)
t.Fatal(err)
}
fmt.Printf("Loaded payload: %s\n", string(payload))

fmt.Printf("--> TEST: %s \n", tc.name)
l := NewTestLabeler(t, tc)
Expand Down
41 changes: 41 additions & 0 deletions test_data/create_pr_mergeable_not_clean_payload
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"action": "opened",
"number": 1,
"pull_request": {
"number": 1,
"state": "open",
"locked": false,
"title": "Update test",
"user": {
"login": "srvaroa",
"type": "User"
},
"body": "Test PR",
"base": {
"repo": {
"name": "labeler",
"owner": {
"login": "srvaroa"
}
}
},
"created_at": "2019-05-24T22:03:59Z",
"updated_at": "2019-05-24T22:03:59Z",
"closed_at": null,
"merged_at": null,
"merge_commit_sha": null,
"assignee": null,
"assignees": [],
"requested_reviewers": [],
"requested_teams": [],
"labels": [],
"milestone": null,
"commits": 1,
"additions": 1,
"deletions": 1,
"changed_files": 1,
"mergeable": true,
"mergeable_state": "blocked",
"author_association": "OWNER"
}
}
Loading