Skip to content

Commit

Permalink
Allow opt in logins to be case insensitive
Browse files Browse the repository at this point in the history
Update main.test.ts for case insensitivity
  • Loading branch information
Hkly committed Jun 13, 2024
1 parent cb3a93a commit 4893ac4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,24 @@ describe('action', () => {
expect(setOutputMock).toHaveBeenNthCalledWith(2, 'category', 'extra small')
})

it('runs the workflow sucessfully regardless of casing of optIns and pull request author login', async () => {
// Mock the @actions/github context.
Object.defineProperty(github, 'context', {
value: pullRequestEventContext({ user: { login: 'LeReBeAr' } })
})

loadConfigurationMock.mockImplementation(() => ({
optIns: ['lerebear']
}))

await main.run()

expect(runMock).toHaveReturned()
expect(setFailedMock).not.toHaveBeenCalled()
expect(setOutputMock).toHaveBeenNthCalledWith(1, 'score', 1)
expect(setOutputMock).toHaveBeenNthCalledWith(2, 'category', 'extra small')
})

it('skips the workflow entirely when the pull request author has not opted into it', async () => {
// Mock the @actions/github context.
Object.defineProperty(github, 'context', {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

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

4 changes: 3 additions & 1 deletion src/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export function getOptInStatus(
const usersWhoHaveOptedin = config.optIns || []
const userHasOptedOut =
usersWhoHaveOptedin.length &&
!usersWhoHaveOptedin.find((login: string) => login === pull.user.login)
!usersWhoHaveOptedin.find(
(login: string) => login.toLowerCase() === pull.user.login.toLowerCase()
)

if (userHasOptedOut && config.shadowOptOuts) {
core.info('Executing workflow silently for user who was not opted in')
Expand Down

0 comments on commit 4893ac4

Please sign in to comment.