Skip to content

Commit

Permalink
Merge pull request #192 from github/prechecks-fixes
Browse files Browse the repository at this point in the history
Prechecks Fixes
  • Loading branch information
GrantBirki authored Aug 29, 2023
2 parents ccff97c + bc37876 commit 4eda8f9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
62 changes: 60 additions & 2 deletions __tests__/functions/prechecks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2096,15 +2096,73 @@ test('runs prechecks and finds that the commit status is success and skip_review
)
).toStrictEqual({
message:
'✅ CI checked passsed and required reviewers have been disabled for this environment',
'✅ CI checks passed and required reviewers have been disabled for this environment',
noopMode: false,
ref: 'test-ref',
status: true,
sha: 'abc123'
})

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 checks 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 checks have not been defined and required reviewers have been disabled for this environment'
)
})

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

10 changes: 8 additions & 2 deletions src/functions/prechecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export async function prechecks(
} else if (
(commitStatus === 'SUCCESS' ||
commitStatus === null ||
commitStatus == 'skip_ci') &&
commitStatus === 'skip_ci') &&
update_branch !== 'disabled' &&
behind === true
) {
Expand Down Expand Up @@ -357,7 +357,13 @@ export async function prechecks(
// CI checks are passing and reviews are set to be bypassed
} else if (commitStatus === 'SUCCESS' && reviewDecision == 'skip_reviews') {
message =
'✅ CI checked passsed and required reviewers have been disabled for this environment'
'✅ 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 checks 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
Expand Down

0 comments on commit 4eda8f9

Please sign in to comment.