Skip to content

Commit 94f5613

Browse files
committed
test with regexCommandWithParameters for issueops commands with environment targets
1 parent fc09997 commit 94f5613

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

__tests__/functions/prechecks.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,3 +1423,52 @@ test('runs prechecks and finds that the IssueOps commands are valid and from a d
14231423
status: true
14241424
})
14251425
})
1426+
1427+
test('runs prechecks and finds that the IssueOps commands are valid with parameters and from a defined admin', async () => {
1428+
var octogoodres = octokit
1429+
octogoodres['rest']['repos']['getCollaboratorPermissionLevel'] = jest
1430+
.fn()
1431+
.mockReturnValueOnce({data: {permission: 'admin'}, status: 200})
1432+
octogoodres['graphql'] = jest.fn().mockReturnValue({
1433+
repository: {
1434+
pullRequest: {
1435+
reviewDecision: 'REVIEW_REQUIRED',
1436+
commits: {
1437+
nodes: [
1438+
{
1439+
commit: {
1440+
statusCheckRollup: {
1441+
state: 'SUCCESS'
1442+
}
1443+
}
1444+
}
1445+
]
1446+
}
1447+
}
1448+
}
1449+
})
1450+
jest.spyOn(isAdmin, 'isAdmin').mockImplementation(() => {
1451+
return true
1452+
})
1453+
expect(
1454+
await prechecks(
1455+
'.deploy to production',
1456+
'.deploy',
1457+
'noop',
1458+
'disabled',
1459+
'main',
1460+
'123',
1461+
true,
1462+
context,
1463+
octogoodres
1464+
)
1465+
).toStrictEqual({
1466+
message:
1467+
'✔️ CI is passing and approval is bypassed due to admin rights - OK',
1468+
noopMode: false,
1469+
ref: 'test-ref',
1470+
status: true
1471+
})
1472+
1473+
expect(infoMock).toHaveBeenCalledWith('issueops command used with parameters')
1474+
})

dist/index.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/prechecks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export async function prechecks(
5858
'i'
5959
)
6060
const regexCommandWithoutParameters = new RegExp(`^\\${trigger}\\s*$`, 'i')
61+
const regexCommandWithParameters = new RegExp(`^\\${trigger}\\s+.*$`, 'i')
6162

6263
// Check to see if the "stable" branch was used as the deployment target
6364
if (regexCommandWithStableBranch.test(comment)) {
@@ -77,6 +78,9 @@ export async function prechecks(
7778
core.info(
7879
`${trigger} command used on current branch - setting ref to ${ref}`
7980
)
81+
// Check to see if the IssueOps command was used in a basic form with other params
82+
} else if (regexCommandWithParameters.test(comment)) {
83+
core.info(`issueops command used with parameters`)
8084
// If no regex patterns matched, the IssueOps command was used in an unsupported way
8185
} else {
8286
message = dedent(`

0 commit comments

Comments
 (0)