|
| 1 | +name: review |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + pull_request: |
| 7 | + paths: |
| 8 | + - .github/workflows/review.yml |
| 9 | + - dev/mcps/review.py |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + review: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: read |
| 20 | + models: read |
| 21 | + pull-requests: write |
| 22 | + timeout-minutes: 10 |
| 23 | + # Run on pull_request events from mlflow/mlflow (not forks) or when harupy comments '/review' on a pull request |
| 24 | + if: > |
| 25 | + (github.event_name == 'pull_request' && |
| 26 | + github.event.pull_request.head.repo.full_name == 'mlflow/mlflow') |
| 27 | + || |
| 28 | + (github.event_name == 'issue_comment' && |
| 29 | + github.event.issue.pull_request && |
| 30 | + startsWith(github.event.comment.body, '/review') && |
| 31 | + github.event.comment.user.login == 'harupy') |
| 32 | + steps: |
| 33 | + - name: React to comment |
| 34 | + if: ${{ github.event_name == 'issue_comment' }} |
| 35 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 36 | + with: |
| 37 | + script: | |
| 38 | + const { comment } = context.payload; |
| 39 | + await github.rest.reactions.createForIssueComment({ |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + comment_id: comment.id, |
| 43 | + content: 'rocket' |
| 44 | + }); |
| 45 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 46 | + with: |
| 47 | + sparse-checkout: | |
| 48 | + dev |
| 49 | + - uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb # v6.1.0 |
| 50 | + with: |
| 51 | + version: 0.7.8 |
| 52 | + - name: Install codex |
| 53 | + run: | |
| 54 | + curl -L -o codex.tar.gz https://github.com/openai/codex/releases/download/rust-v0.25.0/codex-x86_64-unknown-linux-musl.tar.gz |
| 55 | + tar -xzf codex.tar.gz |
| 56 | + mv codex-x86_64-unknown-linux-musl codex |
| 57 | + chmod +x codex |
| 58 | + ./codex --version |
| 59 | +
|
| 60 | + - name: Set up config |
| 61 | + run: | |
| 62 | + # https://github.com/openai/codex/blob/main/docs/config.md |
| 63 | + mkdir -p ~/.codex |
| 64 | + cat <<'EOF' > ~/.codex/config.toml |
| 65 | + # TODO: Use github models if gpt-5 supports higher input/output token limits |
| 66 | + # https://github.com/marketplace/models/azure-openai/gpt-5 |
| 67 | + # model = "openai/gpt-5" |
| 68 | + # model_provider = "github-models" |
| 69 | + model_verbosity = "high" |
| 70 | + approval_policy = "never" |
| 71 | + sandbox_mode = "workspace-write" |
| 72 | +
|
| 73 | + [sandbox_workspace_write] |
| 74 | + network_access = true |
| 75 | +
|
| 76 | + [model_providers.github-models] |
| 77 | + # https://docs.github.com/en/github-models/use-github-models/prototyping-with-ai-models#rate-limits |
| 78 | + name = "GitHub Models" |
| 79 | + base_url = "https://models.github.ai/inference" |
| 80 | + env_key = "GITHUB_TOKEN" |
| 81 | + wire_api = "chat" |
| 82 | +
|
| 83 | + [mcp_servers.github] |
| 84 | + # https://github.com/github/github-mcp-server |
| 85 | + command = "uv" |
| 86 | + args = [ |
| 87 | + "run", |
| 88 | + "--no-project", |
| 89 | + "dev/mcps/review.py" |
| 90 | + ] |
| 91 | + env = { "GITHUB_TOKEN" = "${{ secrets.GITHUB_TOKEN }}" } |
| 92 | + EOF |
| 93 | +
|
| 94 | + - name: Prompt |
| 95 | + run: | |
| 96 | + cat <<'EOF' > AGENTS.md |
| 97 | + You're a helpful assistant to review PRs. Your task is to follow the instructions below and review the given PR. |
| 98 | +
|
| 99 | + # Instructions |
| 100 | +
|
| 101 | + ## 1. Fetch and Analyze PR |
| 102 | + - Use `fetch_diff` tool to fetch the PR diff |
| 103 | + - Carefully examine all changes in the diff |
| 104 | +
|
| 105 | + ## 2. Review Against Style Guide |
| 106 | + - Read `dev/guides/python.md` thoroughly |
| 107 | + - Check for violations of the style guide |
| 108 | +
|
| 109 | + ## 3. Decision Point |
| 110 | + - If NO issues found -> Skip remaining steps |
| 111 | + - If issues found -> Continue to step 4 |
| 112 | +
|
| 113 | + ## 4. Add Review Comments |
| 114 | + - Use `add_pr_review_comment` tool for each issue found |
| 115 | + - Comment parameters: |
| 116 | + - Single-line: Set `subject_type` to `LINE`, specify `line` |
| 117 | + - Multi-line: Set `subject_type` to `LINE`, specify both `start_line` and `line` |
| 118 | + - Comment format: |
| 119 | + - Use triple backticks (```) for code examples with an appropriate language identifier |
| 120 | + - Be specific about the violation and suggest fixes |
| 121 | + - Include `🤖 Generated by Codex` at the end of each comment |
| 122 | + EOF |
| 123 | +
|
| 124 | + - name: Run codex |
| 125 | + env: |
| 126 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 127 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + PR_URL: ${{ github.event.issue.pull_request.html_url || github.event.pull_request.html_url}} |
| 129 | + run: | |
| 130 | + # Use timeout in case codex hangs |
| 131 | + timeout 3m ./codex exec --skip-git-repo-check "Can you review $PR_URL?" || true |
0 commit comments