github-branch-protectionlisted
Install: claude install-skill rodrigopg/claude-skill-github-branch-protection
# GitHub Branch Protection Skill
Protege a branch `main` (ou qualquer branch alvo) contra push direto. Toda alteracao deve passar por PR.
## Quando usar
- `/github-branch-protection` — detecta repo atual e configura
- `/github-branch-protection <branch>` — protege branch especifica (default: `main`)
- `/github-branch-protection status` — verifica se protecao esta ativa
- `/github-branch-protection remove` — remove protecao
---
## Fluxo de execucao
### 1. Detectar repositorio e plano
```bash
# Obter owner/repo do remote atual
REPO=$(git remote get-url origin | sed 's/.*github\.com[:/]\(.*\)\.git/\1/' | sed 's/.*github\.com[:/]\(.*\)/\1/')
OWNER=$(echo "$REPO" | cut -d/ -f1)
# Verificar tipo de conta e plano
gh api repos/$REPO --jq '{owner_type: .owner.type, private: .private, plan: .owner.plan}'
# Testar se branch protection API esta disponivel (requer plano pago em repos privados)
STATUS=$(gh api repos/$REPO/branches/main/protection 2>&1)
if echo "$STATUS" | grep -q "Upgrade to GitHub Pro"; then
PLAN_TYPE="free"
else
PLAN_TYPE="paid"
fi
# Testar rulesets
RULESET_STATUS=$(gh api repos/$REPO/rulesets --method POST ... 2>&1)
# Mesmo erro 403 = free plan
```
**Regra:** repo privado + org free = forcar workaround Actions. Repo publico ou plano pago = usar protecao nativa.
### 2. Rota A — Plano pago (GitHub Team/Pro/Enterprise)
Usar GitHub Rulesets (mais moderno que branch protection classica):
```bash
gh api repos/$REPO/rulesets \
--method POST \
-H "Accept: