|
| 1 | +name: PR updated → dispatch to coding agent |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize, ready_for_review, edited] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: read |
| 10 | + |
| 11 | +env: |
| 12 | + TARGET_REPOSITORY: hyperifyio/goagent |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: pr-${{ github.event.pull_request.number }}-dispatch |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + dispatch: |
| 20 | + if: ${{ !github.event.pull_request.head.repo.fork && github.repository == env.TARGET_REPOSITORY }} |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Build payload |
| 24 | + id: payload |
| 25 | + run: | |
| 26 | + jq -n \ |
| 27 | + --arg repo "${{ github.repository }}" \ |
| 28 | + --argjson pr ${{ github.event.pull_request.number }} \ |
| 29 | + --arg sha "${{ github.event.pull_request.head.sha }}" \ |
| 30 | + --arg url "${{ github.event.pull_request.html_url }}" \ |
| 31 | + --arg head_repo "${{ github.event.pull_request.head.repo.full_name }}" \ |
| 32 | + --arg head_ref "${{ github.event.pull_request.head.ref }}" \ |
| 33 | + --arg base_ref "${{ github.event.pull_request.base.ref }}" \ |
| 34 | + '{event_type:"coding_agent_dispatch", |
| 35 | + client_payload:{repo:$repo,pr:$pr,pr_head_sha:$sha,pr_html_url:$url, |
| 36 | + head_repo:$head_repo,head_ref:$head_ref,base_ref:$base_ref}}' \ |
| 37 | + > payload.json |
| 38 | +
|
| 39 | + - name: Send repository_dispatch to aibuddy |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }} |
| 42 | + run: | |
| 43 | + set -euo pipefail |
| 44 | +
|
| 45 | + # Secret present? |
| 46 | + if [[ -z "${GH_TOKEN:-}" ]]; then |
| 47 | + echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set." |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +
|
| 51 | + # Payload present? |
| 52 | + if [[ ! -s payload.json ]]; then |
| 53 | + echo "::error title=Missing payload::payload.json was not created." |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | +
|
| 57 | + # Validate JSON if jq exists |
| 58 | + if command -v jq >/dev/null 2>&1; then |
| 59 | + jq -e . payload.json >/dev/null || { |
| 60 | + echo "::error title=Invalid JSON payload::payload.json is not valid JSON" |
| 61 | + cat payload.json |
| 62 | + exit 1 |
| 63 | + } |
| 64 | + fi |
| 65 | +
|
| 66 | + # Dispatch (GitHub returns 204 No Content on success) |
| 67 | + gh api repos/hyperifyio/aibuddy/dispatches \ |
| 68 | + --method POST \ |
| 69 | + -H "Accept: application/vnd.github+json" \ |
| 70 | + --input payload.json |
| 71 | +
|
| 72 | + echo "repository_dispatch sent successfully." |
0 commit comments