Skip to content
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
27 changes: 27 additions & 0 deletions __tests__/functions/trigger-check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ test('checks a message and finds a global trigger', async () => {
const body = 'I want to .deploy'
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(false)
expect(debugMock).toHaveBeenCalledWith(
`comment body does not start with trigger: ${color}.deploy${colorReset}`
)
})

test('checks a message and finds a trigger with an environment and a variable', async () => {
Expand All @@ -52,3 +55,27 @@ test('checks a message and does not find global trigger', async () => {
`comment body does not start with trigger: ${color}.deploy${colorReset}`
)
})

test('does not match when body starts with a longer command sharing prefix', async () => {
const body = '.deploy-two to prod'
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(false)
expect(debugMock).toHaveBeenCalledWith(
`comment body starts with trigger but is not complete: ${color}.deploy${colorReset}`
)
})

test('does not match when immediately followed by alphanumeric', async () => {
const body = '.deploy1'
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(false)
expect(debugMock).toHaveBeenCalledWith(
`comment body starts with trigger but is not complete: ${color}.deploy${colorReset}`
)
})

test('matches when followed by a newline (whitespace)', async () => {
const body = `.deploy\ndev`
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(true)
})
9 changes: 9 additions & 0 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: 9 additions & 0 deletions src/functions/trigger-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ export async function triggerCheck(body, trigger) {
return false
}

// Ensure the trigger match is complete: either end-of-string or followed by whitespace
const nextChar = body[trigger.length]
if (nextChar && !/\s/.test(nextChar)) {
core.debug(
`comment body starts with trigger but is not complete: ${COLORS.highlight}${trigger}${COLORS.reset}`
)
return false
}

core.info(
`✅ comment body starts with trigger: ${COLORS.highlight}${trigger}${COLORS.reset}`
)
Expand Down