Compare commits
3 Commits
3bfaad3036
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a4c6786a2 | |||
| 77fde815c7 | |||
| 1d99f664ee |
3
README.MD
Normal file
3
README.MD
Normal file
@@ -0,0 +1,3 @@
|
||||
# configurable-required-approvals
|
||||
|
||||
This is a fork of [weetbix/configurable-required-approvals](https://github.com/weetbix/configurable-required-approvals) that does't bother showing a green checkmark when a review is required.
|
||||
85
dist/index.js
generated
vendored
85
dist/index.js
generated
vendored
@@ -52,7 +52,7 @@ function getPRFilenames(octokit) {
|
||||
repo: github_1.context.repo.repo,
|
||||
pull_number: (_b = (_a = github_1.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number) !== null && _b !== void 0 ? _b : 0,
|
||||
});
|
||||
return files.map(file => file.filename);
|
||||
return files.filter(file => file.status !== 'added').map(file => file.filename);
|
||||
});
|
||||
}
|
||||
// Returns true if any of the filenames match any of the patterns
|
||||
@@ -62,7 +62,7 @@ function hasChangedFilesMatchingPatterns(patterns, filenames) {
|
||||
// The main action function.
|
||||
// Checks if the required approvals are met for the patterns
|
||||
function checkRequiredApprovals(config) {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h;
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let requiredApprovalsMet = true;
|
||||
const octokit = (0, github_1.getOctokit)(config.token);
|
||||
@@ -85,10 +85,11 @@ function checkRequiredApprovals(config) {
|
||||
}
|
||||
}
|
||||
}
|
||||
const noReviewsYet = github_1.context.eventName === 'pull_request' && reviews.length === 0;
|
||||
const noReviewsYet = github_1.context.eventName === 'pull_request' && reviews.length === 0 && false;
|
||||
const checkTitle = noReviewsYet
|
||||
? 'No reviews yet'
|
||||
: `${approvals}/${maxApprovalsRequired} approvals`;
|
||||
core.info(checkTitle);
|
||||
if (
|
||||
// Always succeed on pull_request events when there are no reviews yet.
|
||||
// That way we will not get red Xs on the PR right away.
|
||||
@@ -100,45 +101,59 @@ function checkRequiredApprovals(config) {
|
||||
else {
|
||||
core.info('All checks passed!');
|
||||
}
|
||||
yield octokit.rest.checks.create({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
name: 'Required number of approvals met',
|
||||
head_sha: (_e = (_d = (_c = github_1.context.payload.pull_request) === null || _c === void 0 ? void 0 : _c.head) === null || _d === void 0 ? void 0 : _d.sha) !== null && _e !== void 0 ? _e : github_1.context.sha,
|
||||
status: 'completed',
|
||||
conclusion: 'success',
|
||||
started_at: new Date().toISOString(),
|
||||
completed_at: new Date().toISOString(),
|
||||
output: {
|
||||
title: checkTitle,
|
||||
summary: 'All required approvals have been met.',
|
||||
},
|
||||
});
|
||||
process.exit(0);
|
||||
/*
|
||||
|
||||
await octokit.rest.checks.create({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
name: 'Required number of approvals met',
|
||||
head_sha: context.payload.pull_request?.head?.sha ?? context.sha,
|
||||
status: 'completed',
|
||||
conclusion: 'success',
|
||||
started_at: new Date().toISOString(),
|
||||
completed_at: new Date().toISOString(),
|
||||
output: {
|
||||
title: checkTitle,
|
||||
summary: 'All required approvals have been met.',
|
||||
},
|
||||
})
|
||||
*/
|
||||
}
|
||||
else {
|
||||
core.info(`Required approvals not met for one or more patterns.`);
|
||||
core.info(`Re-run this check when the required approvals has been met.`);
|
||||
process.exit(1);
|
||||
/*
|
||||
|
||||
// If the check already exists, update it so its pending and the
|
||||
// PR cannot be merged. Otherwise leave the check missing.
|
||||
const checks = yield octokit.rest.checks.listForRef({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
ref: (_h = (_g = (_f = github_1.context.payload.pull_request) === null || _f === void 0 ? void 0 : _f.head) === null || _g === void 0 ? void 0 : _g.sha) !== null && _h !== void 0 ? _h : github_1.context.sha,
|
||||
});
|
||||
const requiredApprovalsCheck = checks.data.check_runs.find(check => check.name === 'Required number of approvals met');
|
||||
const checks = await octokit.rest.checks.listForRef({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
ref: context.payload.pull_request?.head?.sha ?? context.sha,
|
||||
})
|
||||
|
||||
const requiredApprovalsCheck = checks.data.check_runs.find(
|
||||
check => check.name === 'Required number of approvals met',
|
||||
)
|
||||
|
||||
if (requiredApprovalsCheck) {
|
||||
core.info(`Setting existing check to in_progress`);
|
||||
yield octokit.rest.checks.update({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
check_run_id: requiredApprovalsCheck.id,
|
||||
status: 'in_progress',
|
||||
started_at: new Date().toISOString(),
|
||||
output: {
|
||||
title: checkTitle,
|
||||
summary: `${maxApprovalsRequired} approvals are required, but only ${approvals} have been met.`,
|
||||
},
|
||||
});
|
||||
core.info(`Setting existing check to in_progress`)
|
||||
|
||||
await octokit.rest.checks.update({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
check_run_id: requiredApprovalsCheck.id,
|
||||
status: 'in_progress',
|
||||
started_at: new Date().toISOString(),
|
||||
output: {
|
||||
title: checkTitle,
|
||||
summary: `${maxApprovalsRequired} approvals are required, but only ${approvals} have been met.`,
|
||||
},
|
||||
})
|
||||
}
|
||||
*/
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
7069
package-lock.json
generated
Normal file
7069
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -22,7 +22,7 @@ async function getPRFilenames(octokit: Octokit): Promise<string[]> {
|
||||
pull_number: context.payload.pull_request?.number ?? 0,
|
||||
})
|
||||
|
||||
return files.map(file => file.filename)
|
||||
return files.filter(file => file.status !== 'added').map(file => file.filename)
|
||||
}
|
||||
|
||||
// Returns true if any of the filenames match any of the patterns
|
||||
@@ -76,12 +76,14 @@ export async function checkRequiredApprovals(config: Config): Promise<void> {
|
||||
}
|
||||
|
||||
const noReviewsYet =
|
||||
context.eventName === 'pull_request' && reviews.length === 0
|
||||
context.eventName === 'pull_request' && reviews.length === 0 && false
|
||||
|
||||
const checkTitle = noReviewsYet
|
||||
? 'No reviews yet'
|
||||
: `${approvals}/${maxApprovalsRequired} approvals`
|
||||
|
||||
core.info(checkTitle);
|
||||
|
||||
if (
|
||||
// Always succeed on pull_request events when there are no reviews yet.
|
||||
// That way we will not get red Xs on the PR right away.
|
||||
@@ -93,6 +95,8 @@ export async function checkRequiredApprovals(config: Config): Promise<void> {
|
||||
} else {
|
||||
core.info('All checks passed!')
|
||||
}
|
||||
process.exit(0);
|
||||
/*
|
||||
|
||||
await octokit.rest.checks.create({
|
||||
owner: context.repo.owner,
|
||||
@@ -108,8 +112,12 @@ export async function checkRequiredApprovals(config: Config): Promise<void> {
|
||||
summary: 'All required approvals have been met.',
|
||||
},
|
||||
})
|
||||
*/
|
||||
} else {
|
||||
core.info(`Required approvals not met for one or more patterns.`)
|
||||
core.info(`Re-run this check when the required approvals has been met.`)
|
||||
process.exit(1);
|
||||
/*
|
||||
|
||||
// If the check already exists, update it so its pending and the
|
||||
// PR cannot be merged. Otherwise leave the check missing.
|
||||
@@ -138,5 +146,6 @@ export async function checkRequiredApprovals(config: Config): Promise<void> {
|
||||
},
|
||||
})
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user