diff --git a/justfile b/justfile new file mode 100644 index 0000000..02eb2c8 --- /dev/null +++ b/justfile @@ -0,0 +1,24 @@ +# Hardcoding all the args for now, can be dynamic later + +_default: + @just --list + +# Start a server on http://localhost:3000 which receives webhook events and dumps the payloads into the fixtures folder +listen: + python3 server.py + +# Requires the following commands to be run first: +# - gh extension install cli/gh-webhook +# - gh auth refresh -h github.com -s admin:org_hook +# +# Create a development GitHub webhook and forward all webhook events to http://localhost:3000 +register_webhook: + gh webhook forward --events='*' --org=catppuccin-rfc --url="http://localhost:3000" + +# Create a new issue, close and reopen it in catppuccin-rfc/polybar +issues: + #!/usr/bin/env bash + ISSUE_URL=$(gh issue create --title "rockdove-{{datetime_utc("%Y%m%d_%H%M%S")}}" --body "rockdove" --repo catppuccin-rfc/polybar) + gh issue close "$ISSUE_URL" + gh issue reopen "$ISSUE_URL" + diff --git a/server.py b/server.py new file mode 100644 index 0000000..eb32d09 --- /dev/null +++ b/server.py @@ -0,0 +1,39 @@ +from http.server import HTTPServer, BaseHTTPRequestHandler +import json +from pathlib import Path + + +class WebhookHandler(BaseHTTPRequestHandler): + def do_POST(self): + content_length = int(self.headers["Content-Length"]) + post_data = self.rfile.read(content_length) + payload = json.loads(post_data.decode("utf-8")) + + event_type = self.headers.get("X-GitHub-Event") + # Worth noting that the action field can be the same for different + # events that we want to track so we may want some custom logic in the + # future to handle this or not bother with auto-saving the payload from + # it. + action = payload.get("action", "default") + + filename = Path(f"fixtures/{event_type}/{action}.json") + filename.parent.mkdir(parents=True, exist_ok=True) + with open(filename, "w") as f: + json.dump(payload, f, indent=2) + + print(f"Received {event_type} event with action: {action}") + print(f"Payload saved to {filename}") + + self.send_response(200) + self.end_headers() + + +def run_server(port=3000): + server_address = ("", port) + httpd = HTTPServer(server_address, WebhookHandler) + print(f"Server running on http://localhost:{port}") + httpd.serve_forever() + + +if __name__ == "__main__": + run_server()