Skip to content

Commit

Permalink
v4.2.0 approval_mode feature
Browse files Browse the repository at this point in the history
  • Loading branch information
skymoore committed Apr 26, 2024
1 parent 818748e commit 2bf564e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8927,6 +8927,7 @@ async function main() {
process.env["INPUT_REQUIRE_ALL_APPROVALS_LATEST_COMMIT"];
const ghRef = process.env["GITHUB_REF"];
const ghRepo = process.env["GITHUB_REPOSITORY"];
const approvalMode = process.env["INPUT_APPROVAL_MODE"];

const octokit = new Octokit({ auth: token });
const readOrgOctokit = new Octokit({ auth: readOrgToken });
Expand Down Expand Up @@ -9052,15 +9053,24 @@ async function main() {
}

const allCodeownersApproved = Object.values(requiredCodeownerEntities).every((value) => value);
const anyCodeownerApproved = Object.values(requiredCodeownerEntities).some((value) => value);

const codeownersApprovalsCheck = approvalMode === "ANY" ? anyCodeownerApproved : allCodeownersApproved;
const minApprovalsMet = new Set(approvedCodeowners).size >= minApprovals;

const coReason = allCodeownersApproved ? "all codeowners approved" : "not all codeowners approved";
let coReason;
if (approvalMode === "ALL") {
coReason = allCodeownersApproved ? "All codeowners have approved." : "Not all codeowners have approved.";
} else if (approvalMode === "ANY") {
coReason = anyCodeownerApproved ? "At least one of the codeowners has approved." : "None of the codeowners has approved.";
}

const maReason = minApprovalsMet
? `total approvals:${approvedCodeowners.length} >= minimum approvals:${minApprovals}`
: `total approvals:${approvedCodeowners.length} < minimum approvals:${minApprovals}`;
const reason = `${coReason} and ${maReason}`;

const requiredApprovals = allCodeownersApproved && minApprovalsMet;
const requiredApprovals = codeownersApprovalsCheck && minApprovalsMet;

const outputPath = process.env["GITHUB_OUTPUT"];
fs.appendFileSync(outputPath, `approved=${requiredApprovals.toString().toLowerCase()}`);
Expand All @@ -9072,6 +9082,7 @@ async function main() {
console.warn(`Required approvals not met: ${reason}`);
process.exit(1);
}

}

main();
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "required-approvals",
"version": "4.0.0",
"version": "4.2.0",
"private": true,
"scripts": {
"build": "ncc build src/index.js -o dist"
Expand Down

0 comments on commit 2bf564e

Please sign in to comment.