Skip to content

Commit

Permalink
Merge pull request #30 from jcfr/support-allowlist-for-both-issue-and-pr
Browse files Browse the repository at this point in the history
fix: Ensure allowlist is also checked in the context of issue
  • Loading branch information
GrantBirki committed May 9, 2024
2 parents f16582e + 576eba0 commit d975bd0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
16 changes: 16 additions & 0 deletions __tests__/functions/prechecks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,22 @@ test('runs prechecks and finds that the user is not an allowed operator', async
message: `### ⚠️ Cannot proceed with operation\n\n> User monalisa is not an allowed operator`,
status: false
})

expect(
await prechecks(
'123',
true,
false, // skip_ci
true, // skip_reviews
false, // allow_drafts
'issue', // contextType
context,
octokit
)
).toStrictEqual({
message: `### ⚠️ Cannot proceed with operation\n\n> User monalisa is not an allowed operator`,
status: false
})
})

test('runs prechecks and finds that skip_ci is set and no reviews are defined', async () => {
Expand Down
12 changes: 6 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/functions/prechecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export async function prechecks(
return {message: validPermissionsRes, status: false}
}

// Get allowed operator data
if (!(await isAllowed(context))) {
message = `### ⚠️ Cannot proceed with operation\n\n> User ${context.actor} is not an allowed operator`
return {message: message, status: false}
}

// if this is an issue comment, we can skip all the logic below here as it...
// ... only applies to pull requests
if (contextType === 'issue') {
Expand Down Expand Up @@ -189,12 +195,6 @@ export async function prechecks(
}
}

// Get allowed operator data
if (!(await isAllowed(context))) {
message = `### ⚠️ Cannot proceed with operation\n\n> User ${context.actor} is not an allowed operator`
return {message: message, status: false}
}

// log values for debugging
core.debug('precheck values for debugging:')
core.debug(`reviewDecision: ${reviewDecision}`)
Expand Down

0 comments on commit d975bd0

Please sign in to comment.