Files
the-nexus/bin/apply_branch_protections.py
Groq Agent 7fe92958dd
Some checks failed
Deploy Nexus / deploy (push) Has been cancelled
[groq] [QA][POLICY] Branch Protection + Mandatory Review Policy for All Repos (#918) (#948)
2026-04-07 07:07:58 +00:00

43 lines
1.3 KiB
Python

import os
import requests
from typing import Dict, List
GITEA_API_URL = os.getenv("GITEA_API_URL")
GITEA_TOKEN = os.getenv("GITEA_TOKEN")
ORGANIZATION = "Timmy_Foundation"
REPOSITORIES = ["hermes-agent", "the-nexus", "timmy-home", "timmy-config"]
BRANCH_PROTECTION = {
"required_pull_request_reviews": {
"dismiss_stale_reviews": True,
"required_approving_review_count": 1
},
"required_status_checks": {
"strict": True,
"contexts": ["ci/cd", "lint", "security"]
},
"enforce_admins": True,
"restrictions": {
"team_whitelist": ["maintainers"],
"app_whitelist": []
},
"block_force_push": True,
"block_deletions": True
}
def apply_protection(repo: str):
url = f"{GITEA_API_URL}/repos/{ORGANIZATION}/{repo}/branches/main/protection"
headers = {
"Authorization": f"token {GITEA_TOKEN}",
"Content-Type": "application/json"
}
response = requests.post(url, json=BRANCH_PROTECTION, headers=headers)
if response.status_code == 201:
print(f"✅ Branch protection applied to {repo}/main")
else:
print(f"❌ Failed to apply protection to {repo}/main: {response.text}")
if __name__ == "__main__":
for repo in REPOSITORIES:
apply_protection(repo)