Skip to content

Commit e641e5e

Browse files
committed
Refactor PR Event Logger workflow to improve event handling and logging
1 parent 22c368f commit e641e5e

File tree

2 files changed

+39
-45
lines changed

2 files changed

+39
-45
lines changed

.github/workflows/reviewer.yml

+20-37
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,26 @@
1-
name: PR Reviewer Agent
1+
name: PR Event Logger
2+
23
on:
3-
issue_comment:
4-
types: [created]
54
pull_request:
6-
types: [opened, synchronize, reopened]
7-
push:
5+
types: [opened, reopened, ready_for_review, review_requested]
6+
issue_comment:
7+
types: [created, edited]
8+
89
jobs:
9-
process_pr_events:
10+
log-event:
1011
runs-on: ubuntu-latest
1112
steps:
12-
- name: Extract event details
13-
run: echo "EVENT_PAYLOAD=$(jq -c . < $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
14-
15-
- name: Generate Signature and Encrypt Token
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.9'
20+
21+
- name: Run event logger
1622
env:
17-
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
18-
API_TOKEN: ${{ secrets.API_TOKEN }}
19-
run: |
20-
# Generate signature for the payload
21-
SIGNATURE=$(echo -n "$EVENT_PAYLOAD" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" | cut -d " " -f2)
22-
echo "SIGNATURE=$SIGNATURE" >> $GITHUB_ENV
23-
24-
# Create a consistent key from the webhook secret
25-
KEY=$(echo -n "$WEBHOOK_SECRET" | openssl dgst -sha256 | cut -d ' ' -f2)
26-
27-
# Generate a random IV
28-
IV=$(openssl rand -hex 16)
29-
30-
# Encrypt token with proper padding
31-
ENCRYPTED_TOKEN=$(echo -n "$API_TOKEN" | openssl enc -aes-256-cbc -a -A -K "$KEY" -iv "$IV" -md sha256)
32-
33-
echo "ENCRYPTED_TOKEN=$ENCRYPTED_TOKEN" >> $GITHUB_ENV
34-
echo "TOKEN_IV=$IV" >> $GITHUB_ENV
35-
36-
- name: Call External API (With Encrypted Token)
37-
run: |
38-
curl -X POST https://firstly-worthy-chamois.ngrok-free.app/github-webhook \
39-
-H "Content-Type: application/json" \
40-
-H "X-Hub-Signature-256: sha256=$SIGNATURE" \
41-
-H "X-Encrypted-Token: $ENCRYPTED_TOKEN" \
42-
-H "X-Token-IV: $TOKEN_IV" \
43-
-d "$EVENT_PAYLOAD"
23+
GITHUB_EVENT_NAME: ${{ github.event_name }}
24+
GITHUB_EVENT_PATH: ${{ github.event_path }}
25+
run: python main.py
26+

main.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
from dotenv import load_dotenv
2-
from fastapi import FastAPI
3-
import listener
1+
import os
2+
import json
43

5-
app = FastAPI()
4+
def main():
5+
github_event_name = os.getenv("GITHUB_EVENT_NAME")
6+
github_event_path = os.getenv("GITHUB_EVENT_PATH")
67

7-
# Include listener router
8-
app.include_router(listener.router)
8+
print(f"Received GitHub event: {github_event_name}")
9+
10+
if not github_event_path:
11+
print("GITHUB_EVENT_PATH not set, cannot read event data.")
12+
return
13+
14+
try:
15+
with open(github_event_path, "r") as file:
16+
event_data = json.load(file)
17+
print("Event JSON Payload:")
18+
print(json.dumps(event_data, indent=2))
19+
except Exception as e:
20+
print(f"Error reading event data: {e}")
921

1022
if __name__ == "__main__":
11-
import uvicorn
12-
uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)
23+
main()

0 commit comments

Comments
 (0)