|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
echo "π‘οΈ Setting up branch protection for algorithmic trading repository..." |
|
|
|
|
|
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..." |
|
|
|
|
|
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 |