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

Allow anyone to approve #117

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

philn-delphia
Copy link

Make the approvers field optional, and allow anyone to approve if it's empty.

I had to rework approvalFromComments to make this work, since it worked by removing names from the required approvers list until the list was small enough.

closes #108

Anyone can approve except the workflow initiator if they're not allowed.
fix length of issue approvers
@trstringer
Copy link
Owner

What kind of testing did you do for this PR? And also thanks for contributing!

@zchenyu
Copy link

zchenyu commented Jul 18, 2024

bump, this would be a nice feature :)

@philn-delphia
Copy link
Author

What kind of testing did you do for this PR? And also thanks for contributing!

I've been using this internally with no issues, but honestly we always have it set to allow all reviewers since it's private repos.

@MichalLeszczynski
Copy link

Hello, bumping as it'd be really helpful for me. Is there anything blocking us from merging it?

@@ -6,7 +6,7 @@ branding:
inputs:
approvers:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add your input here

approverIdx := approversIndex(remainingApprovers, commentUser)
if approverIdx < 0 {

if approversIndex(disallowedUsers, commentUser) >= 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nonApprovers is a little more concise and clear

@@ -162,7 +163,7 @@ func TestApprovalFromComments(t *testing.T) {

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
actual, err := approvalFromComments(testCase.comments, testCase.approvers, testCase.minimumApprovals)
actual, err := approvalFromComments(testCase.comments, testCase.approvers, testCase.minimumApprovals, testCase.disallowedUsers)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would like to see a test for this specifically - as well as a test for if the same user is in the disallowed and allowed lists

@@ -6,7 +6,7 @@ branding:
inputs:
approvers:
description: Required approvers
required: true
required: false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest keeping this field as required and adding a keyword for your use case.
If we have a keyword instead of an empty field it could save potential security catastrophies caused by a mere oversight.

@@ -54,14 +56,19 @@ func (a *approvalEnvironment) createApprovalIssue(ctx context.Context) error {
issueTitle = fmt.Sprintf("%s: %s", issueTitle, a.issueTitle)
}

issueApproversText := "Anyone can approve."
if len(a.issueApprovers) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of overwriting a variable, it would be better to use if...else.

}

approvers := []string{}
requiredApproversRaw := os.Getenv(envVarApprovers)
requiredApprovers := strings.Split(requiredApproversRaw, ",")
requiredApprovers := []string{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of overwriting a variable, it would be better to use if...else.

@snskArora
Copy link
Collaborator

Also, please rebase on the main branch to account the new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Let anyone approve an issue
6 participants