-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add config to automate fixtures (#13)
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |