|
21 | 21 | pull-requests: write |
22 | 22 | issues: write |
23 | 23 | 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 | + } |
24 | 68 | - name: Check author permissions |
25 | 69 | uses: actions/github-script@v7 |
26 | 70 | with: |
@@ -145,7 +189,7 @@ jobs: |
145 | 189 |
|
146 | 190 | core.setOutput('prompt', prompt); |
147 | 191 | - name: Run Oz Agent |
148 | | - uses: warpdotdev/oz-agent-action@v1 |
| 192 | + uses: warpdotdev/oz-agent-action@ce1621abf6a8ed8afdd4e4cc994545ede8fe1c6f # v1.0.12 |
149 | 193 | env: |
150 | 194 | GH_TOKEN: ${{ github.token }} |
151 | 195 | id: agent |
|
0 commit comments