Skip to content

Commit

Permalink
add missing condition to 'prechecks.js'
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Aug 29, 2023
1 parent e2552b7 commit 522bc47
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
60 changes: 59 additions & 1 deletion __tests__/functions/prechecks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,65 @@ test('runs prechecks and finds that the commit status is success and skip_review
})

expect(infoMock).toHaveBeenCalledWith(
'✅ CI checked passsed and required reviewers have been disabled for this environment'
'✅ CI checks passed and required reviewers have been disabled for this environment'
)
})

test('runs prechecks and finds that no ci checks are defined and skip_reviews is set for the environment', async () => {
octokit.graphql = jest.fn().mockReturnValue({
repository: {
pullRequest: {
reviewDecision: 'REVIEW_REQUIRED',
commits: {
nodes: [
{
commit: {
checkSuites: {
totalCount: 0
},
statusCheckRollup: null
}
}
]
}
}
}
})
jest.spyOn(isAdmin, 'isAdmin').mockImplementation(() => {
return false
})

environmentObj.target = 'staging'

expect(
await prechecks(
'.deploy to staging',
'.deploy',
'.noop',
'disabled',
'main',
'123',
true,
'development', // skip_ci
'staging', // skip_reviews
'development', // draft_permitted_targets
'staging', // the environment the deployment was sent to
environmentObj,
help_trigger,
context,
octokit
)
).toStrictEqual({
message:
'✅ CI have not been defined and required reviewers have been disabled for this environment',
noopMode: false,
ref: 'test-ref',
status: true,
sha: 'abc123'
})

expect(infoMock).toHaveBeenCalledWith(
'✅ CI have not been defined and required reviewers have been disabled for this environment'
)
})

Expand Down
8 changes: 7 additions & 1 deletion 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.

6 changes: 6 additions & 0 deletions src/functions/prechecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ export async function prechecks(
'✅ CI checks passed and required reviewers have been disabled for this environment'
core.info(message)

// CI checks have not been defined and reviews are set to be bypassed
} else if (commitStatus === null && reviewDecision === 'skip_reviews') {
message =
'✅ CI have not been defined and required reviewers have been disabled for this environment'
core.info(message)

// CI checks are set to be bypassed and the pull request is approved
} else if (commitStatus === 'skip_ci' && reviewDecision === 'APPROVED') {
message =
Expand Down

0 comments on commit 522bc47

Please sign in to comment.