refactor: restructure into proper project layout + improve docs

Project layout:
- src/: application modules (run_server, auto_merge_bot, health-check, sync-key, trivial_merge, callback_server, start_server)
- scripts/: setup/deployment helpers (setup_all, setup_app, generate_manifest)
- templates/: manifest.json (GitHub App manifest template)
- docs/  + CONTRIBUTING.md: documentation

Improvements:
- flake.nix: added pr-agent-auto-merge wrapper binary, updated installPhase paths
- deploy.yml: syntax check covers all modules including health-check.py and sync-key.py
- README.md: comprehensive with architecture, layout, dev, ops, deployment
- CONTRIBUTING.md: standards and testing checklist
- .gitignore: added *.log, *.pid, .env.*
- Cleanup: removed duplicate manifest_current.json / manifest_final.json
- Fix: health-check.py docstring updated to claude-opus-5

Verification:
-  python3 -m py_compile: all 11 modules pass
-  nix flake check: passes
This commit is contained in:
asepharyana
2026-08-20 11:38:24 +07:00
parent 017656d97b
commit bc8e1739e9
19 changed files with 141 additions and 90 deletions
+95
View File
@@ -0,0 +1,95 @@
#!/usr/bin/env python3
"""
PR-Agent GitHub App Setup Helper
Creates the GitHub App manifest and prepares the server configuration.
"""
import json
import base64
import os
import secrets
# ============================================================
# CONFIGURATION
# ============================================================
APP_NAME = "pr-agent-auto"
APP_SLUG = "pr-agent-auto"
DESCRIPTION = "Automated PR review and merge bot powered by AI"
HOME_URL = "https://github.com/asepharyana"
PUBLIC_IP = "45.127.35.244"
PORT = 4002
WEBHOOK_URL = "https://pr-agent.asepharyana.my.id/api/v1/github_webhooks"
REDIRECT_URL = "https://pr-agent.asepharyana.my.id/app-setup-complete"
CALLBACK_URLS = ["https://pr-agent.asepharyana.my.id/callback"]
# Generate webhook secret
WEBHOOK_SECRET = secrets.token_hex(20)
# ============================================================
# CREATE MANIFEST
# ============================================================
manifest = {
"name": APP_NAME,
"slug": APP_SLUG,
"description": DESCRIPTION,
"url": HOME_URL,
"hook_attributes": {
"url": WEBHOOK_URL,
"active": True
},
"redirect_url": REDIRECT_URL,
"callback_urls": CALLBACK_URLS,
"public": False,
"default_events": [
"pull_request",
"issue_comment",
"push"
],
"default_permissions": {
"pull_requests": "write",
"issues": "write",
"metadata": "read",
"contents": "read",
"checks": "write",
"emails": "read"
}
}
# Save manifest
os.makedirs("/opt/pr-agent-server", exist_ok=True)
manifest_path = "/opt/pr-agent-server/manifest.json"
with open(manifest_path, "w") as f:
json.dump(manifest, f, indent=2)
# Create the URL
manifest_b64 = base64.b64encode(json.dumps(manifest).encode()).decode()
manifest_url = f"https://github.com/settings/apps/new?manifest={manifest_b64}"
print("=" * 60)
print("PR-Agent GITHUB APP SETUP")
print("=" * 60)
print(f"\n📋 App Name: {APP_NAME}")
print(f"🌐 Webhook URL: {WEBHOOK_URL}")
print(f"🔑 Webhook Secret: {WEBHOOK_SECRET}")
print(f"\n{'=' * 60}")
print("STEP 1: Click this URL to create the GitHub App:")
print(f"{'=' * 60}")
print(f"\n{manifest_url}\n")
print(f"{'=' * 60}")
print("STEP 2: After clicking 'Create GitHub App', you'll be redirected.")
print(" Save the App ID, Private Key, and Webhook Secret shown.")
print(f"{'=' * 60}")
# Save vars for later use
env_file = "/opt/pr-agent-server/.env"
with open(env_file, "w") as f:
f.write(f"WEBHOOK_SECRET={WEBHOOK_SECRET}\n")
f.write(f"PORT={PORT}\n")
f.write("# After GitHub App creation, add:\n")
f.write("# APP_ID=<your-app-id>\n")
f.write("# PRIVATE_KEY_PATH=/opt/pr-agent-server/private-key.pem\n")
f.write(f"# GITHUB_APP_NAME={APP_NAME}\n")
print(f"\n📁 Config saved to: {manifest_path}")
print(f"📁 Env file: {env_file}")
print(f"\nWebhook Secret (save this!): {WEBHOOK_SECRET}")