diff --git a/.github/workflows/pr-review-trigger.yml b/.github/workflows/pr-review-trigger.yml new file mode 100644 index 0000000000..ddc5d2d4ac --- /dev/null +++ b/.github/workflows/pr-review-trigger.yml @@ -0,0 +1,20 @@ +name: PR Review - Trigger +on: + pull_request: + types: [ready_for_review, opened] +permissions: {} +jobs: + save-pr: + runs-on: ubuntu-latest + steps: + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + run: printf '%s' "$PR_NUMBER" > pr_number.txt + + - name: Upload PR context + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: pr-review-context + path: pr_number.txt + retention-days: 1 diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 7d379530fb..23868a070f 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -1,30 +1,53 @@ name: PR Review on: - issue_comment: # Enables /review command in PR comments + issue_comment: # Enables /review command in PR comments types: [created] pull_request_review_comment: # Captures feedback on review comments for learning types: [created] - pull_request: # Triggers auto-review on PR open (same-repo branches only; fork PRs use /review) - types: [ready_for_review, opened] + workflow_run: # Auto-review for all PRs via artifact handoff (fork and non-fork) + workflows: ["PR Review - Trigger"] + types: [completed] permissions: - contents: read # Required at top level so `GITHUB_TOKEN` for `issue_comment` events can read repository contents. + contents: read # Required at top-level so `issue_comment` events can read repository contents. + actions: read # Required to download artifacts from the PR Review - Trigger workflow run. jobs: - review: - if: >- - github.event_name == 'issue_comment' || - github.event_name == 'pull_request_review_comment' || - github.event.pull_request.user.login != 'dependabot[bot]' - uses: docker/cagent-action/.github/workflows/review-pr.yml@dba0ca51938c78afb363625363c50582243218d6 # v1.3.1 + get-pr-context: + if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest + outputs: + pr-number: ${{ steps.pr.outputs.number }} + steps: + - name: Download PR context + if: github.event_name == 'workflow_run' + continue-on-error: true + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: pr-review-context + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + + - name: Read PR number + id: pr + if: github.event_name == 'workflow_run' + run: echo "number=$(cat pr_number.txt)" >> $GITHUB_OUTPUT + + run-docker-agent: + needs: [get-pr-context] + if: | + always() && ( + github.event_name == 'issue_comment' || + github.event_name == 'pull_request_review_comment' || + needs.get-pr-context.result == 'success' + ) + uses: docker/cagent-action/.github/workflows/review-pr.yml@d98096f432f2aea5091c811852c4da804e60623a # v1.4.1 # Scoped to the job so other jobs in this workflow aren't over-permissioned permissions: - contents: read # Read repository files and PR diffs + contents: read # Read repository files and PR diffs pull-requests: write # Post review comments and approve/request changes - issues: write # Create security incident issues if secrets are detected in output - checks: write # (Optional) Show review progress as a check run on the PR - secrets: - ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - CAGENT_ORG_MEMBERSHIP_TOKEN: ${{ secrets.CAGENT_ORG_MEMBERSHIP_TOKEN }} # PAT with read:org scope; gates auto-reviews to org members only - CAGENT_REVIEWER_APP_ID: ${{ secrets.CAGENT_REVIEWER_APP_ID }} # GitHub App ID; reviews appear as your app instead of github-actions[bot] - CAGENT_REVIEWER_APP_PRIVATE_KEY: ${{ secrets.CAGENT_REVIEWER_APP_PRIVATE_KEY }} # GitHub App private key; paired with App ID above + issues: write # Create security incident issues if secrets are detected in output + checks: write # (Optional) Show review progress as a check run on the PR + id-token: write # Required for OIDC authentication to AWS Secrets Manager + with: + pr-number: ${{ needs.get-pr-context.outputs.pr-number }}