Skip to content

Commit e0a4146

Browse files
authored
fix(ci): carry branch authority to ClawSweeper (#121674)
Co-authored-by: brokemac79 <[email protected]>
1 parent 105038e commit e0a4146

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎.github/workflows/clawsweeper-dispatch.yml‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ jobs:
289289
env:
290290
GH_TOKEN: ${{ steps.token.outputs.token }}
291291
TARGET_REPO: ${{ github.repository }}
292+
TARGET_BRANCH: ${{ github.event.repository.default_branch }}
292293
ITEM_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }}
293294
ITEM_KIND: ${{ github.event_name == 'pull_request_target' && 'pull_request' || 'issue' }}
294295
SOURCE_EVENT: ${{ github.event_name }}
@@ -299,14 +300,52 @@ jobs:
299300
exit 0
300301
fi
301302
. "$RUNNER_TEMP/github-api-backoff.sh"
303+
ingress_fingerprint="$(node <<'NODE'
304+
const crypto = require("node:crypto");
305+
const fs = require("node:fs");
306+
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));
307+
const pullRequest = event.pull_request && typeof event.pull_request === "object"
308+
? event.pull_request
309+
: {};
310+
const headSha = String(pullRequest.head?.sha || "").trim().toLowerCase();
311+
const updatedAt = String(pullRequest.updated_at || "").trim();
312+
if (
313+
process.env.ITEM_KIND !== "pull_request" ||
314+
!/^[0-9a-f]{40}$/.test(headSha) ||
315+
!updatedAt
316+
) {
317+
process.stdout.write("");
318+
} else {
319+
process.stdout.write(
320+
crypto
321+
.createHash("sha256")
322+
.update(
323+
JSON.stringify({
324+
version: 1,
325+
target_repo: String(process.env.TARGET_REPO || "").toLowerCase(),
326+
item_number: Number(process.env.ITEM_NUMBER),
327+
action: String(process.env.SOURCE_ACTION || ""),
328+
head_sha: headSha,
329+
updated_at: updatedAt,
330+
body: typeof pullRequest.body === "string" ? pullRequest.body : "",
331+
label: String(event.label?.name || ""),
332+
}),
333+
)
334+
.digest("hex"),
335+
);
336+
}
337+
NODE
338+
)"
302339
payload="$(jq -nc \
303340
--arg target_repo "$TARGET_REPO" \
341+
--arg target_branch "$TARGET_BRANCH" \
304342
--argjson item_number "$ITEM_NUMBER" \
305343
--arg item_kind "$ITEM_KIND" \
306344
--arg source_event "$SOURCE_EVENT" \
307345
--arg source_action "$SOURCE_ACTION" \
346+
--arg ingress_fingerprint "$ingress_fingerprint" \
308347
--argjson supersedes_in_progress "$SUPERSEDES_IN_PROGRESS" \
309-
'{event_type:"clawsweeper_item",client_payload:{target_repo:$target_repo,item_number:$item_number,item_kind:$item_kind,source_event:$source_event,source_action:$source_action,supersedes_in_progress:$supersedes_in_progress}}')"
348+
'{event_type:"clawsweeper_item",client_payload:({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} + (if $ingress_fingerprint != "" then {ingress_route:"target_dispatcher",ingress_fingerprint:$ingress_fingerprint} else {} end))}')"
310349
if gh_api_with_retry repos/openclaw/clawsweeper/dispatches \
311350
--method POST \
312351
--input - <<< "$payload"; then

‎test/scripts/ci-workflow-guards.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,18 @@ NODE
13631363
expect(activityRun).toMatch(
13641364
/push: \(if \$event_name == "push" then \{\s+before: \.before,\s+after: \.after,\s+ref: \.ref,\s+compare: \.compare,\s+head_commit: \.head_commit\.id\s+\} else null end\)/u,
13651365
);
1366+
1367+
const exactReviewStep = expectDefined(
1368+
steps.find((step) => step.name === "Dispatch exact ClawSweeper review"),
1369+
"ClawSweeper exact-review dispatch",
1370+
);
1371+
expect(exactReviewStep.env?.TARGET_BRANCH).toBe(
1372+
"${{ github.event.repository.default_branch }}",
1373+
);
1374+
expect(exactReviewStep.run).toContain('--arg target_branch "$TARGET_BRANCH"');
1375+
expect(exactReviewStep.run).toContain("target_branch:$target_branch");
1376+
expect(exactReviewStep.run).toContain('ingress_route:"target_dispatcher"');
1377+
expect(exactReviewStep.run).toContain("ingress_fingerprint:$ingress_fingerprint");
13661378
});
13671379

13681380
it("runs the PR context and evidence gate only for relevant PR changes", () => {

0 commit comments

Comments
 (0)