From 0388d8cd9a7e6a618633a977ae322eaeba85538a Mon Sep 17 00:00:00 2001 From: Philip Nicolcev Date: Tue, 3 Mar 2026 15:38:13 -0800 Subject: [PATCH] Fix error when no approvers are specified When both approvers and minimumApprovals are unset (the "anyone can approve" case), default minimumApprovals to 1 instead of returning an error. --- approval.go | 5 +++-- approval_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/approval.go b/approval.go index 1e41e89..ccc0278 100644 --- a/approval.go +++ b/approval.go @@ -105,9 +105,10 @@ func approvalFromComments(comments []*github.IssueComment, approvers []string, m if minimumApprovals == 0 { if len(approvers) == 0 { - return "", fmt.Errorf("error: no required approvers or minimum approvals set") + minimumApprovals = 1 + } else { + minimumApprovals = len(approvers) } - minimumApprovals = len(approvers) } for _, comment := range comments { diff --git a/approval_test.go b/approval_test.go index 1c99e5c..39d5335 100644 --- a/approval_test.go +++ b/approval_test.go @@ -159,6 +159,34 @@ func TestApprovalFromComments(t *testing.T) { expectedStatus: approvalStatusPending, minimumApprovals: 2, }, + { + name: "no_approvers_anyone_can_approve", + comments: []*github.IssueComment{ + { + User: &github.User{Login: &login1}, + Body: &bodyApproved, + }, + }, + approvers: []string{}, + expectedStatus: approvalStatusApproved, + }, + { + name: "no_approvers_anyone_can_deny", + comments: []*github.IssueComment{ + { + User: &github.User{Login: &login1}, + Body: &bodyDenied, + }, + }, + approvers: []string{}, + expectedStatus: approvalStatusDenied, + }, + { + name: "no_approvers_pending_when_no_comments", + comments: []*github.IssueComment{}, + approvers: []string{}, + expectedStatus: approvalStatusPending, + }, } for _, testCase := range testCases {