Skip to content

Commit

Permalink
Merge pull request #190 from github/addtional-msg-formatting
Browse files Browse the repository at this point in the history
Additional msg formatting
  • Loading branch information
GrantBirki committed Aug 18, 2023
2 parents ff27077 + 26c4e78 commit 3b1e6d2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 52 deletions.
7 changes: 5 additions & 2 deletions __tests__/functions/admin.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {isAdmin} from '../../src/functions/admin'
import {COLORS} from '../../src/functions/colors'
import * as github from '@actions/github'
import * as core from '@actions/core'

const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {})
const warningMock = jest.spyOn(core, 'warning').mockImplementation(() => {})
// const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})

class NotFoundError extends Error {
constructor(message) {
Expand All @@ -23,6 +25,7 @@ var context
var octokit
beforeEach(() => {
jest.clearAllMocks()
jest.spyOn(core, 'info').mockImplementation(() => {})
process.env.INPUT_ADMINS_PAT = 'faketoken'
process.env.INPUT_ADMINS =
'MoNaLiSa,@lisamona,octoawesome/octo-awEsome-team,bad$user'
Expand Down Expand Up @@ -75,7 +78,7 @@ test('runs isAdmin checks for an org team and fails due to no admins_pat', async
process.env.INPUT_ADMINS = 'octoawesome/octo-awesome'
expect(await isAdmin(context)).toStrictEqual(false)
expect(warningMock).toHaveBeenCalledWith(
'No admins_pat provided, skipping admin check for org team membership'
`🚨 no ${COLORS.highlight}admins_pat${COLORS.reset} provided, skipping admin check for org team membership`
)
})

Expand Down Expand Up @@ -219,6 +222,6 @@ test('runs isAdmin checks for an org team and an unexpected error is thrown from
expect(await isAdmin(context)).toStrictEqual(false)
expect(debugMock).toHaveBeenCalledWith('monalisa is not an admin')
expect(warningMock).toHaveBeenCalledWith(
'Error checking org team membership: Error: something went boom'
'error checking org team membership: Error: something went boom'
)
})
7 changes: 4 additions & 3 deletions __tests__/functions/post-deploy.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {postDeploy} from '../../src/functions/post-deploy'
import {COLORS} from '../../src/functions/colors'
import * as actionStatus from '../../src/functions/action-status'
import * as lock from '../../src/functions/lock'
import * as unlock from '../../src/functions/unlock'
Expand Down Expand Up @@ -260,7 +261,7 @@ test('successfully completes a production branch deployment and removes a non-st
'' // environment_url
)
expect(infoMock).toHaveBeenCalledWith(
'non-sticky lock detected, will remove lock'
`🧹 ${COLORS.highlight}non-sticky${COLORS.reset} lock detected, will remove lock`
)
})

Expand Down Expand Up @@ -308,7 +309,7 @@ test('successfully completes a noop branch deployment and removes a non-sticky l
true
)
expect(infoMock).toHaveBeenCalledWith(
'non-sticky lock detected, will remove lock'
`🧹 ${COLORS.highlight}non-sticky${COLORS.reset} lock detected, will remove lock`
)
})

Expand Down Expand Up @@ -353,7 +354,7 @@ test('successfully completes a noop branch deployment but does not get any lock
true
)
expect(warningMock).toHaveBeenCalledWith(
'a request to obtain the lock data returned null or undefined - the lock may have been removed by another process while this Action was running'
'💡 a request to obtain the lock data returned null or undefined - the lock may have been removed by another process while this Action was running'
)
})

Expand Down
58 changes: 35 additions & 23 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.

9 changes: 7 additions & 2 deletions src/functions/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from '@actions/core'
import * as github from '@actions/github'
import githubUsernameRegex from 'github-username-regex'
import {octokitRetry} from '@octokit/plugin-retry'
import {COLORS} from './colors'

// Helper function to check if a user exists in an org team
// :param actor: The user to check
Expand All @@ -14,7 +15,7 @@ async function orgTeamCheck(actor, orgTeams) {
// If no admin_pat is provided, then we cannot check for org team memberships
if (!adminsPat || adminsPat.length === 0 || adminsPat === 'false') {
core.warning(
'No admins_pat provided, skipping admin check for org team membership'
`🚨 no ${COLORS.highlight}admins_pat${COLORS.reset} provided, skipping admin check for org team membership`
)
return false
}
Expand Down Expand Up @@ -62,7 +63,7 @@ async function orgTeamCheck(actor, orgTeams) {
core.debug(`${actor} is not a member of the ${orgTeam} team`)
// If some other error occured, output a warning
} else {
core.warning(`Error checking org team membership: ${error}`)
core.warning(`error checking org team membership: ${error}`)
}
}
}
Expand Down Expand Up @@ -107,9 +108,12 @@ export async function isAdmin(context) {
}
})

const isAdminMsg = `🔮 ${COLORS.highlight}${context.actor}${COLORS.reset} is an ${COLORS.highlight}admin`

// Check if the user is in the admin handle list
if (handles.includes(context.actor.toLowerCase())) {
core.debug(`${context.actor} is an admin via handle reference`)
core.info(isAdminMsg)
return true
}

Expand All @@ -118,6 +122,7 @@ export async function isAdmin(context) {
const result = await orgTeamCheck(context.actor, orgTeams)
if (result) {
core.debug(`${context.actor} is an admin via org team reference`)
core.info(isAdminMsg)
return true
}
}
Expand Down
Loading

0 comments on commit 3b1e6d2

Please sign in to comment.