Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: checks input option is not respecting required checks in the pending state #363

Merged
merged 4 commits into from
Jan 29, 2025
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
186 changes: 160 additions & 26 deletions __tests__/functions/prechecks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ test('runs prechecks and finds that the IssueOps command is valid for a branch d
isFork: false
})

expect(debugMock).toHaveBeenCalledWith('ignoring ci check: markdown-lint')
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: markdown-lint'
)
})

test('runs prechecks and finds that the IssueOps command is valid for a branch deployment with a few explictly requested checks and a few ignored checks', async () => {
Expand Down Expand Up @@ -375,13 +377,113 @@ test('runs prechecks and finds that the IssueOps command is valid for a branch d
isFork: false
})

expect(debugMock).toHaveBeenCalledWith('explicitly including ci check: test')
expect(debugMock).toHaveBeenCalledWith(
'explicitly including ci check: acceptance-test'
'filterChecks() - explicitly including ci check: test'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - explicitly including ci check: acceptance-test'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - explicitly including ci check: lint'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - markdown-lint is not in the explicit list of checks to include (test,acceptance-test,lint)'
)
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: markdown-lint'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: lint'
)
})

test('runs prechecks and finds that the IssueOps command is valid for a branch deployment with a few explictly requested checks and a few ignored checks but one CI check is missing', async () => {
octokit.graphql = jest.fn().mockReturnValue({
repository: {
pullRequest: {
reviewDecision: 'APPROVED',
mergeStateStatus: 'CLEAN',
reviews: {
totalCount: 1
},
commits: {
nodes: [
{
commit: {
oid: 'abc123',
checkSuites: {
totalCount: 5
},
statusCheckRollup: {
state: 'FAILURE',
contexts: {
nodes: [
{
isRequired: true,
conclusion: 'SUCCESS',
name: 'test'
},
{
isRequired: false,
conclusion: 'SUCCESS',
name: 'acceptance-test'
},
{
isRequired: true,
conclusion: 'SKIPPED',
name: 'lint'
},
{
isRequired: false,
conclusion: 'FAILURE',
name: 'build'
},
{
isRequired: true,
conclusion: 'FAILURE',
name: 'markdown-lint'
}
]
}
}
}
}
]
}
}
}
})

data.inputs.checks = ['test', 'acceptance-test', 'quality-control', 'lint']
data.inputs.ignored_checks = ['lint']

expect(await prechecks(context, octokit, data)).toStrictEqual({
message:
'### ⚠️ Cannot proceed with deployment\n\n- reviewDecision: `APPROVED`\n- commitStatus: `MISSING`\n\n> The `checks` input option requires that all of the following checks are passing: `test,acceptance-test,quality-control,lint`. However, the following checks are missing: `quality-control`',
status: false
})

expect(warningMock).toHaveBeenCalledWith(
`the ${COLORS.info}checks${COLORS.reset} input option requires that all of the following checks are passing: ${COLORS.highlight}${data.inputs.checks.join(', ')}${COLORS.reset} - however, the following checks are missing: ${COLORS.highlight}quality-control${COLORS.reset}`
)
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - explicitly including ci check: test'
)
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - explicitly including ci check: acceptance-test'
)
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - explicitly including ci check: lint'
)
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - markdown-lint is not in the explicit list of checks to include (test,acceptance-test,lint)'
)
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: markdown-lint'
)
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: lint'
)
expect(debugMock).toHaveBeenCalledWith('explicitly including ci check: lint')
expect(debugMock).not.toHaveBeenCalledWith('ignoring ci check: markdown-lint')
expect(debugMock).toHaveBeenCalledWith('ignoring ci check: lint')
})

test('runs prechecks and finds that the IssueOps command is valid for a branch deployment but checks and ignore checks cancel eachother out', async () => {
Expand Down Expand Up @@ -465,22 +567,38 @@ test('runs prechecks and finds that the IssueOps command is valid for a branch d
isFork: false
})

expect(debugMock).toHaveBeenCalledWith('explicitly including ci check: test')
expect(debugMock).toHaveBeenCalledWith(
'explicitly including ci check: acceptance-test'
'filterChecks() - explicitly including ci check: test'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - explicitly including ci check: acceptance-test'
)
expect(debugMock).toHaveBeenCalledWith('explicitly including ci check: lint')
expect(debugMock).toHaveBeenCalledWith(
'explicitly including ci check: markdown-lint'
)
expect(debugMock).toHaveBeenCalledWith('explicitly including ci check: build')
expect(debugMock).toHaveBeenCalledWith('ignoring ci check: markdown-lint')
expect(debugMock).toHaveBeenCalledWith('ignoring ci check: lint')
expect(debugMock).toHaveBeenCalledWith('ignoring ci check: build')
expect(debugMock).toHaveBeenCalledWith('ignoring ci check: test')
expect(debugMock).toHaveBeenCalledWith('ignoring ci check: acceptance-test')
'filterChecks() - explicitly including ci check: lint'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - explicitly including ci check: markdown-lint'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - explicitly including ci check: build'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: markdown-lint'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: lint'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: build'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: test'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: acceptance-test'
)
expect(debugMock).toHaveBeenCalledWith(
'after filtering, no checks remain - this will result in a SUCCESS state as it is treated as if no checks are defined'
'filterChecks() - after filtering, no checks remain - this will result in a SUCCESS state as it is treated as if no checks are defined'
)
})

Expand Down Expand Up @@ -553,8 +671,12 @@ test('runs prechecks and finds that the IssueOps command is valid for a branch d
isFork: false
})

expect(debugMock).toHaveBeenCalledWith('ignoring ci check: build')
expect(debugMock).toHaveBeenCalledWith('ignoring ci check: markdown-lint')
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: build'
)
expect(debugMock).toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: markdown-lint'
)
})

test('runs prechecks and finds that the IssueOps command is valid for a branch deployment with ALL checks being required but the user has provided some checks to ignore', async () => {
Expand Down Expand Up @@ -626,8 +748,12 @@ test('runs prechecks and finds that the IssueOps command is valid for a branch d
expect(debugMock).not.toHaveBeenCalledWith(
'explicitly including ci check: test'
)
expect(debugMock).not.toHaveBeenCalledWith('ignoring ci check: build')
expect(debugMock).not.toHaveBeenCalledWith('ignoring ci check: markdown-lint')
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: build'
)
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: markdown-lint'
)
})

test('runs prechecks and finds that the IssueOps command is valid for a branch deployment with ALL checks being required but the user has provided some checks to ignore but none match', async () => {
Expand Down Expand Up @@ -696,8 +822,12 @@ test('runs prechecks and finds that the IssueOps command is valid for a branch d
status: false
})

expect(debugMock).not.toHaveBeenCalledWith('ignoring ci check: build')
expect(debugMock).not.toHaveBeenCalledWith('ignoring ci check: markdown-lint')
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: build'
)
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: markdown-lint'
)
})

test('runs prechecks and finds that the IssueOps command is valid for a branch deployment with ALL checks being required and the user did not provided checks to ignore and some are failing', async () => {
Expand Down Expand Up @@ -766,8 +896,12 @@ test('runs prechecks and finds that the IssueOps command is valid for a branch d
status: false
})

expect(debugMock).not.toHaveBeenCalledWith('ignoring ci check: build')
expect(debugMock).not.toHaveBeenCalledWith('ignoring ci check: markdown-lint')
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: build'
)
expect(debugMock).not.toHaveBeenCalledWith(
'filterChecks() - ignoring ci check: markdown-lint'
)
})

test('runs prechecks and finds that the IssueOps command is valid for a rollback deployment', async () => {
Expand Down
Loading