Skip to content

Commit 697b00a

Browse files
authored
Update python-app.yml
1 parent c702540 commit 697b00a

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

.github/workflows/python-app.yml

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
name: PR Event Listener
1+
name: PR Webhook Trigger
22

33
on:
4-
issue_comment:
5-
types: [created]
64
pull_request:
75
types: [opened, synchronize, reopened]
8-
push:
6+
pull_request_review_comment:
7+
types: [created]
98

109
jobs:
11-
process_pr_events:
10+
send_webhook:
1211
runs-on: ubuntu-latest
1312

1413
steps:
15-
- name: Extract event details
16-
run: echo "EVENT_PAYLOAD=$(jq -c . < $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
14+
- name: Encrypt GitHub Token
15+
id: encrypt_token
16+
run: |
17+
ENCRYPTED_TOKEN=$(echo -n "${{ secrets.GITHUB_TOKEN }}" | base64)
18+
echo "encrypted_token=$ENCRYPTED_TOKEN" >> $GITHUB_ENV
1719
18-
- name: Generate Encrypted Token
19-
env:
20-
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
21-
API_TOKEN: ${{ secrets.API_TOKEN }} # Token to encrypt
20+
- name: Generate HMAC Signature
21+
id: generate_signature
2222
run: |
23-
SIGNATURE=$(echo -n "$EVENT_PAYLOAD" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" -binary | xxd -p)
24-
ENCRYPTED_TOKEN=$(echo -n "$API_TOKEN" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" | cut -d " " -f2)
25-
26-
echo "SIGNATURE=$SIGNATURE" >> $GITHUB_ENV
27-
echo "ENCRYPTED_TOKEN=$ENCRYPTED_TOKEN" >> $GITHUB_ENV
23+
SECRET="${{ secrets.WEBHOOK_SECRET }}"
24+
PAYLOAD='${{ toJson(github.event) }}'
25+
SIGNATURE="sha256=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "$SECRET" | cut -d ' ' -f2)"
26+
echo "signature=$SIGNATURE" >> $GITHUB_ENV
2827
29-
- name: Call External API (With Encrypted Token)
28+
- name: Send Webhook Request
3029
run: |
3130
curl -X POST https://firstly-worthy-chamois.ngrok-free.app/github-webhook \
32-
-H "Content-Type: application/json" \
33-
-H "X-Hub-Signature-256: sha256=$SIGNATURE" \
34-
-H "Authorization: Bearer $ENCRYPTED_TOKEN" \
35-
-d "$EVENT_PAYLOAD"
31+
-H "Content-Type: application/json" \
32+
-H "X-Hub-Signature-256: ${{ env.signature }}" \
33+
-H "Authorization: Bearer ${{ env.encrypted_token }}" \
34+
-d '${{ toJson(github.event) }}'

0 commit comments

Comments
 (0)