export async function updateBranchProtection()

in packages/repocop/src/remediation/branch-protector/github-requests.ts [4:35]


export async function updateBranchProtection(
	octokit: Octokit,
	owner: string,
	repo: string,
	branch: string,
) {
	console.log(`Applying branch protection to ${repo}`);
	//https://github.com/guardian/recommendations/blob/main/github.md#branch-protection
	const branchProtectionParams: UpdateBranchProtectionParams = {
		owner: owner,
		repo: repo,
		branch: branch,
		required_status_checks: {
			strict: true,
			contexts: [],
		},
		restrictions: null,
		enforce_admins: true,
		required_pull_request_reviews: {
			require_code_owner_reviews: true,
			required_approving_review_count: 1,
		},
		allow_force_pushes: false,
		allow_deletions: false,
	};
	try {
		await octokit.rest.repos.updateBranchProtection(branchProtectionParams);
	} catch (error) {
		console.error(`Error: branch protection failed for ${repo}`);
		console.error(error);
	}
}