🏥 Code-Conductor 2025-07-24 #222
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
| name: 🔍 PR Review Tasks | |
| on: | |
| pull_request: | |
| types: [labeled] # Only when 'needs-review' label is added | |
| issue_comment: | |
| types: [created] | |
| workflow_dispatch: | |
| inputs: | |
| pr_number: | |
| description: 'PR number to review' | |
| required: true | |
| type: number | |
| permissions: | |
| contents: read | |
| issues: write | |
| pull-requests: read | |
| jobs: | |
| check-review-needed: | |
| name: Check if Review Needed | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_review: ${{ steps.check.outputs.should_review }} | |
| pr_number: ${{ steps.check.outputs.pr_number }} | |
| steps: | |
| - name: Check review triggers | |
| id: check | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.CONDUCTOR_GITHUB_TOKEN || github.token }} | |
| script: | | |
| let shouldReview = false; | |
| let prNumber = null; | |
| // Check different trigger types | |
| if (context.eventName === 'pull_request') { | |
| // Only if 'needs-review' label was added | |
| if (context.payload.label?.name === 'needs-review') { | |
| prNumber = context.payload.pull_request.number; | |
| shouldReview = true; | |
| } | |
| } else if (context.eventName === 'issue_comment') { | |
| // Check for review commands | |
| const comment = context.payload.comment.body.toLowerCase(); | |
| const reviewTriggers = ['/review', '/conductor review', '@conductor review']; | |
| if (context.payload.issue.pull_request && | |
| reviewTriggers.some(trigger => comment.includes(trigger))) { | |
| prNumber = context.payload.issue.number; | |
| shouldReview = true; | |
| } | |
| } else if (context.eventName === 'workflow_dispatch') { | |
| // Manual trigger | |
| prNumber = context.payload.inputs.pr_number; | |
| shouldReview = true; | |
| } | |
| // If we have a PR number, check if it should be skipped | |
| if (shouldReview && prNumber) { | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber | |
| }); | |
| // Skip conditions | |
| const skipConditions = [ | |
| pr.draft, // Skip drafts | |
| pr.user.type === 'Bot', // Skip bot PRs | |
| pr.user.login === 'dependabot[bot]', // Skip dependabot | |
| pr.labels.some(l => l.name === 'skip-review'), // Skip if labeled | |
| pr.additions + pr.deletions < 10, // Skip tiny PRs | |
| ]; | |
| // Check if only docs changed | |
| const { data: files } = await github.rest.pulls.listFiles({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber | |
| }); | |
| const onlyDocs = files.every(f => | |
| f.filename.match(/\.(md|txt|rst)$/i) || | |
| f.filename.includes('docs/') | |
| ); | |
| if (onlyDocs) { | |
| skipConditions.push(true); | |
| } | |
| // Check if already has review task | |
| const { data: issues } = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| labels: 'conductor:task,code-review', | |
| state: 'open' | |
| }); | |
| const hasReviewTask = issues.some(issue => | |
| issue.title.includes(`PR #${prNumber}`) || | |
| issue.body.includes(`PR #${prNumber}`) | |
| ); | |
| if (hasReviewTask) { | |
| console.log(`Review task already exists for PR #${prNumber}`); | |
| shouldReview = false; | |
| } | |
| if (skipConditions.some(condition => condition)) { | |
| console.log(`Skipping review for PR #${prNumber} based on skip conditions`); | |
| shouldReview = false; | |
| } | |
| } | |
| core.setOutput('should_review', shouldReview); | |
| core.setOutput('pr_number', prNumber); | |
| create-review-task: | |
| name: Create Review Task | |
| needs: check-review-needed | |
| if: needs.check-review-needed.outputs.should_review == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| pip install pyyaml requests | |
| - name: Setup GitHub CLI | |
| run: | | |
| echo "${{ secrets.CONDUCTOR_GITHUB_TOKEN || github.token }}" > token.txt | |
| gh auth login --with-token < token.txt | |
| rm -f token.txt | |
| - name: Ensure labels exist | |
| run: | | |
| # Create labels if they don't exist | |
| labels=("code-review:5319e7:Code review task for pull requests" | |
| "needs-review:fbca04:PR needs code review") | |
| for label_data in "${labels[@]}"; do | |
| IFS=':' read -r name color desc <<< "$label_data" | |
| gh label list | grep -q "^${name}" || \ | |
| gh label create "${name}" --color "${color}" --description "${desc}" || true | |
| done | |
| env: | |
| GH_TOKEN: ${{ secrets.CONDUCTOR_GITHUB_TOKEN || github.token }} | |
| - name: Create review task issue | |
| run: | | |
| python .conductor/scripts/create-review-task.py \ | |
| --pr-number "${{ needs.check-review-needed.outputs.pr_number }}" \ | |
| --repo "${{ github.repository }}" \ | |
| --event-type "${{ github.event_name }}" | |
| env: | |
| GH_TOKEN: ${{ secrets.CONDUCTOR_GITHUB_TOKEN || github.token }} | |
| GITHUB_TOKEN: ${{ secrets.CONDUCTOR_GITHUB_TOKEN || github.token }} | |
| - name: Add acknowledgment comment | |
| if: github.event_name == 'issue_comment' | |
| run: | | |
| gh pr comment ${{ github.event.issue.number }} \ | |
| --body "✅ Review task created! An AI agent will claim and complete the code review." | |
| env: | |
| GH_TOKEN: ${{ secrets.CONDUCTOR_GITHUB_TOKEN || github.token }} | |
| - name: Remove needs-review label | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| # Remove the trigger label after creating task | |
| gh pr edit ${{ needs.check-review-needed.outputs.pr_number }} \ | |
| --remove-label "needs-review" || true | |
| env: | |
| GH_TOKEN: ${{ secrets.CONDUCTOR_GITHUB_TOKEN || github.token }} |