ParallelLLC/algorithmic_trading
2732
1#!/bin/bash2 3# Branch Protection Setup Script4# Run this script to automatically configure branch protection5 6echo "๐ก๏ธ Setting up branch protection for algorithmic trading repository..."7 8# Configuration9REPO="EAName/algorithmic_trading"10BRANCH="main"11REQUIRED_REVIEWS=212REQUIRED_CHECKS='["ci-cd/quality-check","ci-cd/test","ci-cd/security","ci-cd/backtesting"]'13 14echo "๐ Configuration:"15echo " Repository: $REPO"16echo " Branch: $BRANCH"17echo " Required reviews: $REQUIRED_REVIEWS"18echo " Required checks: $REQUIRED_CHECKS"19 20echo ""21echo "โ ๏ธ IMPORTANT: You need a GitHub Personal Access Token with 'repo' permissions"22echo " Get one from: https://github.com/settings/tokens"23echo ""24 25read -p "Enter your GitHub Personal Access Token: " GITHUB_TOKEN26 27if [ -z "$GITHUB_TOKEN" ]; then28 echo "โ No token provided. Exiting."29 exit 130fi31 32echo ""33echo "๐ง Applying branch protection rules..."34 35# Apply branch protection36curl -X PUT \37 -H "Authorization: token $GITHUB_TOKEN" \38 -H "Accept: application/vnd.github.v3+json" \39 "https://api.github.com/repos/$REPO/branches/$BRANCH/protection" \40 -d "{41 \"required_status_checks\": {42 \"strict\": true,43 \"contexts\": $REQUIRED_CHECKS44 },45 \"enforce_admins\": true,46 \"required_pull_request_reviews\": {47 \"required_approving_review_count\": $REQUIRED_REVIEWS,48 \"dismiss_stale_reviews\": true,49 \"require_code_owner_reviews\": true50 },51 \"restrictions\": null,52 \"allow_force_pushes\": false,53 \"allow_deletions\": false54 }"55 56if [ $? -eq 0 ]; then57 echo ""58 echo "โ
Branch protection successfully applied!"59 echo ""60 echo "๐ Applied rules:"61 echo " - Require pull request before merging"62 echo " - Require $REQUIRED_REVIEWS approvals"63 echo " - Require code owner reviews"64 echo " - Require status checks: $REQUIRED_CHECKS"65 echo " - No force pushes allowed"66 echo " - No deletions allowed"67 echo ""68 echo "๐ View settings: https://github.com/$REPO/settings/branches"69else70 echo ""71 echo "โ Failed to apply branch protection. Check your token and permissions."72fi 