Annotate one mother-bud pair at a time tool #334
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
| name: Auto Approve Small PRs | |
| on: | |
| pull_request: | |
| types: [opened, reopened, synchronize] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| auto-approve: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Calculate number of changed lines | |
| id: diff | |
| uses: actions/github-script@v7 | |
| with: | |
| result-encoding: string | |
| script: | | |
| console.log(`PR Number: ${context.payload.pull_request.number}`); | |
| console.log(`Repository: ${context.repo.owner}/${context.repo.repo}`); | |
| const { data: files } = await github.rest.pulls.listFiles({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.payload.pull_request.number, | |
| }); | |
| const totalChanges = files.reduce((sum, file) => sum + file.changes, 0); | |
| console.log(`Total changed lines: ${totalChanges}`); | |
| return totalChanges; | |
| - name: Approve if PR is small | |
| if: steps.diff.outputs.result < 15 && github.actor != 'github-actions[bot]' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.PR_MANAGEMENT }} | |
| script: | | |
| try { | |
| console.log(`Attempting to approve PR #${context.payload.pull_request.number}`); | |
| console.log(`Changed lines: ${{ steps.diff.outputs.result }}`); | |
| const response = await github.rest.pulls.createReview({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.payload.pull_request.number, | |
| event: "APPROVE" | |
| }); | |
| console.log(`✅ Successfully approved PR. Review ID: ${response.data.id}`); | |
| } catch (error) { | |
| console.error(`❌ Failed to approve PR: ${error.message}`); | |
| // Don't throw error to prevent workflow failure | |
| } |