Skip to content

Handle GitHub EMU usernames #15

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

Merged
merged 3 commits into from
Dec 2, 2023
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
22 changes: 22 additions & 0 deletions __tests__/functions/allowlist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ test('runs isAllowed checks and finds a valid admin via handle reference', async
)
})

test('runs isAllowed checks and finds a valid handle that is a GitHub EMU', async () => {
process.env.INPUT_ALLOWLIST = 'username_company'
const contextNoAdmin = {
actor: 'username_company'
}
expect(await isAllowed(contextNoAdmin)).toStrictEqual(true)
expect(debugMock).toHaveBeenCalledWith(
'username_company is an allowlisted operator via handle reference'
)
})

test('runs isAllowed checks and does not find a valid admin', async () => {
process.env.INPUT_ALLOWLIST = 'monalisa'
const contextNoAdmin = {
Expand All @@ -72,6 +83,17 @@ test('runs isAllowed checks and does not find a valid admin', async () => {
)
})

test('runs isAllowed checks and does not find a valid admin due to a bad GitHub handle', async () => {
process.env.INPUT_ALLOWLIST = 'mona%lisa-'
const contextNoAdmin = {
actor: 'mona%lisa-'
}
expect(await isAllowed(contextNoAdmin)).toStrictEqual(false)
expect(debugMock).toHaveBeenCalledWith(
'mona%lisa- is not a valid GitHub username... skipping allowlist check'
)
})

test('runs isAllowed checks and determines that all users are allowed because it is unset', async () => {
process.env.INPUT_ALLOWLIST = 'false'
expect(await isAllowed(context)).toStrictEqual(true)
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.

124 changes: 123 additions & 1 deletion dist/licenses.txt

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

8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@actions/github": "^6.0.0",
"@octokit/plugin-retry": "^6.0.1",
"dedent-js": "^1.0.1",
"github-username-regex": "^1.0.0"
"github-username-regex-js": "^1.0.0"
},
"jest": {
"coverageReporters": [
Expand Down
2 changes: 1 addition & 1 deletion src/functions/allowlist.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import githubUsernameRegex from 'github-username-regex'
import githubUsernameRegex from 'github-username-regex-js'

// Helper function to check if a user exists in an org team
// :param actor: The user to check
Expand Down