Skip to content

Commit d9c936f

Browse files
committed
Fixed to detect comment changes
1 parent 7b1abc0 commit d9c936f

1 file changed

Lines changed: 224 additions & 19 deletions

File tree

.github/workflows/pr.yml

Lines changed: 224 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
1-
name: PR updated → dispatch to coding agent
1+
name: PR/Issue updated or commented → dispatch to coding agent
22

33
on:
44
pull_request:
55
types: [opened, reopened, synchronize, ready_for_review, edited]
6+
issue_comment:
7+
types: [created] # Issue comments + PR Conversation tab comments
8+
pull_request_review_comment:
9+
types: [created] # Inline PR code comments
10+
pull_request_review:
11+
types: [submitted] # PR review submitted (approve/request-changes/comment)
612

713
permissions:
814
contents: read
915
pull-requests: read
16+
issues: read
17+
18+
# Set these as Repository Variables (Settings → Variables)
19+
# ADMIN_HANDLE = thejhh
20+
# CODING_AGENT_HANDLE = heusalagroupbot
21+
env:
22+
ADMIN_HANDLE: ${{ vars.ADMIN_HANDLE }}
23+
CODING_AGENT_HANDLE: ${{ vars.CODING_AGENT_HANDLE }}
1024

1125
concurrency:
12-
group: pr-${{ github.event.pull_request.number }}-dispatch
26+
group: dispatch-${{ github.event.pull_request.number || github.event.issue.number || github.run_id }}
1327
cancel-in-progress: true
1428

