algorithmic_trading / scripts /setup_branch_protection.sh
Edwin Salguero
chore: enterprise-grade project structure, robust .gitignore, and directory cleanup
9289e29
#!/bin/bash
# Branch Protection Setup Script
# Run this script to automatically configure branch protection
echo "πŸ›‘οΈ Setting up branch protection for algorithmic trading repository..."
# Configuration
REPO="EAName/algorithmic_trading"
BRANCH="main"
REQUIRED_REVIEWS=2
REQUIRED_CHECKS='["ci-cd/quality-check","ci-cd/test","ci-cd/security","ci-cd/backtesting"]'
echo "πŸ“‹ Configuration:"
echo " Repository: $REPO"
echo " Branch: $BRANCH"
echo " Required reviews: $REQUIRED_REVIEWS"
echo " Required checks: $REQUIRED_CHECKS"
echo ""
echo "⚠️ IMPORTANT: You need a GitHub Personal Access Token with 'repo' permissions"
echo " Get one from: https://github.com/settings/tokens"
echo ""
read -p "Enter your GitHub Personal Access Token: " GITHUB_TOKEN
if [ -z "$GITHUB_TOKEN" ]; then
echo "❌ No token provided. Exiting."
exit 1
fi
echo ""
echo "πŸ”§ Applying branch protection rules..."
# Apply branch protection
curl -X PUT \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$REPO/branches/$BRANCH/protection" \
-d "{
\"required_status_checks\": {
\"strict\": true,
\"contexts\": $REQUIRED_CHECKS
},
\"enforce_admins\": true,
\"required_pull_request_reviews\": {
\"required_approving_review_count\": $REQUIRED_REVIEWS,
\"dismiss_stale_reviews\": true,
\"require_code_owner_reviews\": true
},
\"restrictions\": null,
\"allow_force_pushes\": false,
\"allow_deletions\": false
}"
if [ $? -eq 0 ]; then
echo ""
echo "βœ… Branch protection successfully applied!"
echo ""
echo "πŸ“‹ Applied rules:"
echo " - Require pull request before merging"
echo " - Require $REQUIRED_REVIEWS approvals"
echo " - Require code owner reviews"
echo " - Require status checks: $REQUIRED_CHECKS"
echo " - No force pushes allowed"
echo " - No deletions allowed"
echo ""
echo "πŸ”— View settings: https://github.com/$REPO/settings/branches"
else
echo ""
echo "❌ Failed to apply branch protection. Check your token and permissions."
fi