Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include rulesets for pipeline health page #2917

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 44 additions & 7 deletions bin/pipelines.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,60 @@ export const writePipelinesJson = async () => {
if (branch !== 'TEMPLATE') {
// Get branch protection rules
try {
const rules = await octokit.rest.repos.getBranchProtection({
const branchRules = await octokit.rest.repos.getBranchProtection({
owner: 'nf-core',
repo: name,
branch: branch,
});
data[`${branch}_branch_protection_up_to_date`] = rules?.data?.res;
data[`${branch}_branch_protection_status_checks`] = rules?.data?.required_status_checks ?? -1;

data[`${branch}_branch_protection_up_to_date`] = branchRules?.data?.res;
data[`${branch}_branch_protection_status_checks`] = branchRules?.data?.required_status_checks ?? -1;
data[`${branch}_branch_protection_required_reviews`] =
rules?.data?.required_pull_request_reviews?.required_approving_review_count ?? -1;
branchRules?.data?.required_pull_request_reviews?.required_approving_review_count ?? -1;
data[`${branch}_branch_protection_require_codeowner_review`] =
rules?.data?.required_pull_request_reviews?.require_code_owner_reviews ?? -1;
branchRules?.data?.required_pull_request_reviews?.require_code_owner_reviews ?? -1;
data[`${branch}_branch_protection_require_non_stale_review`] =
rules?.data?.required_pull_request_reviews?.dismiss_stale_reviews ?? -1;
data[`${branch}_branch_protection_enforce_admins`] = rules?.data?.enforce_admins?.enabled ?? -1;
branchRules?.data?.required_pull_request_reviews?.dismiss_stale_reviews ?? -1;
data[`${branch}_branch_protection_enforce_admins`] = branchRules?.data?.enforce_admins?.enabled ?? -1;
} catch (err) {
console.log(`Failed to fetch ${branch} branch protection`, err);
}
try {
const ruleSet = await octokit.request('GET /repos/{owner}/{repo}/rules/branches/{branch}', {
owner: 'nf-core',
repo: name,
branch: branch,
});

if (ruleSet?.data?.length > 0) {
const pullRequestRule = ruleSet.data.find((rule) => rule.type === 'pull_request');
const statusCheckRule = ruleSet.data.find((rule) => rule.type === 'required_status_checks');

data[`${branch}_branch_protection_up_to_date`] = -1;

// Status checks
data[`${branch}_branch_protection_status_checks`] = statusCheckRule
? statusCheckRule.parameters.required_status_checks?.some(
(check) =>
check.context === 'nf-core' || check.context === 'pre-commit'
)
? 1
: 0
: 0;

// Pull request reviews
if (pullRequestRule) {
const params = pullRequestRule.parameters;
data[`${branch}_branch_protection_required_reviews`] = params.required_approving_review_count || 0;
data[`${branch}_branch_protection_require_codeowner_review`] = params.require_code_owner_review ? 1 : 0;
data[`${branch}_branch_protection_require_non_stale_review`] = params.dismiss_stale_reviews_on_push
? 0
: 1;
}
}
} catch (err) {
console.log(`Failed to fetch ${branch} rulesets`, err);
}
} else {
// Template branch protection rules
try {
Expand Down
Loading