Skip to content

Commit d7689de

Browse files
thejhhCopilot
andauthored
Ci/fix task workflow 2 (#91)
* Fixed to detect comment changes * Fixed env. -> var. * Fixed typo .var -> .vars * Update .github/workflows/pr.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update .github/workflows/pr.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent bbc81e3 commit d7689de

1 file changed

Lines changed: 229 additions & 19 deletions

File tree

.github/workflows/pr.yml

Lines changed: 229 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 == vars.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,229 @@ 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 == vars.ADMIN_HANDLE)
101+
&& github.actor != vars.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+
# Configurable limit for comment body truncation (default: 500)
109+
COMMENT_BODY_TRUNCATE_LIMIT: ${{ env.COMMENT_BODY_TRUNCATE_LIMIT || 500 }}
110+
run: |
111+
set -euo pipefail
112+
IS_PR=$(jq -r 'has("issue") and (.issue.pull_request != null)' "$GITHUB_EVENT_PATH")
113+
COMMENT_ID=$(jq -r '.comment.id' "$GITHUB_EVENT_PATH")
114+
COMMENT_URL=$(jq -r '.comment.html_url' "$GITHUB_EVENT_PATH")
115+
# Truncate comment body to configurable limit
116+
COMMENT_BODY=$(jq -r --argjson limit "$COMMENT_BODY_TRUNCATE_LIMIT" '.comment.body | if length > $limit then (.[0:$limit] + "…") else . end' "$GITHUB_EVENT_PATH")
117+
118+
jq -n \
119+
--arg repo "${{ github.repository }}" \
120+
--argjson issue ${{ github.event.issue.number }} \
121+
--arg is_pr "$IS_PR" \
122+
--arg actor "${{ github.actor }}" \
123+
--arg comment_id "$COMMENT_ID" \
124+
--arg comment_url "$COMMENT_URL" \
125+
--arg body "$COMMENT_BODY" \
126+
'{event_type:"coding_agent_dispatch",
127+
client_payload:{
128+
trigger:"issue_comment",
129+
repo:$repo,
130+
issue:$issue,
131+
is_pr:($is_pr == "true"),
132+
comment_actor:$actor,
133+
comment_id:$comment_id,
134+
comment_html_url:$comment_url,
135+
comment_body:$body
136+
}}' \
137+
> payload.json
138+
jq -e . payload.json >/dev/null
139+
140+
- name: Preflight (token & target repo access)
141+
env:
142+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
143+
run: |
144+
set -euo pipefail
145+
TARGET="hyperifyio/aibuddy"
49146
if [[ -z "${GH_TOKEN:-}" ]]; then
50147
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
51148
exit 1
52149
fi
150+
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
151+
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
152+
cat err.txt || true
153+
exit 1
154+
fi
53155
54-
# Verify token can see the private repo; prints a helpful error otherwise
156+
- name: Send repository_dispatch to aibuddy (gh api)
157+
env:
158+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
159+
run: |
160+
set -euo pipefail
161+
gh api repos/hyperifyio/aibuddy/dispatches \
162+
--method POST \
163+
-H "Accept: application/vnd.github+json" \
164+
--input payload.json
165+
echo "repository_dispatch sent successfully (issue_comment)."
166+
167+
# ---------------------------
168+
# Inline PR review comments (pull_request_review_comment)
169+
# ---------------------------
170+
dispatch_pr_review_comment:
171+
if: ${{ github.event_name == 'pull_request_review_comment'
172+
&& (github.actor == vars.ADMIN_HANDLE)
173+
&& github.actor != vars.CODING_AGENT_HANDLE }}
174+
runs-on: ubuntu-latest
175+
timeout-minutes: 5
176+
steps:
177+
- name: Build payload (pull_request_review_comment)
178+
run: |
179+
# Truncate comment body to 65000 characters to avoid payload/argument limits
180+
TRUNC_BODY="$(echo "${{ github.event.comment.body }}" | head -c 65000)"
181+
jq -n \
182+
--arg repo "${{ github.repository }}" \
183+
--argjson pr ${{ github.event.pull_request.number }} \
184+
--arg actor "${{ github.actor }}" \
185+
--arg comment_id "${{ github.event.comment.id }}" \
186+
--arg comment_url "${{ github.event.comment.html_url }}" \
187+
--arg body "$TRUNC_BODY" \
188+
'{event_type:"coding_agent_dispatch",
189+
client_payload:{
190+
trigger:"pull_request_review_comment",
191+
repo:$repo,
192+
pr:$pr,
193+
comment_actor:$actor,
194+
comment_id:$comment_id,
195+
comment_html_url:$comment_url,
196+
comment_body:$body
197+
}}' \
198+
> payload.json
199+
jq -e . payload.json >/dev/null
200+
201+
- name: Preflight (token & target repo access)
202+
env:
203+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
204+
run: |
205+
set -euo pipefail
206+
TARGET="hyperifyio/aibuddy"
207+
if [[ -z "${GH_TOKEN:-}" ]]; then
208+
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
209+
exit 1
210+
fi
55211
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
56212
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
57213
cat err.txt || true
58214
exit 1
59215
fi
60216
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
217+
- name: Send repository_dispatch to aibuddy (gh api)
218+
env:
219+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
220+
run: |
221+
set -euo pipefail
222+
gh api repos/hyperifyio/aibuddy/dispatches \
223+
--method POST \
224+
-H "Accept: application/vnd.github+json" \
225+
--input payload.json
226+
echo "repository_dispatch sent successfully (pull_request_review_comment)."
227+
228+
# ---------------------------
229+
# PR review submissions (pull_request_review)
230+
# ---------------------------
231+
dispatch_pr_review:
232+
if: ${{ github.event_name == 'pull_request_review'
233+
&& (github.actor == vars.ADMIN_HANDLE)
234+
&& github.actor != vars.CODING_AGENT_HANDLE }}
235+
runs-on: ubuntu-latest
236+
timeout-minutes: 5
237+
steps:
238+
- name: Build payload (pull_request_review)
239+
run: |
240+
jq -n \
241+
--arg repo "${{ github.repository }}" \
242+
--argjson pr ${{ github.event.pull_request.number }} \
243+
--arg actor "${{ github.actor }}" \
244+
--arg review_id "${{ github.event.review.id }}" \
245+
--arg review_url "${{ github.event.review.html_url }}" \
246+
--arg state "${{ github.event.review.state }}" \
247+
--arg body "${{ github.event.review.body }}" \
248+
'{event_type:"coding_agent_dispatch",
249+
client_payload:{
250+
trigger:"pull_request_review",
251+
repo:$repo,
252+
pr:$pr,
253+
review_actor:$actor,
254+
review_id:$review_id,
255+
review_html_url:$review_url,
256+
review_state:$state,
257+
review_body:$body
258+
}}' \
259+
> payload.json
260+
jq -e . payload.json >/dev/null
261+
262+
- name: Preflight (token & target repo access)
263+
env:
264+
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
265+
run: |
266+
set -euo pipefail
267+
TARGET="hyperifyio/aibuddy"
268+
if [[ -z "${GH_TOKEN:-}" ]]; then
269+
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
270+
exit 1
271+
fi
272+
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
273+
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
274+
cat err.txt || true
65275
exit 1
66276
fi
67277
@@ -74,4 +284,4 @@ jobs:
74284
--method POST \
75285
-H "Accept: application/vnd.github+json" \
76286
--input payload.json
77-
echo "repository_dispatch sent successfully."
287+
echo "repository_dispatch sent successfully (pull_request_review)."

0 commit comments

Comments
 (0)