Skip to content

Commit

Permalink
set output 'comment_body' in main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Aug 17, 2023
1 parent 2ca4fa6 commit 90f2610
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 36 deletions.
27 changes: 0 additions & 27 deletions __tests__/functions/trigger-check.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {triggerCheck} from '../../src/functions/trigger-check'
import * as core from '@actions/core'

const setOutputMock = jest.spyOn(core, 'setOutput')
const infoMock = jest.spyOn(core, 'info')
const debugMock = jest.spyOn(core, 'debug')

beforeEach(() => {
jest.clearAllMocks()
jest.spyOn(core, 'setOutput').mockImplementation(() => {})
jest.spyOn(core, 'saveState').mockImplementation(() => {})
jest.spyOn(core, 'info').mockImplementation(() => {})
jest.spyOn(core, 'debug').mockImplementation(() => {})
Expand All @@ -17,7 +15,6 @@ test('checks a message and finds a standard trigger', async () => {
const body = '.deploy'
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(true)
expect(setOutputMock).toHaveBeenCalledWith('comment_body', '.deploy')
expect(infoMock).toHaveBeenCalledWith(
'✅ comment body starts with trigger: ".deploy"'
)
Expand All @@ -27,7 +24,6 @@ test('checks a message and does not find trigger', async () => {
const body = '.bad'
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(false)
expect(setOutputMock).toHaveBeenCalledWith('comment_body', '.bad')
expect(debugMock).toHaveBeenCalledWith(
'comment body does not start with trigger: ".deploy"'
)
Expand All @@ -42,38 +38,15 @@ test('checks a message and finds a global trigger', async () => {
test('checks a message and finds a trigger with an environment and a variable', async () => {
const trigger = '.deploy'
expect(await triggerCheck('.deploy dev something', trigger)).toBe(true)
expect(setOutputMock).toHaveBeenCalledWith(
'comment_body',
'.deploy dev something'
)

expect(await triggerCheck('.deploy something', trigger)).toBe(true)
expect(setOutputMock).toHaveBeenCalledWith(
'comment_body',
'.deploy dev something'
)

expect(await triggerCheck('.deploy dev something', trigger)).toBe(true)
expect(setOutputMock).toHaveBeenCalledWith(
'comment_body',
'.deploy dev something'
)

expect(await triggerCheck('.deploy dev something', trigger)).toBe(true)
expect(setOutputMock).toHaveBeenCalledWith(
'comment_body',
'.deploy dev something'
)
})

test('checks a message and does not find global trigger', async () => {
const body = 'I want to .ping a website'
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(false)
expect(setOutputMock).toHaveBeenCalledWith(
'comment_body',
'I want to .ping a website'
)
expect(debugMock).toHaveBeenCalledWith(
'comment body does not start with trigger: ".deploy"'
)
Expand Down
8 changes: 4 additions & 4 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.

5 changes: 1 addition & 4 deletions src/functions/trigger-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import * as core from '@actions/core'

// A simple function that checks the body of the message against the trigger
// :param body: The content body of the message being checked (String)
// :param trigger: The "trigger" phrase which is searched for in the body of the message
// :param trigger: The "trigger" phrase which is searched for in the body of the message (String)
// :returns: true if a message activates the trigger, false otherwise
export async function triggerCheck(body, trigger) {
// Set the output of the comment body for later use with other actions
core.setOutput('comment_body', body)

// If the trigger is not activated, set the output to false and return with false
if (!body.startsWith(trigger)) {
core.debug(`comment body does not start with trigger: "${trigger}"`)
Expand Down
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export async function run() {
const issue_number = context.payload.issue.number
const {owner, repo} = context.repo

// Set the output of the comment body for later use with other actions
core.setOutput('comment_body', body)

// Check if the comment is a trigger and what type of trigger it is
const isDeploy = await triggerCheck(body, trigger)
const isNoopDeploy = await triggerCheck(body, noop_trigger)
Expand Down

0 comments on commit 90f2610

Please sign in to comment.