|
| 1 | +name: AI PR Comment Analysis |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +jobs: |
| 8 | + analyze-comment: |
| 9 | + # Only run on PR comments that start with the trigger phrase |
| 10 | + if: | |
| 11 | + github.event.issue.pull_request && |
| 12 | + startsWith(github.event.comment.body, '@co-pilot-auto') |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Debug PR reviewer information |
| 20 | + uses: actions/github-script@v7 |
| 21 | + with: |
| 22 | + script: | |
| 23 | + console.log('Comment author:', context.payload.comment.user.login); |
| 24 | + console.log('PR author:', context.payload.issue.user.login); |
| 25 | +
|
| 26 | + // Get PR details to see reviewers |
| 27 | + const prNumber = context.payload.issue.number; |
| 28 | + const { data: prData } = await github.rest.pulls.get({ |
| 29 | + owner: context.repo.owner, |
| 30 | + repo: context.repo.repo, |
| 31 | + pull_number: prNumber |
| 32 | + }); |
| 33 | +
|
| 34 | + console.log('Requested reviewers:', JSON.stringify(prData.requested_reviewers)); |
| 35 | +
|
| 36 | + const reviewerLogins = prData.requested_reviewers.map(reviewer => reviewer.login); |
| 37 | + console.log('Reviewer logins:', reviewerLogins); |
| 38 | +
|
| 39 | + const isCommentFromPRAuthor = context.payload.comment.user.login === context.payload.issue.user.login; |
| 40 | + const isCommentFromReviewer = reviewerLogins.includes(context.payload.comment.user.login); |
| 41 | +
|
| 42 | + console.log('Is comment from PR author?', isCommentFromPRAuthor); |
| 43 | + console.log('Is comment from reviewer?', isCommentFromReviewer); |
| 44 | + console.log('Should proceed?', isCommentFromPRAuthor || isCommentFromReviewer); |
| 45 | +
|
| 46 | + // Store this information for later steps |
| 47 | + core.exportVariable('SHOULD_PROCEED', isCommentFromPRAuthor || isCommentFromReviewer); |
| 48 | +
|
| 49 | + - name: Generate token |
| 50 | + id: generate-token |
| 51 | + if: env.SHOULD_PROCEED == 'true' |
| 52 | + uses: actions/create-github-app-token@v1 |
| 53 | + with: |
| 54 | + app_id: ${{ secrets.INTERNAL_APP_ID }} |
| 55 | + private_key: ${{ secrets.INTERNAL_PRIVATE_KEY }} |
| 56 | + owner: ${{ github.repository_owner }} |
| 57 | + |
| 58 | + - name: Checkout repository |
| 59 | + if: env.SHOULD_PROCEED == 'true' |
| 60 | + uses: actions/checkout@v4 |
| 61 | + |
| 62 | + - name: Call PR analysis workflow |
| 63 | + if: env.SHOULD_PROCEED == 'true' |
| 64 | + uses: actions/github-script@v7 |
| 65 | + with: |
| 66 | + github-token: ${{ steps.generate-token.outputs.token }} |
| 67 | + script: | |
| 68 | + const commentBody = context.payload.comment.body; |
| 69 | + const commenter = context.payload.comment.user.login; |
| 70 | + const prNumber = context.payload.issue.number; |
| 71 | + const runId = context.runId; |
| 72 | + const workflowRunUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; |
| 73 | +
|
| 74 | + // Post acknowledgment comment with workflow run link |
| 75 | + await github.rest.issues.createComment({ |
| 76 | + issue_number: prNumber, |
| 77 | + owner: context.repo.owner, |
| 78 | + repo: context.repo.repo, |
| 79 | + body: `@${commenter} 🔄 Co-Pilot-Auto Client Triggered... Please wait for the results.\n\nView Client trigger workflow progress: [GitHub Actions Run](${workflowRunUrl})` |
| 80 | + }); |
| 81 | +
|
| 82 | + // Call the reusable workflow in the analyzer repository |
| 83 | + await github.rest.actions.createWorkflowDispatch({ |
| 84 | + owner: 'tier4', |
| 85 | + repo: 'llm_pr_analyzer', |
| 86 | + workflow_id: 'co-pilot-auto-server.yml', // The filename of the reusable workflow |
| 87 | + ref: 'pilot-auto-branch', // The branch where the workflow is defined |
| 88 | + inputs: { |
| 89 | + repo: `${context.repo.owner}/${context.repo.repo}`, |
| 90 | + pr_number: `${prNumber}`, |
| 91 | + comment_body: commentBody, |
| 92 | + commenter: commenter, |
| 93 | + } |
| 94 | + }); |
0 commit comments