File size: 2,145 Bytes
184a5a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
#!/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 |