You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ensure that prechecks() actually fails if an exact check input is provided (for a CI check) and that check does not exist in the graphql response for passed checks on the pull request
Copy file name to clipboardExpand all lines: __tests__/functions/prechecks.test.js
+89Lines changed: 89 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -397,6 +397,95 @@ test('runs prechecks and finds that the IssueOps command is valid for a branch d
397
397
)
398
398
})
399
399
400
+
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()=>{
'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`',
463
+
status: false
464
+
})
465
+
466
+
expect(warningMock).toHaveBeenCalledWith(
467
+
`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}`
468
+
)
469
+
expect(debugMock).not.toHaveBeenCalledWith(
470
+
'filterChecks() - explicitly including ci check: test'
471
+
)
472
+
expect(debugMock).not.toHaveBeenCalledWith(
473
+
'filterChecks() - explicitly including ci check: acceptance-test'
474
+
)
475
+
expect(debugMock).not.toHaveBeenCalledWith(
476
+
'filterChecks() - explicitly including ci check: lint'
477
+
)
478
+
expect(debugMock).not.toHaveBeenCalledWith(
479
+
'filterChecks() - markdown-lint is not in the explicit list of checks to include (test,acceptance-test,lint)'
480
+
)
481
+
expect(debugMock).not.toHaveBeenCalledWith(
482
+
'filterChecks() - ignoring ci check: markdown-lint'
483
+
)
484
+
expect(debugMock).not.toHaveBeenCalledWith(
485
+
'filterChecks() - ignoring ci check: lint'
486
+
)
487
+
})
488
+
400
489
test('runs prechecks and finds that the IssueOps command is valid for a branch deployment but checks and ignore checks cancel eachother out',async()=>{
message=`### ⚠️ Cannot proceed with deployment\n\n- reviewDecision: \`${reviewDecision}\`\n- commitStatus: \`${commitStatus}\`\n\n> CI checks must be passing in order to continue`
654
658
return{message: message,status: false}
655
659
660
+
// Regardless of the reviewDecision or noop, if the commitStatus is 'MISSING' this means that a user has explicitly requested a CI check to be passing with the `checks: <check1>,<check2>,<etc>` input option, but the check could not be found in the GraphQL result
661
+
// In this case, we should alert the user that the check could not be found and exit
662
+
}elseif(commitStatus==='MISSING'){
663
+
message=`### ⚠️ Cannot proceed with deployment\n\n- reviewDecision: \`${reviewDecision}\`\n- commitStatus: \`${commitStatus}\`\n\n> CI checks must be passing in order to continue`
// If a set of values is provided for the `checks` input option, ensure all of them exist in checkResults
768
+
// Example: if `checks` is set to `['test', 'lint', 'build']`, ensure that all of those checks exist in checkResults
769
+
if(checksProvided){
770
+
constmissingChecks=checks.filter(
771
+
ch=>!checkResults.some(cr=>cr.name===ch)
772
+
)
773
+
if(missingChecks.length>0){
774
+
core.warning(
775
+
`the ${COLORS.info}checks${COLORS.reset} input option requires that all of the following checks are passing: ${COLORS.highlight}${checks.join(', ')}${COLORS.reset} - however, the following checks are missing: ${COLORS.highlight}${missingChecks.join(', ')}${COLORS.reset}`
776
+
)
777
+
778
+
return{
779
+
message: `The \`checks\` input option requires that all of the following checks are passing: \`${checks.join(',')}\`. However, the following checks are missing: \`${missingChecks.join(',')}\``,
780
+
status: 'MISSING'
781
+
}
782
+
}
783
+
}
784
+
752
785
// Filter the checkResults based on user input (checks), ignoring checks, and required flag
753
786
constfilteredChecks=checkResults
754
787
.filter(check=>{
755
-
// If checks is an array (meaning it isn't just `required` or `all`) and it contains items, filter checks based on it
756
-
if(Array.isArray(checks)&&checks.length>0){
788
+
if(checksProvided){
757
789
// check if the `checks` input option explicitly includes the name of the check that was found
758
790
constisIncluded=checks.includes(check.name)
759
791
@@ -793,12 +825,16 @@ function filterChecks(checks, checkResults, ignoredChecks, required) {
793
825
794
826
// If no checks remain after filtering, default to SUCCESS
795
827
if(filteredChecks.length===0){
796
-
core.debug(
828
+
constmessage=
797
829
'filterChecks() - after filtering, no checks remain - this will result in a SUCCESS state as it is treated as if no checks are defined'
798
-
)
799
-
return'SUCCESS'
830
+
core.debug(message)
831
+
return{message: message,status: 'SUCCESS'}
800
832
}
801
833
802
-
// Return SUCCESS if all checks are healthy, otherwise FAILURE
0 commit comments