From 877df14d3f48cd729b785c54d7015d529304c728 Mon Sep 17 00:00:00 2001 From: Jheison Martinez Bolivar Date: Fri, 10 Apr 2026 08:20:13 -0500 Subject: [PATCH] feat: update branch protection with ghscaff apply --- src/apply.rs | 36 ++++++++++++++++++------------------ src/wizard.rs | 16 ++++++++++++++-- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/apply.rs b/src/apply.rs index 193e076..d8d23c9 100644 --- a/src/apply.rs +++ b/src/apply.rs @@ -326,26 +326,26 @@ pub fn run_apply(repo_arg: Option<&str>, dry_run: bool) -> Result<()> { sync_labels(&client, &owner, &repo_name, false)?; println!(" ✓ Labels synced"); - // 2. Branch protection (skip if already enabled, warn on failure) - if !ctx.branch_protection_enabled { - match crate::github::branches::apply_branch_protection( - &client, &owner, &repo_name, "main", "CI", - ) { - Ok(()) => println!(" ✓ Branch protection applied"), - Err(e) => { - let msg = format!("{e:#}"); - if msg.contains("403") { - println!(" ⚠ Branch protection skipped (403 Forbidden)"); - println!(" Possible causes:"); - println!(" • Private repo on a free org plan (requires GitHub Team)"); - println!(" • Token not authorized for this organization"); - } else { - println!(" ⚠ Branch protection failed: {msg}"); - } + // 2. Branch protection (always apply to ensure correct config) + match crate::github::branches::apply_branch_protection( + &client, + &owner, + &repo_name, + "main", + "rust-ci / Format, Lint & Test", + ) { + Ok(()) => println!(" ✓ Branch protection applied"), + Err(e) => { + let msg = format!("{e:#}"); + if msg.contains("403") { + println!(" ⚠ Branch protection skipped (403 Forbidden)"); + println!(" Possible causes:"); + println!(" • Private repo on a free org plan (requires GitHub Team)"); + println!(" • Token not authorized for this organization"); + } else { + println!(" ⚠ Branch protection failed: {msg}"); } } - } else { - println!(" ✓ Branch protection (already enabled)"); } // 3. Develop branch (if needed) diff --git a/src/wizard.rs b/src/wizard.rs index ce81d6c..e4644bf 100644 --- a/src/wizard.rs +++ b/src/wizard.rs @@ -315,13 +315,25 @@ fn execute(client: &GithubClient, c: &WizardConfig, dry_run: bool, token: &str) step!( &format!("apply branch protection ({})", c.default_branch), { - branches::apply_branch_protection(client, owner, name, &c.default_branch, "build")?; + branches::apply_branch_protection( + client, + owner, + name, + &c.default_branch, + "rust-ci / Format, Lint & Test", + )?; Ok::<(), anyhow::Error>(()) } ); if c.create_develop { step!("apply branch protection (develop)", { - branches::apply_branch_protection(client, owner, name, "develop", "build")?; + branches::apply_branch_protection( + client, + owner, + name, + "develop", + "rust-ci / Format, Lint & Test", + )?; Ok::<(), anyhow::Error>(()) }); }