|
| 1 | +name: Codex PR Creation |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +jobs: |
| 8 | + codex-pr: |
| 9 | + name: Create PR with Codex |
| 10 | + runs-on: ubuntu-latest |
| 11 | + if: | |
| 12 | + startsWith(github.event.comment.body, '/codex') && |
| 13 | + github.event.comment.user.login == github.repository_owner |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + pull-requests: write |
| 17 | + issues: write |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Run Codex |
| 25 | + id: run_codex |
| 26 | + uses: openai/codex-action@v1 |
| 27 | + with: |
| 28 | + openai-api-key: ${{ secrets.OPENAI_API_KEY }} |
| 29 | + prompt: | |
| 30 | + Issue #${{ github.event.issue.number }}: ${{ github.event.issue.title }} |
| 31 | + |
| 32 | + ${{ github.event.issue.body }} |
| 33 | + |
| 34 | + This repository is a TypeScript SignalR client library. |
| 35 | + Please implement code changes to address the above issue. |
| 36 | + Always include tests for the changes you make. |
| 37 | + sandbox: workspace-write |
| 38 | + safety-strategy: drop-sudo |
| 39 | + |
| 40 | + - name: Create Pull Request |
| 41 | + id: create_pr |
| 42 | + uses: peter-evans/create-pull-request@v8 |
| 43 | + with: |
| 44 | + branch: codex/issue-${{ github.event.issue.number }} |
| 45 | + branch-suffix: timestamp |
| 46 | + commit-message: Address issue #${{ github.event.issue.number }}: ${{ github.event.issue.title }} |
| 47 | + title: '[Codex] Address issue #${{ github.event.issue.number }}: ${{ github.event.issue.title }}' |
| 48 | + body: | |
| 49 | + This PR was automatically created by Codex to address issue #${{ github.event.issue.number }}. |
| 50 | + base: main |
| 51 | + |
| 52 | + - name: Comment on issue |
| 53 | + if: steps.create_pr.outputs.pull-request-number != '' |
| 54 | + uses: actions/github-script@v7 |
| 55 | + with: |
| 56 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + script: | |
| 58 | + await github.rest.issues.createComment({ |
| 59 | + owner: context.repo.owner, |
| 60 | + repo: context.repo.repo, |
| 61 | + issue_number: context.payload.issue.number, |
| 62 | + body: `✅ PR created: #${{ steps.create_pr.outputs.pull-request-number }} |
| 63 | +
|
| 64 | + ${{ steps.create_pr.outputs.pull-request-url }}`, |
| 65 | + }); |
| 66 | +
|
| 67 | + - name: Comment on issue (no changes) |
| 68 | + if: steps.create_pr.outputs.pull-request-number == '' |
| 69 | + uses: actions/github-script@v7 |
| 70 | + with: |
| 71 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + script: | |
| 73 | + await github.rest.issues.createComment({ |
| 74 | + owner: context.repo.owner, |
| 75 | + repo: context.repo.repo, |
| 76 | + issue_number: context.payload.issue.number, |
| 77 | + body: 'ℹ️ Codex ran but no changes were made.', |
| 78 | + }); |
| 79 | +
|
| 80 | + - name: Handle errors |
| 81 | + if: failure() |
| 82 | + uses: actions/github-script@v7 |
| 83 | + with: |
| 84 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + script: | |
| 86 | + await github.rest.issues.createComment({ |
| 87 | + owner: context.repo.owner, |
| 88 | + repo: context.repo.repo, |
| 89 | + issue_number: context.payload.issue.number, |
| 90 | + body: '❌ An error occurred while running Codex. Please check the workflow logs.', |
| 91 | + }); |
| 92 | +
|
0 commit comments