Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /scripts /github_pr.py
| #!/usr/bin/env python3 | |
| """ | |
| GitHub PR Helper - Erstellt und merged PR via GitHub API | |
| """ | |
| import time | |
| import jwt | |
| import requests | |
| # Config | |
| CONFIG = { | |
| "zenai": { | |
| "app_id": "2872904", | |
| "key_path": "/root/.ssh/github-app-zenai.pem", | |
| "owner": "SHAdd0WTAka", | |
| "repo": "Zen-Ai-Pentest", | |
| } | |
| } | |
| def generate_jwt(app_id, key_path): | |
| """Generiert JWT für GitHub App""" | |
| with open(key_path, "r") as f: | |
| private_key = f.read() | |
| payload = { | |
| "iat": int(time.time()), | |
| "exp": int(time.time()) + 600, | |
| "iss": app_id, | |
| } | |
| return jwt.encode(payload, private_key, algorithm="RS256") | |
| def get_installation_token(jwt_token, owner, repo): | |
| """Holt Installation Access Token""" | |
| # Installation ID finden | |
| headers = { | |
| "Authorization": f"Bearer {jwt_token}", | |
| "Accept": "application/vnd.github.v3+json", | |
| } | |
| resp = requests.get(f"https://api.github.com/repos/{owner}/{repo}/installation", headers=headers, timeout=30) | |
| if resp.status_code != 200: | |
| print(f"❌ Installation nicht gefunden: {resp.text}") | |
| return None | |
| installation_id = resp.json()["id"] | |
| # Access Token generieren | |
| resp = requests.post( | |
| f"https://api.github.com/app/installations/{installation_id}/access_tokens", headers=headers, timeout=30 | |
| ) | |
| if resp.status_code == 201: | |
| return resp.json()["token"] | |
| else: | |
| print(f"❌ Token Fehler: {resp.text}") | |
| return None | |
| def create_pr(token, owner, repo, title, head, base, body): | |
| """Erstellt Pull Request""" | |
| headers = { | |
| "Authorization": f"token {token}", | |
| "Accept": "application/vnd.github.v3+json", | |
| } | |
| data = {"title": title, "head": head, "base": base, "body": body} | |
| resp = requests.post(f"https://api.github.com/repos/{owner}/{repo}/pulls", headers=headers, json=data, timeout=30) | |
| if resp.status_code == 201: | |
| pr = resp.json() | |
| print(f"✅ PR erstellt: #{pr['number']} - {pr['html_url']}") | |
| return pr["number"] | |
| else: | |
| print(f"❌ PR Fehler: {resp.text}") | |
| return None | |
| def merge_pr(token, owner, repo, pr_number): | |
| """Merged Pull Request""" | |
| headers = { | |
| "Authorization": f"token {token}", | |
| "Accept": "application/vnd.github.v3+json", | |
| } | |
| resp = requests.put( | |
| f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}/merge", | |
| headers=headers, | |
| json={"merge_method": "squash"}, | |
| timeout=30, | |
| ) | |
| if resp.status_code == 200: | |
| print(f"✅ PR #{pr_number} gemerged!") | |
| return True | |
| else: | |
| print(f"❌ Merge Fehler: {resp.text}") | |
| return False | |
| if __name__ == "__main__": | |
| import sys | |
| if len(sys.argv) < 2: | |
| print("Usage: python3 github_pr.py [create|merge] [pr_number]") | |
| sys.exit(1) | |
| action = sys.argv[1] | |
| cfg = CONFIG["zenai"] | |
| # JWT generieren | |
| jwt_token = generate_jwt(cfg["app_id"], cfg["key_path"]) | |
| print("🔑 JWT generiert") | |
| # Installation Token holen | |
| token = get_installation_token(jwt_token, cfg["owner"], cfg["repo"]) | |
| if not token: | |
| sys.exit(1) | |
| print("🔑 Installation Token erhalten") | |
| if action == "create": | |
| # PR erstellen | |
| pr_body = """## Self-Healing Agent Architecture v2.0 | |
| ### 🎯 Was ist neu? | |
| **Komplette Architektur-Überarbeitung:** | |
| - ✅ ToolExecutor Abstraktion für robuste Tool-Ausführung | |
| - ✅ RecoveryEngine mit automatischen Tool-Fallbacks | |
| - ✅ Gobuster v2 mit JSON-Parsing und Soft-404 Detection | |
| - ✅ Agent Prompt v2 mit OODA Loop und State-Awareness | |
| - ✅ 210 SMART Tests für alle 31 Tools | |
| ### 🔧 Technische Änderungen | |
| **Neue Komponenten:** | |
| - `core/tool_executor.py` - Abstraktion für Shell-Aufrufe | |
| - `agents/recovery_engine.py` - Self-Healing Logik | |
| - `agents/pentester_prompt_v2.md` - Strategischer Prompt | |
| - `agent_runner.py` - Autonomer Live-Scan Runner | |
| **Tests:** | |
| - 210 neue SMART Tests (CommandRunner Pattern) | |
| - Golden File Fixtures für deterministische Tests | |
| - State-Machine Integration Tests | |
| **Entfernt:** | |
| - ~600 Ghost-Test Dateien | |
| - Alter Test Generator | |
| - 19.000 Placeholder-Tests | |
| ### 🧪 Getestet | |
| - ✅ Alle 210 Tests passing | |
| - ✅ Live Proof of Concept gegen scanme.nmap.org | |
| - ✅ Self-Healing verified (gobuster → dirb fallback) | |
| ### 🚀 Breaking Changes | |
| Alter Test Generator entfernt. Neue Tests nutzen: | |
| - CommandRunner Pattern | |
| - Golden File Fixtures | |
| - ToolExecutor Abstraktion | |
| --- | |
| **Ready for Production** ❤️🔥""" | |
| pr_number = create_pr( | |
| token, | |
| cfg["owner"], | |
| cfg["repo"], | |
| title="feat: Self-Healing Agent Architecture v2.0", | |
| head="feature/self-healing-architecture-v2", | |
| base="main", | |
| body=pr_body, | |
| ) | |
| if pr_number: | |
| print(f"\n🔗 PR URL: https://github.com/{cfg['owner']}/{cfg['repo']}/pull/{pr_number}") | |
| print(f"💡 Zum Mergen: python3 github_pr.py merge {pr_number}") | |
| elif action == "merge" and len(sys.argv) >= 3: | |
| pr_number = int(sys.argv[2]) | |
| merge_pr(token, cfg["owner"], cfg["repo"], pr_number) | |
| else: | |
| print("Usage: python3 github_pr.py [create|merge] [pr_number]") | |
Xet Storage Details
- Size:
- 5.24 kB
- Xet hash:
- 5ba0c9b4a5473a84cdf9678e27a342997b9b9b276aad9cc1c88a0ac6517e2b34
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.