Skip to content

Commit bce5fe1

Browse files
authored
Merge pull request #124 from github/has-hooks-fix
HAS_HOOKS checks
2 parents 4c98be0 + 14a3b43 commit bce5fe1

File tree

4 files changed

+83
-5
lines changed

4 files changed

+83
-5
lines changed

__tests__/functions/prechecks.test.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,3 +2654,81 @@ test('runs prechecks and finds the PR is NOT behind the stable branch (BLOCKED)
26542654
sha: 'abc123'
26552655
})
26562656
})
2657+
2658+
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 () => {
2659+
var octonocommitchecks = octokit
2660+
octonocommitchecks['graphql'] = jest.fn().mockReturnValue({
2661+
repository: {
2662+
pullRequest: {
2663+
reviewDecision: 'APPROVED',
2664+
mergeStateStatus: 'HAS_HOOKS',
2665+
commits: {
2666+
nodes: [
2667+
{
2668+
commit: {
2669+
checkSuites: {
2670+
totalCount: 1
2671+
},
2672+
statusCheckRollup: {
2673+
state: 'SUCCESS'
2674+
}
2675+
}
2676+
}
2677+
]
2678+
}
2679+
}
2680+
}
2681+
})
2682+
octonocommitchecks['rest']['repos']['getCollaboratorPermissionLevel'] = jest
2683+
.fn()
2684+
.mockReturnValueOnce({data: {permission: 'admin'}, status: 200})
2685+
octonocommitchecks['rest']['pulls']['get'] = jest.fn().mockReturnValue({
2686+
data: {
2687+
head: {
2688+
ref: 'test-ref',
2689+
sha: 'abc123'
2690+
},
2691+
base: {
2692+
ref: 'main'
2693+
}
2694+
},
2695+
status: 200
2696+
})
2697+
octonocommitchecks['rest']['repos']['getBranch'] = jest
2698+
.fn()
2699+
.mockReturnValueOnce({data: {commit: {sha: 'deadbeef'}}, status: 200})
2700+
octonocommitchecks['rest']['repos']['compareCommits'] = jest
2701+
.fn()
2702+
.mockReturnValueOnce({data: {behind_by: 0}, status: 200})
2703+
octonocommitchecks['rest']['pulls']['updateBranch'] = jest
2704+
.fn()
2705+
.mockReturnValue({
2706+
data: {
2707+
message: 'Updating pull request branch.',
2708+
url: 'https://api.github.com/repos/foo/bar/pulls/123'
2709+
},
2710+
status: 202
2711+
})
2712+
expect(
2713+
await prechecks(
2714+
'.deploy noop',
2715+
'.deploy',
2716+
'noop',
2717+
'force',
2718+
'main',
2719+
'123',
2720+
true,
2721+
'',
2722+
'',
2723+
'production',
2724+
context,
2725+
octonocommitchecks
2726+
)
2727+
).toStrictEqual({
2728+
message: '✔️ PR is approved and all CI checks passed - OK',
2729+
status: true,
2730+
noopMode: true,
2731+
ref: 'test-ref',
2732+
sha: 'abc123'
2733+
})
2734+
})

dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/prechecks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ export async function prechecks(
258258

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

0 commit comments

Comments
 (0)