Skip to content

Commit 14107d6

Browse files
hongyi-chenoz-agent
andcommitted
Harden respond-to-comment.yml against fork PRs
Adds a fork-guard step before checkout/agent/push, and pins warpdotdev/oz-agent-action from the floating @v1 tag to a commit SHA in both workflows. Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent 77c9758 commit 14107d6

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

.github/workflows/respond-to-comment.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,50 @@ jobs:
2121
pull-requests: write
2222
issues: write
2323
steps:
24+
- name: Check PR is not from a fork
25+
uses: actions/github-script@v7
26+
with:
27+
github-token: ${{ github.token }}
28+
script: |
29+
const { owner, repo } = context.repo;
30+
const prNumber = context.payload.issue?.number
31+
?? context.payload.pull_request?.number;
32+
if (!prNumber) {
33+
core.setFailed('Could not determine PR number from event payload.');
34+
return;
35+
}
36+
37+
const { data: pr } = await github.rest.pulls.get({
38+
owner,
39+
repo,
40+
pull_number: prNumber,
41+
});
42+
43+
const headRepo = pr.head?.repo?.full_name;
44+
const upstream = `${owner}/${repo}`;
45+
if (headRepo !== upstream) {
46+
const author = context.payload.comment.user.login;
47+
const body = `@${author}: Sorry, I can't run on pull requests from forks for security reasons (this PR's head is \`${headRepo ?? 'unknown'}\`). A maintainer can re-open this as a branch on \`${upstream}\` and I'll be happy to help there.`;
48+
49+
if (context.eventName === 'pull_request_review_comment') {
50+
await github.rest.pulls.createReplyForReviewComment({
51+
owner,
52+
repo,
53+
pull_number: prNumber,
54+
comment_id: context.payload.comment.id,
55+
body,
56+
});
57+
} else {
58+
await github.rest.issues.createComment({
59+
owner,
60+
repo,
61+
issue_number: prNumber,
62+
body,
63+
});
64+
}
65+
66+
core.setFailed(`Refusing to run on fork PR (head repo: ${headRepo ?? 'unknown'}).`);
67+
}
2468
- name: Check author permissions
2569
uses: actions/github-script@v7
2670
with:
@@ -145,7 +189,7 @@ jobs:
145189
146190
core.setOutput('prompt', prompt);
147191
- name: Run Oz Agent
148-
uses: warpdotdev/oz-agent-action@v1
192+
uses: warpdotdev/oz-agent-action@ce1621abf6a8ed8afdd4e4cc994545ede8fe1c6f # v1.0.12
149193
env:
150194
GH_TOKEN: ${{ github.token }}
151195
id: agent

.github/workflows/review-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: actions/checkout@v4
1919

2020
- name: Review PR with Oz agent
21-
uses: warpdotdev/oz-agent-action@v1
21+
uses: warpdotdev/oz-agent-action@ce1621abf6a8ed8afdd4e4cc994545ede8fe1c6f # v1.0.12
2222
env:
2323
GH_TOKEN: ${{ github.token }}
2424
with:

0 commit comments

Comments
 (0)