-
Notifications
You must be signed in to change notification settings - Fork 0
287 lines (269 loc) · 11 KB
/
pr.yml
File metadata and controls
287 lines (269 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
name: PR/Issue updated or commented → dispatch to coding agent
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review, edited]
issue_comment:
types: [created] # Issue comments + PR Conversation tab comments
pull_request_review_comment:
types: [created] # Inline PR code comments
pull_request_review:
types: [submitted] # PR review submitted (approve/request-changes/comment)
permissions:
contents: read
pull-requests: read
issues: read
# Set these as Repository Variables (Settings → Variables)
# ADMIN_HANDLE = thejhh
# CODING_AGENT_HANDLE = heusalagroupbot
env:
ADMIN_HANDLE: ${{ vars.ADMIN_HANDLE }}
CODING_AGENT_HANDLE: ${{ vars.CODING_AGENT_HANDLE }}
concurrency:
group: dispatch-${{ github.event.pull_request.number || github.event.issue.number || github.run_id }}
cancel-in-progress: true
jobs:
# ---------------------------
# PR lifecycle triggers
# ---------------------------
dispatch_pr:
if: ${{ github.event_name == 'pull_request'
&& !github.event.pull_request.head.repo.fork
&& (github.actor == vars.ADMIN_HANDLE)
&& github.event.pull_request.base.ref == 'main' }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Build payload (PR event)
run: |
jq -n \
--arg repo "${{ github.repository }}" \
--argjson pr ${{ github.event.pull_request.number }} \
--arg sha "${{ github.event.pull_request.head.sha }}" \
--arg url "${{ github.event.pull_request.html_url }}" \
--arg head_repo "${{ github.event.pull_request.head.repo.full_name }}" \
--arg head_ref "${{ github.event.pull_request.head.ref }}" \
--arg base_ref "${{ github.event.pull_request.base.ref }}" \
--arg actor "${{ github.actor }}" \
'{event_type:"coding_agent_dispatch",
client_payload:{
trigger:"pull_request",
repo:$repo,
pr:$pr,
pr_head_sha:$sha,
pr_html_url:$url,
head_repo:$head_repo,
head_ref:$head_ref,
base_ref:$base_ref,
actor:$actor
}}' \
> payload.json
- name: Preflight (token & target repo access)
env:
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
run: |
set -euo pipefail
TARGET="hyperifyio/aibuddy"
if [[ -z "${GH_TOKEN:-}" ]]; then
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
exit 1
fi
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
cat err.txt || true
exit 1
fi
jq -e . payload.json >/dev/null
- name: Send repository_dispatch to aibuddy (gh api)
env:
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
run: |
set -euo pipefail
gh api repos/hyperifyio/aibuddy/dispatches \
--method POST \
-H "Accept: application/vnd.github+json" \
--input payload.json
echo "repository_dispatch sent successfully (PR event)."
# ---------------------------
# Issue/PR conversation comments (issue_comment)
# ---------------------------
dispatch_issue_comment:
if: ${{ github.event_name == 'issue_comment'
&& (github.actor == vars.ADMIN_HANDLE)
&& github.actor != vars.CODING_AGENT_HANDLE }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Build payload (issue_comment)
env:
GITHUB_EVENT_PATH: ${{ github.event_path }}
# Configurable limit for comment body truncation (default: 500)
COMMENT_BODY_TRUNCATE_LIMIT: ${{ env.COMMENT_BODY_TRUNCATE_LIMIT || 500 }}
run: |
set -euo pipefail
IS_PR=$(jq -r 'has("issue") and (.issue.pull_request != null)' "$GITHUB_EVENT_PATH")
COMMENT_ID=$(jq -r '.comment.id' "$GITHUB_EVENT_PATH")
COMMENT_URL=$(jq -r '.comment.html_url' "$GITHUB_EVENT_PATH")
# Truncate comment body to configurable limit
COMMENT_BODY=$(jq -r --argjson limit "$COMMENT_BODY_TRUNCATE_LIMIT" '.comment.body | if length > $limit then (.[0:$limit] + "…") else . end' "$GITHUB_EVENT_PATH")
jq -n \
--arg repo "${{ github.repository }}" \
--argjson issue ${{ github.event.issue.number }} \
--arg is_pr "$IS_PR" \
--arg actor "${{ github.actor }}" \
--arg comment_id "$COMMENT_ID" \
--arg comment_url "$COMMENT_URL" \
--arg body "$COMMENT_BODY" \
'{event_type:"coding_agent_dispatch",
client_payload:{
trigger:"issue_comment",
repo:$repo,
issue:$issue,
is_pr:($is_pr == "true"),
comment_actor:$actor,
comment_id:$comment_id,
comment_html_url:$comment_url,
comment_body:$body
}}' \
> payload.json
jq -e . payload.json >/dev/null
- name: Preflight (token & target repo access)
env:
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
run: |
set -euo pipefail
TARGET="hyperifyio/aibuddy"
if [[ -z "${GH_TOKEN:-}" ]]; then
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
exit 1
fi
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
cat err.txt || true
exit 1
fi
- name: Send repository_dispatch to aibuddy (gh api)
env:
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
run: |
set -euo pipefail
gh api repos/hyperifyio/aibuddy/dispatches \
--method POST \
-H "Accept: application/vnd.github+json" \
--input payload.json
echo "repository_dispatch sent successfully (issue_comment)."
# ---------------------------
# Inline PR review comments (pull_request_review_comment)
# ---------------------------
dispatch_pr_review_comment:
if: ${{ github.event_name == 'pull_request_review_comment'
&& (github.actor == vars.ADMIN_HANDLE)
&& github.actor != vars.CODING_AGENT_HANDLE }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Build payload (pull_request_review_comment)
run: |
# Truncate comment body to 65000 characters to avoid payload/argument limits
TRUNC_BODY="$(echo "${{ github.event.comment.body }}" | head -c 65000)"
jq -n \
--arg repo "${{ github.repository }}" \
--argjson pr ${{ github.event.pull_request.number }} \
--arg actor "${{ github.actor }}" \
--arg comment_id "${{ github.event.comment.id }}" \
--arg comment_url "${{ github.event.comment.html_url }}" \
--arg body "$TRUNC_BODY" \
'{event_type:"coding_agent_dispatch",
client_payload:{
trigger:"pull_request_review_comment",
repo:$repo,
pr:$pr,
comment_actor:$actor,
comment_id:$comment_id,
comment_html_url:$comment_url,
comment_body:$body
}}' \
> payload.json
jq -e . payload.json >/dev/null
- name: Preflight (token & target repo access)
env:
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
run: |
set -euo pipefail
TARGET="hyperifyio/aibuddy"
if [[ -z "${GH_TOKEN:-}" ]]; then
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
exit 1
fi
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
cat err.txt || true
exit 1
fi
- name: Send repository_dispatch to aibuddy (gh api)
env:
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
run: |
set -euo pipefail
gh api repos/hyperifyio/aibuddy/dispatches \
--method POST \
-H "Accept: application/vnd.github+json" \
--input payload.json
echo "repository_dispatch sent successfully (pull_request_review_comment)."
# ---------------------------
# PR review submissions (pull_request_review)
# ---------------------------
dispatch_pr_review:
if: ${{ github.event_name == 'pull_request_review'
&& (github.actor == vars.ADMIN_HANDLE)
&& github.actor != vars.CODING_AGENT_HANDLE }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Build payload (pull_request_review)
run: |
jq -n \
--arg repo "${{ github.repository }}" \
--argjson pr ${{ github.event.pull_request.number }} \
--arg actor "${{ github.actor }}" \
--arg review_id "${{ github.event.review.id }}" \
--arg review_url "${{ github.event.review.html_url }}" \
--arg state "${{ github.event.review.state }}" \
--arg body "${{ github.event.review.body }}" \
'{event_type:"coding_agent_dispatch",
client_payload:{
trigger:"pull_request_review",
repo:$repo,
pr:$pr,
review_actor:$actor,
review_id:$review_id,
review_html_url:$review_url,
review_state:$state,
review_body:$body
}}' \
> payload.json
jq -e . payload.json >/dev/null
- name: Preflight (token & target repo access)
env:
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
run: |
set -euo pipefail
TARGET="hyperifyio/aibuddy"
if [[ -z "${GH_TOKEN:-}" ]]; then
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
exit 1
fi
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
cat err.txt || true
exit 1
fi
- name: Send repository_dispatch to aibuddy (gh api)
env:
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
run: |
set -euo pipefail
gh api repos/hyperifyio/aibuddy/dispatches \
--method POST \
-H "Accept: application/vnd.github+json" \
--input payload.json
echo "repository_dispatch sent successfully (pull_request_review)."