|
| 1 | +name: Codex Review Gate |
| 2 | + |
| 3 | +# Watches for Codex reviews (submitted via FuugaMo's GitHub account). |
| 4 | +# Sets the commit status codex/lgtm based on the review outcome. |
| 5 | +# Also handles comment-based signals in case Codex posts a comment |
| 6 | +# rather than a formal review state. |
| 7 | + |
| 8 | +on: |
| 9 | + pull_request_review: |
| 10 | + types: [submitted, dismissed] |
| 11 | + issue_comment: |
| 12 | + types: [created, edited] |
| 13 | + |
| 14 | +permissions: |
| 15 | + statuses: write |
| 16 | + pull-requests: read |
| 17 | + |
| 18 | +jobs: |
| 19 | + gate: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/github-script@v7 |
| 23 | + with: |
| 24 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + script: | |
| 26 | + const CODEX_USER = 'FuugaMo'; |
| 27 | +
|
| 28 | + // ── Resolve PR and commit SHA ────────────────────────────────────── |
| 29 | + let pr, sha; |
| 30 | +
|
| 31 | + if (context.eventName === 'pull_request_review') { |
| 32 | + pr = context.payload.pull_request; |
| 33 | + sha = pr.head.sha; |
| 34 | + } else { |
| 35 | + // issue_comment — only handle PR comments |
| 36 | + if (!context.payload.issue.pull_request) return; |
| 37 | + const { data } = await github.rest.pulls.get({ |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: context.repo.repo, |
| 40 | + pull_number: context.payload.issue.number, |
| 41 | + }); |
| 42 | + pr = data; |
| 43 | + sha = data.head.sha; |
| 44 | + } |
| 45 | +
|
| 46 | + // Only process PRs with the auto-fix label (from OpenClaw) |
| 47 | + const labels = (pr.labels || []).map(l => l.name); |
| 48 | + if (!labels.includes('auto-fix')) return; |
| 49 | +
|
| 50 | + // ── Determine Codex verdict ──────────────────────────────────────── |
| 51 | + let state = null; |
| 52 | + let description = ''; |
| 53 | +
|
| 54 | + if (context.eventName === 'pull_request_review') { |
| 55 | + const review = context.payload.review; |
| 56 | + if (review.user.login !== CODEX_USER) return; |
| 57 | +
|
| 58 | + if (review.state === 'APPROVED') { |
| 59 | + state = 'success'; |
| 60 | + description = 'Codex LGTM — no critical issues'; |
| 61 | + } else if (review.state === 'CHANGES_REQUESTED') { |
| 62 | + state = 'failure'; |
| 63 | + description = 'Codex requested changes'; |
| 64 | + } else if (review.state === 'DISMISSED') { |
| 65 | + state = 'pending'; |
| 66 | + description = 'Codex review dismissed — awaiting re-review'; |
| 67 | + } else { |
| 68 | + // COMMENTED — parse the body for signals |
| 69 | + const body = (review.body || '').toLowerCase(); |
| 70 | + const critical = ['critical', 'p0', 'security issue', 'breaking', 'incorrect']; |
| 71 | + const positive = ['lgtm', 'no issues', 'looks good', 'no critical', 'approved']; |
| 72 | + if (critical.some(k => body.includes(k))) { |
| 73 | + state = 'failure'; |
| 74 | + description = 'Codex flagged critical issues'; |
| 75 | + } else if (positive.some(k => body.includes(k))) { |
| 76 | + state = 'success'; |
| 77 | + description = 'Codex LGTM (via comment)'; |
| 78 | + } |
| 79 | + } |
| 80 | + } else { |
| 81 | + // issue_comment path — only care about comments from Codex/FuugaMo |
| 82 | + const comment = context.payload.comment; |
| 83 | + if (comment.user.login !== CODEX_USER) return; |
| 84 | + const body = (comment.body || '').toLowerCase(); |
| 85 | + const critical = ['critical', 'p0', 'security issue', 'breaking', 'incorrect']; |
| 86 | + const positive = ['lgtm', 'no issues', 'looks good', 'no critical', 'approved']; |
| 87 | + if (critical.some(k => body.includes(k))) { |
| 88 | + state = 'failure'; |
| 89 | + description = 'Codex flagged critical issues'; |
| 90 | + } else if (positive.some(k => body.includes(k))) { |
| 91 | + state = 'success'; |
| 92 | + description = 'Codex LGTM (via comment)'; |
| 93 | + } |
| 94 | + } |
| 95 | +
|
| 96 | + if (!state) return; // not enough signal to set a status |
| 97 | +
|
| 98 | + // ── Set commit status ────────────────────────────────────────────── |
| 99 | + await github.rest.repos.createCommitStatus({ |
| 100 | + owner: context.repo.owner, |
| 101 | + repo: context.repo.repo, |
| 102 | + sha, |
| 103 | + state, |
| 104 | + description, |
| 105 | + context: 'codex/lgtm', |
| 106 | + }); |
| 107 | +
|
| 108 | + // ── Enable auto-merge on the PR when Codex approves ─────────────── |
| 109 | + if (state === 'success') { |
| 110 | + try { |
| 111 | + await github.rest.pulls.updateBranch({ |
| 112 | + owner: context.repo.owner, |
| 113 | + repo: context.repo.repo, |
| 114 | + pull_number: pr.number, |
| 115 | + }); |
| 116 | + } catch (_) {} |
| 117 | +
|
| 118 | + // Enable squash auto-merge (GitHub native) |
| 119 | + await github.graphql(` |
| 120 | + mutation($prId: ID!) { |
| 121 | + enablePullRequestAutoMerge(input: { |
| 122 | + pullRequestId: $prId, |
| 123 | + mergeMethod: SQUASH |
| 124 | + }) { clientMutationId } |
| 125 | + } |
| 126 | + `, { prId: pr.node_id }); |
| 127 | + } |
0 commit comments