Skip to content

Commit

Permalink
Merge pull request #124 from github/has-hooks-fix
Browse files Browse the repository at this point in the history
HAS_HOOKS checks
  • Loading branch information
GrantBirki authored Mar 13, 2023
2 parents 4c98be0 + 14a3b43 commit bce5fe1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
78 changes: 78 additions & 0 deletions __tests__/functions/prechecks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2654,3 +2654,81 @@ test('runs prechecks and finds the PR is NOT behind the stable branch (BLOCKED)
sha: 'abc123'
})
})

test('runs prechecks and finds the PR is NOT behind the stable branch (HAS_HOOKS) and a noop deploy and does not update the branch', async () => {
var octonocommitchecks = octokit
octonocommitchecks['graphql'] = jest.fn().mockReturnValue({
repository: {
pullRequest: {
reviewDecision: 'APPROVED',
mergeStateStatus: 'HAS_HOOKS',
commits: {
nodes: [
{
commit: {
checkSuites: {
totalCount: 1
},
statusCheckRollup: {
state: 'SUCCESS'
}
}
}
]
}
}
}
})
octonocommitchecks['rest']['repos']['getCollaboratorPermissionLevel'] = jest
.fn()
.mockReturnValueOnce({data: {permission: 'admin'}, status: 200})
octonocommitchecks['rest']['pulls']['get'] = jest.fn().mockReturnValue({
data: {
head: {
ref: 'test-ref',
sha: 'abc123'
},
base: {
ref: 'main'
}
},
status: 200
})
octonocommitchecks['rest']['repos']['getBranch'] = jest
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'deadbeef'}}, status: 200})
octonocommitchecks['rest']['repos']['compareCommits'] = jest
.fn()
.mockReturnValueOnce({data: {behind_by: 0}, status: 200})
octonocommitchecks['rest']['pulls']['updateBranch'] = jest
.fn()
.mockReturnValue({
data: {
message: 'Updating pull request branch.',
url: 'https://api.github.com/repos/foo/bar/pulls/123'
},
status: 202
})
expect(
await prechecks(
'.deploy noop',
'.deploy',
'noop',
'force',
'main',
'123',
true,
'',
'',
'production',
context,
octonocommitchecks
)
).toStrictEqual({
message: '✔️ PR is approved and all CI checks passed - OK',
status: true,
noopMode: true,
ref: 'test-ref',
sha: 'abc123'
})
})
4 changes: 2 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.

4 changes: 2 additions & 2 deletions src/functions/prechecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ export async function prechecks(

// Check to see if the branch is behind the base branch
var behind = false
// if the mergeStateStatus is 'BLOCKED' check to see if the branch is out-of-date with the base branch
if (mergeStateStatus === 'BLOCKED') {
// if the mergeStateStatus is 'BLOCKED' or 'HAS_HOOKS' check to see if the branch is out-of-date with the base branch
if (mergeStateStatus === 'BLOCKED' || mergeStateStatus === 'HAS_HOOKS') {
// Make an API call to get the base branch
const baseBranch = await octokit.rest.repos.getBranch({
...context.repo,
Expand Down

0 comments on commit bce5fe1

Please sign in to comment.