From d9c2853d0406f2470fdc856e1a819bf861839db8 Mon Sep 17 00:00:00 2001 From: Zhiye Li Date: Sun, 1 Sep 2024 12:07:15 -0500 Subject: [PATCH 1/2] add husky --- .husky/pre-commit | 2 ++ package.json | 4 +++- yarn.lock | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..046a82c --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,2 @@ +#!/bin/sh +npm run build diff --git a/package.json b/package.json index d5596a5..19d9f55 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "lint": "eslint -c eslint.config.js src", "test": "jest src --coverage --verbose", "jest-dev": "jest src --coverage --verbose --watch", - "build": "ncc build src/index.js -o dest" + "build": "ncc build src/index.js -o dest", + "prepare": "husky" }, "repository": "git@github.com:adRise/update-pr-branch.git", "license": "MIT", @@ -22,6 +23,7 @@ "eslint": "^9.2.0", "eslint-plugin-jest": "^28.5.0", "globals": "^15.3.0", + "husky": "^9.1.5", "jest": "^29.7.0" } } diff --git a/yarn.lock b/yarn.lock index 8327aeb..2d05d63 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2395,6 +2395,11 @@ human-signals@^2.1.0: resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0" integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw== +husky@^9.1.5: + version "9.1.5" + resolved "https://registry.yarnpkg.com/husky/-/husky-9.1.5.tgz#2b6edede53ee1adbbd3a3da490628a23f5243b83" + integrity sha512-rowAVRUBfI0b4+niA4SJMhfQwc107VLkBUgEYYAOQAbqDCnra1nYh83hF/MDmhYs9t9n1E3DuKOrs2LYNC+0Ag== + ignore@^5.2.0: version "5.3.1" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.1.tgz#5073e554cd42c5b33b394375f538b8593e34d4ef" From 855b1d313c28830c3631d547649e48d14f91ed5c Mon Sep 17 00:00:00 2001 From: Zhiye Li Date: Sun, 1 Sep 2024 12:08:14 -0500 Subject: [PATCH 2/2] test again --- .husky/pre-commit | 1 + dest/index.js | 34 ++++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 046a82c..87c7c10 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,2 +1,3 @@ #!/bin/sh npm run build +git add dest diff --git a/dest/index.js b/dest/index.js index 10874ab..8563336 100644 --- a/dest/index.js +++ b/dest/index.js @@ -31237,7 +31237,7 @@ const getMergeableStatus = async (pullNumber) => { /** * whether all checks passed */ -const areAllChecksPassed = async (sha) => { +const areAllChecksPassed = async (sha, allow_ongoing_checks) => { const octokit = getOctokit(); const repo = github.context.repo; const { @@ -31247,11 +31247,20 @@ const areAllChecksPassed = async (sha) => { ref: sha, }); - const hasUnfinishedOrFailedChecks = check_runs.some((item) => { - return item.status !== 'completed' || item.conclusion === 'failure'; - }); + let hasOffensiveChecks = false; + if (allow_ongoing_checks) { + // check whether there are ongoing checks + hasOffensiveChecks = check_runs.some((item) => { + return item.conclusion === 'failure'; + }); + } else { + // check whether there are unfinished or failed checks + hasOffensiveChecks = check_runs.some((item) => { + return item.status !== 'completed' || item.conclusion === 'failure'; + }); + } - return !hasUnfinishedOrFailedChecks; + return !hasOffensiveChecks; }; /** @@ -31291,7 +31300,9 @@ const getApprovalStatus = async (pullNumber) => { }; const filterApplicablePRs = (openPRs) => { - const includeNonAutoMergePRs = isStringFalse(github_core.getInput('require_auto_merge_enabled')); + const includeNonAutoMergePRs = isStringFalse( + github_core.getInput('require_auto_merge_enabled'), + ); if (includeNonAutoMergePRs) { return openPRs; } @@ -31308,6 +31319,9 @@ const getAutoUpdateCandidate = async (openPRs) => { const requirePassedChecks = isStringTrue( github_core.getInput('require_passed_checks'), ); + const allowOngoingChecks = isStringTrue( + github_core.getInput('allow_ongoing_checks'), + ); const applicablePRs = filterApplicablePRs(openPRs); for (const pr of applicablePRs) { @@ -31353,9 +31367,13 @@ const getAutoUpdateCandidate = async (openPRs) => { * need to note: the mergeable, and mergeable_state don't reflect the checks status */ if (requirePassedChecks) { - const didChecksPass = await areAllChecksPassed(sha); + const didChecksPass = await areAllChecksPassed(sha, allowOngoingChecks); + + const reasonType = allowOngoingChecks + ? 'failed check(s)' + : 'failed or ongoing check(s)'; if (!didChecksPass) { - printFailReason(pullNumber, 'The PR has failed or ongoing check(s)'); + printFailReason(pullNumber, `The PR has ${reasonType}`); continue; } }