|
| 1 | +name: DevFlow PR Review |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - reopened |
| 8 | + - ready_for_review |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + pr_number: |
| 12 | + description: Pull request number to review |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + issues: write |
| 19 | + pull-requests: write |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: devflow-pr-review-${{ github.repository }}-${{ github.event.pull_request.number || github.run_id }} |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +env: |
| 26 | + DEVFLOW_REPOSITORY: ${{ vars.DF_REPO }} |
| 27 | + DEVFLOW_REF: main |
| 28 | + TARGET_REPO_PATH: ${{ github.workspace }}/target-repo |
| 29 | + DEVFLOW_PATH: ${{ github.workspace }}/devflow |
| 30 | + |
| 31 | +jobs: |
| 32 | + review: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + timeout-minutes: 60 |
| 35 | + if: ${{ github.event_name != 'pull_request_target' || !github.event.pull_request.draft }} |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Resolve PR metadata |
| 39 | + id: pr |
| 40 | + shell: bash |
| 41 | + env: |
| 42 | + PR_HTML_URL: ${{ github.event.pull_request.html_url }} |
| 43 | + PR_NUMBER_EVENT: ${{ github.event.pull_request.number }} |
| 44 | + PR_NUMBER_INPUT: ${{ inputs.pr_number }} |
| 45 | + run: | |
| 46 | + set -euo pipefail |
| 47 | +
|
| 48 | + if [[ "${GITHUB_EVENT_NAME}" == "pull_request_target" ]]; then |
| 49 | + pr_number="${PR_NUMBER_EVENT}" |
| 50 | + pr_url="${PR_HTML_URL}" |
| 51 | + else |
| 52 | + pr_number="${PR_NUMBER_INPUT}" |
| 53 | + pr_url="https://github.com/${GITHUB_REPOSITORY}/pull/${pr_number}" |
| 54 | + fi |
| 55 | +
|
| 56 | + if [[ ! "$pr_number" =~ ^[1-9][0-9]*$ ]]; then |
| 57 | + echo "Could not determine PR number; for workflow_dispatch runs, the 'pr_number' input is required when not running on pull_request_target." >&2 |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | +
|
| 61 | + echo "pr_url=${pr_url}" >> "$GITHUB_OUTPUT" |
| 62 | + echo "pr_number=${pr_number}" >> "$GITHUB_OUTPUT" |
| 63 | + echo "repo=${GITHUB_REPOSITORY}" >> "$GITHUB_OUTPUT" |
| 64 | +
|
| 65 | + # Safe checkout: base repo only, not the untrusted PR head. |
| 66 | + - name: Checkout target repo base |
| 67 | + uses: actions/checkout@v5 |
| 68 | + with: |
| 69 | + ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha }} |
| 70 | + fetch-depth: 0 |
| 71 | + persist-credentials: false |
| 72 | + path: target-repo |
| 73 | + |
| 74 | + # Private DevFlow checkout: the PAT/token grants access to this repo's code. |
| 75 | + - name: Checkout DevFlow |
| 76 | + uses: actions/checkout@v5 |
| 77 | + with: |
| 78 | + repository: ${{ env.DEVFLOW_REPOSITORY }} |
| 79 | + ref: ${{ env.DEVFLOW_REF }} |
| 80 | + token: ${{ secrets.DEVFLOW_TOKEN }} |
| 81 | + fetch-depth: 1 |
| 82 | + persist-credentials: false |
| 83 | + path: devflow |
| 84 | + |
| 85 | + - name: Set up Python |
| 86 | + uses: actions/setup-python@v5 |
| 87 | + with: |
| 88 | + python-version: "3.13" |
| 89 | + |
| 90 | + - name: Set up uv |
| 91 | + uses: astral-sh/setup-uv@v6 |
| 92 | + with: |
| 93 | + version: "0.5.x" |
| 94 | + enable-cache: true |
| 95 | + |
| 96 | + - name: Install DevFlow dependencies |
| 97 | + working-directory: ${{ env.DEVFLOW_PATH }} |
| 98 | + run: uv sync --frozen |
| 99 | + |
| 100 | + - name: Classify PR relevance |
| 101 | + id: spam |
| 102 | + working-directory: ${{ env.DEVFLOW_PATH }} |
| 103 | + env: |
| 104 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 105 | + GH_COPILOT_TOKEN: ${{ secrets.GH_COPILOT_TOKEN }} |
| 106 | + SK_REPO_PATH: ${{ env.TARGET_REPO_PATH }} |
| 107 | + AGENT_REPO_PATH: ${{ env.TARGET_REPO_PATH }} |
| 108 | + PR_REPO: ${{ steps.pr.outputs.repo }} |
| 109 | + PR_NUMBER: ${{ steps.pr.outputs.pr_number }} |
| 110 | + run: | |
| 111 | + uv run python scripts/classify_pr_spam.py \ |
| 112 | + --repo "$PR_REPO" \ |
| 113 | + --pr-number "$PR_NUMBER" \ |
| 114 | + --repo-path "${TARGET_REPO_PATH}" \ |
| 115 | + --apply-labels |
| 116 | +
|
| 117 | + - name: Stop after spam gate |
| 118 | + if: ${{ steps.spam.outputs.decision != 'allow' }} |
| 119 | + shell: bash |
| 120 | + env: |
| 121 | + SPAM_DECISION: ${{ steps.spam.outputs.decision }} |
| 122 | + run: | |
| 123 | + echo "Skipping review because spam gate decided: ${SPAM_DECISION}" |
| 124 | +
|
| 125 | + - name: Run PR review |
| 126 | + if: ${{ steps.spam.outputs.decision == 'allow' }} |
| 127 | + id: review |
| 128 | + working-directory: ${{ env.DEVFLOW_PATH }} |
| 129 | + env: |
| 130 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 131 | + GH_COPILOT_TOKEN: ${{ secrets.GH_COPILOT_TOKEN }} |
| 132 | + SK_REPO_PATH: ${{ env.TARGET_REPO_PATH }} |
| 133 | + AGENT_REPO_PATH: ${{ env.TARGET_REPO_PATH }} |
| 134 | + PR_URL: ${{ steps.pr.outputs.pr_url }} |
| 135 | + run: | |
| 136 | + uv run python scripts/trigger_pr_review.py \ |
| 137 | + --pr-url "$PR_URL" \ |
| 138 | + --github-username "$GITHUB_ACTOR" \ |
| 139 | + --no-require-comment-selection |
0 commit comments