Repository navigation
259 lines (253 loc) · 13.2 KB
/
Copy pathclawsweeper-dispatch.yml
File metadata and controls
259 lines (253 loc) · 13.2 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
name: ClawSweeper Dispatch
on:
issues:
types: [opened, reopened, edited, labeled, unlabeled]
issue_comment:
types: [created, edited]
pull_request_target: # zizmor: ignore[dangerous-triggers] maintainer-owned external dispatch; no checkout or untrusted PR code execution
types: [opened, reopened, synchronize, ready_for_review, edited, labeled, unlabeled]
permissions:
contents: read
concurrency:
group: clawsweeper-dispatch-${{ github.repository }}-${{ github.event_name }}-${{ github.event.comment.id || github.event.issue.number || github.event.pull_request.number || github.run_id }}-${{ endsWith(github.actor, '[bot]') && (github.event.action == 'labeled' || github.event.action == 'unlabeled') && github.actor || 'dispatchable' }}
cancel-in-progress: ${{ github.event.action == 'edited' || github.event.action == 'synchronize' || github.event.action == 'ready_for_review' }}
jobs:
dispatch:
runs-on: ubuntu-latest
# id-token proves this repository, event, branch, and run to the queue.
# The job never checks out or executes pull request code.
permissions:
contents: read
id-token: write
if: ${{ !(endsWith(github.actor, '[bot]') && (github.event.action == 'labeled' || github.event.action == 'unlabeled')) }}
env:
SUPERSEDES_IN_PROGRESS: ${{ (github.event.action == 'edited' || github.event.action == 'synchronize' || github.event.action == 'ready_for_review') && 'true' || 'false' }}
steps:
- name: Debounce bursty metadata events
if: ${{ github.event.action == 'labeled' || github.event.action == 'unlabeled' }}
run: sleep 20
- name: Pre-filter ClawSweeper comment
id: comment_filter
if: ${{ github.event_name == 'issue_comment' }}
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
set -euo pipefail
if [[ "$COMMENT_BODY" == *"<!-- clawsweeper-maintainer-opt-in:"* ]]; then
echo "is_command=false" >> "$GITHUB_OUTPUT"
exit 0
fi
if grep -Eiq '(^|[[:space:]])@(clawsweeper|openclaw-clawsweeper)\b(\[bot\])?|(^|[[:space:]])/(clawsweeper|review|re-review|rerun([[:space:]]+|-)?review|status|explain|fix|build|implement|create([[:space:]]+|-)?pr|fix([[:space:]]+|-)?issue|autofix|auto([[:space:]]+|-)?fix|automerge|auto([[:space:]]+|-)?merge|approve|stop|autoclose)\b' <<< "$COMMENT_BODY"; then
echo "is_command=true" >> "$GITHUB_OUTPUT"
else
echo "is_command=false" >> "$GITHUB_OUTPUT"
fi
- name: Dispatch exact ClawSweeper review
if: ${{ github.event_name != 'issue_comment' }}
env:
TARGET_REPO: ${{ github.repository }}
TARGET_BRANCH: ${{ github.event.repository.default_branch }}
ITEM_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }}
ITEM_KIND: ${{ github.event_name == 'pull_request_target' && 'pull_request' || 'issue' }}
SOURCE_EVENT: ${{ github.event_name }}
SOURCE_ACTION: ${{ github.event.action }}
TARGET_DISPATCH_URL: https://clawsweeper.openclaw.ai/github/target-dispatch
run: |
set -euo pipefail
source_identity_json="$(node <<'NODE'
const crypto = require("node:crypto");
const fs = require("node:fs");
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));
const pullRequest = event.pull_request && typeof event.pull_request === "object"
? event.pull_request
: {};
const issue = event.issue && typeof event.issue === "object" ? event.issue : {};
const source = process.env.ITEM_KIND === "pull_request" ? pullRequest : issue;
const headSha = String(pullRequest.head?.sha || "").trim().toLowerCase();
const baseSha = String(pullRequest.base?.sha || "").trim().toLowerCase();
const updatedAt = String(pullRequest.updated_at || "").trim();
const queueClaim = {};
const result = { queue_claim: queueClaim };
const sourceUpdatedAt = String(source.updated_at || "").trim();
if (sourceUpdatedAt && Number.isFinite(Date.parse(sourceUpdatedAt))) {
queueClaim.source_updated_at = sourceUpdatedAt;
}
if (
typeof source.title === "string" &&
(source.body === null || typeof source.body === "string") &&
typeof source.locked === "boolean" &&
Array.isArray(source.labels)
) {
const labels = [
...new Set(
source.labels
.map((label) => String(label?.name || "").trim().toLowerCase())
.filter((label) => {
if (!label) return false;
if (label === "proof: override") return true;
if (/^(?:status|rating|proof|merge-risk|impact|issue-rating):/.test(label)) return false;
if (/^p[0-3]$/.test(label)) return false;
if ([
"maturity:stable",
"feature: ✨ showcase",
"good first issue",
"mantis: telegram-visible-proof",
"proof: telegram-e2e",
"triage: needs-real-behavior-proof",
"clawsweeper-recovery-stuck",
"no-stale",
"stale",
].includes(label)) return false;
return !label.startsWith("clawsweeper:") || [
"clawsweeper:autofix",
"clawsweeper:automerge",
"clawsweeper:human-review",
"clawsweeper:manual-only",
"clawsweeper:bulk-filed",
].includes(label);
}),
),
].sort();
queueClaim.source_content_revision = crypto
.createHash("sha256")
.update(
JSON.stringify({
version: 2,
title: source.title,
body: source.body || "",
locked: source.locked,
close_guard_labels: labels,
}),
)
.digest("hex");
}
if (process.env.ITEM_KIND === "pull_request") {
if (/^[0-9a-f]{40}$/.test(headSha)) queueClaim.source_head_sha = headSha;
if (/^[0-9a-f]{40}$/.test(baseSha)) queueClaim.source_base_sha = baseSha;
if (typeof pullRequest.draft === "boolean") {
queueClaim.source_is_draft = pullRequest.draft;
}
}
if (
process.env.ITEM_KIND !== "pull_request" ||
!/^[0-9a-f]{40}$/.test(headSha) ||
!updatedAt
) {
process.stdout.write(JSON.stringify(result));
} else {
result.ingress_route = "target_dispatcher";
result.ingress_fingerprint = crypto
.createHash("sha256")
.update(
JSON.stringify({
version: 1,
target_repo: String(process.env.TARGET_REPO || "").toLowerCase(),
item_number: Number(process.env.ITEM_NUMBER),
action: String(process.env.SOURCE_ACTION || ""),
head_sha: headSha,
updated_at: updatedAt,
body: typeof pullRequest.body === "string" ? pullRequest.body : "",
label: String(event.label?.name || ""),
}),
)
.digest("hex");
process.stdout.write(JSON.stringify(result));
}
NODE
)"
client_payload="$(jq -nc \
--arg target_repo "$TARGET_REPO" \
--arg target_branch "$TARGET_BRANCH" \
--argjson item_number "$ITEM_NUMBER" \
--arg item_kind "$ITEM_KIND" \
--arg source_event "$SOURCE_EVENT" \
--arg source_action "$SOURCE_ACTION" \
--argjson source_identity "$source_identity_json" \
--argjson supersedes_in_progress "$SUPERSEDES_IN_PROGRESS" \
'{target_repo:$target_repo,target_branch:$target_branch,item_number:$item_number,item_kind:$item_kind,source_event:$source_event,source_action:$source_action,supersedes_in_progress:$supersedes_in_progress} + $source_identity')"
# The App webhook remains an independent delivery route.
if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ] &&
[ -n "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ] &&
oidc_token="$(curl --fail --silent --show-error --connect-timeout 5 --max-time 15 \
--header "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
--get --data-urlencode "audience=$TARGET_DISPATCH_URL" \
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -er '.value | strings | select(length > 0)')" &&
[ -n "$oidc_token" ]; then
echo "::add-mask::$oidc_token"
direct_body="$RUNNER_TEMP/clawsweeper-direct-intake.json"
if direct_status="$(curl --silent --show-error --connect-timeout 5 --max-time 20 \
--request POST \
--header "authorization: Bearer $oidc_token" \
--header "content-type: application/json" \
--data "$client_payload" \
--output "$direct_body" \
--write-out '%{http_code}' \
"$TARGET_DISPATCH_URL")" &&
[[ "$direct_status" == 2[0-9][0-9] ]]; then
echo "Queued ClawSweeper intake directly: $(jq -c . "$direct_body" 2>/dev/null || echo '{}')"
exit 0
fi
# Only non-transient 4xx is a deliberate refusal; the App webhook covers it.
# Timeouts, throttling, and verifier/Worker failures must stay re-runnable.
if [[ "${direct_status:-}" == 4[0-9][0-9] && "$direct_status" != 408 && "$direct_status" != 429 ]]; then
echo "::warning::ClawSweeper intake declined this event (HTTP $direct_status); the App webhook route still applies."
exit 0
fi
echo "::error::ClawSweeper intake unavailable (HTTP ${direct_status:-none}); re-run this job after the Worker recovers."
else
echo "::error::ClawSweeper OIDC token unavailable; the dispatch job needs id-token: write."
fi
exit 1
- name: Dispatch ClawSweeper comment
if: >-
${{
github.event_name == 'issue_comment' &&
steps.comment_filter.outputs.is_command == 'true'
}}
env:
TARGET_REPO: ${{ github.repository }}
ITEM_NUMBER: ${{ github.event.issue.number }}
COMMENT_ID: ${{ github.event.comment.id }}
SOURCE_ACTION: ${{ github.event.action }}
TARGET_DISPATCH_URL: https://clawsweeper.openclaw.ai/github/target-dispatch
run: |
set -euo pipefail
client_payload="$(jq -nc \
--arg target_repo "$TARGET_REPO" \
--argjson item_number "$ITEM_NUMBER" \
--argjson comment_id "$COMMENT_ID" \
--arg source_action "$SOURCE_ACTION" \
'{target_repo:$target_repo,item_number:$item_number,comment_id:$comment_id,source_event:"issue_comment",source_action:$source_action}')"
# The App webhook remains an independent delivery route.
if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ] &&
[ -n "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ] &&
oidc_token="$(curl --fail --silent --show-error --connect-timeout 5 --max-time 15 \
--header "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
--get --data-urlencode "audience=$TARGET_DISPATCH_URL" \
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -er '.value | strings | select(length > 0)')" &&
[ -n "$oidc_token" ]; then
echo "::add-mask::$oidc_token"
direct_body="$RUNNER_TEMP/clawsweeper-direct-intake.json"
if direct_status="$(curl --silent --show-error --connect-timeout 5 --max-time 20 \
--request POST \
--header "authorization: Bearer $oidc_token" \
--header "content-type: application/json" \
--data "$client_payload" \
--output "$direct_body" \
--write-out '%{http_code}' \
"$TARGET_DISPATCH_URL")" &&
[[ "$direct_status" == 2[0-9][0-9] ]]; then
echo "Queued ClawSweeper intake directly: $(jq -c . "$direct_body" 2>/dev/null || echo '{}')"
exit 0
fi
# Only non-transient 4xx is a deliberate refusal; the App webhook covers it.
# Timeouts, throttling, and verifier/Worker failures must stay re-runnable.
if [[ "${direct_status:-}" == 4[0-9][0-9] && "$direct_status" != 408 && "$direct_status" != 429 ]]; then
echo "::warning::ClawSweeper intake declined this event (HTTP $direct_status); the App webhook route still applies."
exit 0
fi
echo "::error::ClawSweeper intake unavailable (HTTP ${direct_status:-none}); re-run this job after the Worker recovers."
else
echo "::error::ClawSweeper OIDC token unavailable; the dispatch job needs id-token: write."
fi
exit 1