Skip to content

Commit bec078a

Browse files
committed
ci: dispatch PR lifecycle events to a downstream repo
Mirrors the main-image dispatch in publish.yml: on pull request state changes (opened, closed, reopened, ready for review, converted to draft, title edits) and pushes to main, send a repository_dispatch so downstream consumers can react to PR lifecycle events without polling. Same-repo events only; the target repo is configurable via repository variables.
1 parent 954ee5c commit bec078a

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

.github/workflows/pr-events.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: 📣 Dispatch PR events
2+
3+
# Notifies downstream consumers (via repository_dispatch) when pull requests
4+
# change state, so they can react to PR lifecycle events without polling.
5+
# Mirrors the main-image dispatch in publish.yml: target repo defaults to the
6+
# canonical value and can be overridden by a repository variable.
7+
8+
on:
9+
pull_request:
10+
types: [opened, reopened, closed, ready_for_review, converted_to_draft, edited]
11+
push:
12+
branches: [main]
13+
14+
jobs:
15+
dispatch:
16+
name: Send repository_dispatch
17+
runs-on: ubuntu-latest
18+
permissions: {}
19+
# Same-repo events only: fork PRs have no secrets, and title-only edits are
20+
# the only `edited` payloads downstream cares about.
21+
if: >-
22+
github.repository == (vars.PR_EVENTS_DISPATCH_REPO || 'triggerdotdev/trigger.dev') &&
23+
(github.event_name == 'push' ||
24+
(github.event.pull_request.head.repo.full_name == github.repository &&
25+
(github.event.action != 'edited' || github.event.changes.title)))
26+
steps:
27+
- name: Build dispatch payload
28+
id: payload
29+
env:
30+
EVENT_NAME: ${{ github.event_name }}
31+
ACTION: ${{ github.event.action }}
32+
PR_NUMBER: ${{ github.event.pull_request.number }}
33+
COMMIT: ${{ github.sha }}
34+
run: |
35+
set -euo pipefail
36+
# jq --arg JSON-escapes every value so nothing can inject into the payload.
37+
if [[ "$EVENT_NAME" == "push" ]]; then
38+
payload=$(jq -nc --arg c "$COMMIT" '{action: "push", commit: $c}')
39+
else
40+
payload=$(jq -nc --arg a "$ACTION" --arg n "$PR_NUMBER" '{action: $a, number: ($n | tonumber)}')
41+
fi
42+
echo "client_payload=$payload" >> "$GITHUB_OUTPUT"
43+
44+
- name: Send repository_dispatch
45+
uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # v4.0.1
46+
with:
47+
token: ${{ secrets.CROSS_REPO_PAT }}
48+
repository: ${{ vars.PR_EVENTS_DISPATCH_TARGET || 'triggerdotdev/cloud' }}
49+
event-type: oss-pr-event
50+
client-payload: ${{ steps.payload.outputs.client_payload }}

0 commit comments

Comments
 (0)