1529
jobs:
16-
dispatch:
17-
# Require: internal actor, not a fork, and PR targets main (tweak branch if needed)
18-
if: ${{ !github.event.pull_request.head.repo.fork
19-
&& contains(fromJSON('["thejhh","heusalagroupbot"]'), github.actor)
30+
31+
# ---------------------------
32+
# PR lifecycle triggers
33+
# ---------------------------
34+
dispatch_pr:
35+
if: ${{ github.event_name == 'pull_request'
36+
&& !github.event.pull_request.head.repo.fork
37+
&& (github.actor == env.ADMIN_HANDLE)
2038
&& github.event.pull_request.base.ref == 'main' }}
2139
runs-on: ubuntu-latest
2240
timeout-minutes: 5
23-
2441
steps:
25-
- name: Build payload
26-
id: payload
42+
- name: Build payload (PR event)
2743
run: |
2844
jq -n \
2945
--arg repo "${{ github.repository }}" \
@@ -33,35 +49,224 @@ jobs:
3349
--arg head_repo "${{ github.event.pull_request.head.repo.full_name }}" \
3450
--arg head_ref "${{ github.event.pull_request.head.ref }}" \
3551
--arg base_ref "${{ github.event.pull_request.base.ref }}" \
52+
--arg actor "${{ github.actor }}" \
3653
'{event_type:"coding_agent_dispatch",
37-
client_payload:{repo:$repo,pr:$pr,pr_head_sha:$sha,pr_html_url:$url,
38-
head_repo:$head_repo,head_ref:$head_ref,base_ref:$base_ref}}' \
39-
> payload.json
54+
client_payload:{
55+
trigger:"pull_request",
56+
repo:$repo,
57+
pr:$pr,
58+
pr_head_sha:$sha,
59+
pr_html_url:$url,
60+
head_repo:$head_repo,
61+
head_ref:$head_ref,
62+
base_ref:$base_ref,
63+
actor:$actor
64+
}}' \
65+
> payload.json
4066
4167
- name: Preflight (token & target repo access)
4268
env:
4369
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
4470
run: |
4571
set -euo pipefail
46-
4772
TARGET="hyperifyio/aibuddy"
73+
if [[ -z "${GH_TOKEN:-}" ]]; then
74+
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
75+
exit 1
76+
fi
77+
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
78+
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
79+
cat err.txt || true
80+
exit 1
81+
fi
82+
jq -e . payload.json >/dev/null
4883
84+
- name: Send repository_dispatch to aibuddy (gh api)
85+
env:
86+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
87+
run: |
88+
set -euo pipefail
89+
gh api repos/hyperifyio/aibuddy/dispatches \
90+
--method POST \
91+
-H "Accept: application/vnd.github+json" \
92+
--input payload.json
93+
echo "repository_dispatch sent successfully (PR event)."
94+
95+
# ---------------------------
96+
# Issue/PR conversation comments (issue_comment)
97+
# ---------------------------
98+
dispatch_issue_comment:
99+
if: ${{ github.event_name == 'issue_comment'
100+
&& (github.actor == env.ADMIN_HANDLE)
101+
&& github.actor != env.CODING_AGENT_HANDLE }}
102+
runs-on: ubuntu-latest
103+
timeout-minutes: 5
104+
steps:
105+
- name: Build payload (issue_comment)
106+
env:
107+
GITHUB_EVENT_PATH: ${{ github.event_path }}
108+
run: |
109+
set -euo pipefail
110+
IS_PR=$(jq -r 'has("issue") and (.issue.pull_request != null)' "$GITHUB_EVENT_PATH")
111+
COMMENT_ID=$(jq -r '.comment.id' "$GITHUB_EVENT_PATH")
112+
COMMENT_URL=$(jq -r '.comment.html_url' "$GITHUB_EVENT_PATH")
113+
COMMENT_BODY=$(jq -r '.comment.body | if length > 500 then (.[:500] + "…") else . end' "$GITHUB_EVENT_PATH")
114+
115+
jq -n \
116+
--arg repo "${{ github.repository }}" \
117+
--argjson issue ${{ github.event.issue.number }} \
118+
--arg is_pr "$IS_PR" \
119+
--arg actor "${{ github.actor }}" \
120+
--arg comment_id "$COMMENT_ID" \
121+
--arg comment_url "$COMMENT_URL" \
122+
--arg body "$COMMENT_BODY" \
123+
'{event_type:"coding_agent_dispatch",
124+
client_payload:{
125+
trigger:"issue_comment",
126+
repo:$repo,
127+
issue:$issue,
128+
is_pr:($is_pr == "true"),
129+
comment_actor:$actor,
130+
comment_id:$comment_id,
131+
comment_html_url:$comment_url,
132+
comment_body:$body
133+
}}' \
134+
> payload.json
135+
jq -e . payload.json >/dev/null
136+
137+
- name: Preflight (token & target repo access)
138+
env:
139+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
140+
run: |
141+
set -euo pipefail
142+
TARGET="hyperifyio/aibuddy"
49143
if [[ -z "${GH_TOKEN:-}" ]]; then
50144
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
51145
exit 1
52146
fi
147+
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
148+
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
149+
cat err.txt || true
150+
exit 1
151+
fi
53152
54-
# Verify token can see the private repo; prints a helpful error otherwise
153+
- name: Send repository_dispatch to aibuddy (gh api)
154+
env:
155+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
156+
run: |
157+
set -euo pipefail
158+
gh api repos/hyperifyio/aibuddy/dispatches \
159+
--method POST \
160+
-H "Accept: application/vnd.github+json" \
161+
--input payload.json
162+
echo "repository_dispatch sent successfully (issue_comment)."
163+
164+
# ---------------------------
165+
# Inline PR review comments (pull_request_review_comment)
166+
# ---------------------------
167+
dispatch_pr_review_comment:
168+
if: ${{ github.event_name == 'pull_request_review_comment'
169+
&& (github.actor == env.ADMIN_HANDLE)
170+
&& github.actor != env.CODING_AGENT_HANDLE }}
171+
runs-on: ubuntu-latest
172+
timeout-minutes: 5
173+
steps:
174+
- name: Build payload (pull_request_review_comment)
175+
run: |
176+
jq -n \
177+
--arg repo "${{ github.repository }}" \
178+
--argjson pr ${{ github.event.pull_request.number }} \
179+
--arg actor "${{ github.actor }}" \
180+
--arg comment_id "${{ github.event.comment.id }}" \
181+
--arg comment_url "${{ github.event.comment.html_url }}" \
182+
--arg body "${{ github.event.comment.body }}" \
183+
'{event_type:"coding_agent_dispatch",
184+
client_payload:{
185+
trigger:"pull_request_review_comment",
186+
repo:$repo,
187+
pr:$pr,
188+
comment_actor:$actor,
189+
comment_id:$comment_id,
190+
comment_html_url:$comment_url,
191+
comment_body:$body
192+
}}' \
193+
> payload.json
194+
jq -e . payload.json >/dev/null
195+
196+
- name: Preflight (token & target repo access)
197+
env:
198+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
199+
run: |
200+
set -euo pipefail
201+
TARGET="hyperifyio/aibuddy"
202+
if [[ -z "${GH_TOKEN:-}" ]]; then
203+
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
204+
exit 1
205+
fi
55206
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
56207
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
57208
cat err.txt || true
58209
exit 1
59210
fi
60211
61-
# Validate payload JSON
62-
if [[ ! -s payload.json ]] || ! jq -e . payload.json >/dev/null; then
63-
echo "::error title=Invalid payload::payload.json missing or not valid JSON"
64-
[[ -f payload.json ]] && cat payload.json || true
212+
- name: Send repository_dispatch to aibuddy (gh api)
213+
env:
214+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
215+
run: |
216+
set -euo pipefail
217+
gh api repos/hyperifyio/aibuddy/dispatches \
218+
--method POST \
219+
-H "Accept: application/vnd.github+json" \
220+
--input payload.json
221+
echo "repository_dispatch sent successfully (pull_request_review_comment)."
222+
223+
# ---------------------------
224+
# PR review submissions (pull_request_review)
225+
# ---------------------------
226+
dispatch_pr_review:
227+
if: ${{ github.event_name == 'pull_request_review'
228+
&& (github.actor == env.ADMIN_HANDLE)
229+
&& github.actor != env.CODING_AGENT_HANDLE }}
230+
runs-on: ubuntu-latest
231+
timeout-minutes: 5
232+
steps:
233+
- name: Build payload (pull_request_review)
234+
run: |
235+
jq -n \
236+
--arg repo "${{ github.repository }}" \
237+
--argjson pr ${{ github.event.pull_request.number }} \
238+
--arg actor "${{ github.actor }}" \
239+
--arg review_id "${{ github.event.review.id }}" \
240+
--arg review_url "${{ github.event.review.html_url }}" \
241+
--arg state "${{ github.event.review.state }}" \
242+
--arg body "${{ github.event.review.body }}" \
243+
'{event_type:"coding_agent_dispatch",
244+
client_payload:{
245+
trigger:"pull_request_review",
246+
repo:$repo,
247+
pr:$pr,
248+
review_actor:$actor,
249+
review_id:$review_id,
250+
review_html_url:$review_url,
251+
review_state:$state,
252+
review_body:$body
253+
}}' \
254+
> payload.json
255+
jq -e . payload.json >/dev/null
256+
257+
- name: Preflight (token & target repo access)
258+
env:
259+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
260+
run: |
261+
set -euo pipefail
262+
TARGET="hyperifyio/aibuddy"
263+
if [[ -z "${GH_TOKEN:-}" ]]; then
264+
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
265+
exit 1
266+
fi
267+
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
268+
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
269+
cat err.txt || true
65270
exit 1
66271
fi
67272
@@ -74,4 +279,4 @@ jobs:
74279
--method POST \
75280
-H "Accept: application/vnd.github+json" \
76281
--input payload.json
77-
echo "repository_dispatch sent successfully."
282+
echo "repository_dispatch sent successfully (pull_request_review)."

0 commit comments

Comments
 (0)