|
| 1 | +on: |
| 2 | +pull_request: |
| 3 | +name: auto-merge-readme |
| 4 | +jobs: |
| 5 | +approve: |
| 6 | +runs-on: ubuntu-latest |
| 7 | +if: .repository_owner == 'googleapis' && .head_ref == 'autosynth-readme' |
| 8 | +steps: |
| 9 | + |
| 10 | +with: |
| 11 | +-token: ${{secrets.YOSHI_APPROVER_TOKEN}} |
| 12 | +script: | |
| 13 | +// only approve PRs from yoshi-automation |
| 14 | +if (context.payload.pull_request.user.login !== "yoshi-automation") { |
| 15 | +return; |
| 16 | +} |
| 17 | +
|
| 18 | +// only approve PRs like "chore: release <release version>" |
| 19 | +if (!context.payload.pull_request.title === "chore: regenerate README") { |
| 20 | +return; |
| 21 | +} |
| 22 | +
|
| 23 | +// only approve PRs with README.md and synth.metadata changes |
| 24 | +const files = new Set( |
| 25 | +( |
| 26 | +await .paginate( |
| 27 | +.pulls.listFiles.endpoint({ |
| 28 | +owner: context.repo.owner, |
| 29 | +repo: context.repo.repo, |
| 30 | +pull_number: context.payload.pull_request.number, |
| 31 | +}) |
| 32 | +) |
| 33 | +).map(file => file.filename) |
| 34 | +); |
| 35 | +if (files.size != 2 || !files.has("README.md") || !files.has("./readme/synth.metadata/synth.metadata")) { |
| 36 | +return; |
| 37 | +} |
| 38 | +
|
| 39 | +// approve README regeneration PR |
| 40 | +await .pulls.createReview({ |
| 41 | +owner: context.repo.owner, |
| 42 | +repo: context.repo.repo, |
| 43 | +body: 'Rubber stamped PR!', |
| 44 | +pull_number: context.payload.pull_request.number, |
| 45 | +event: 'APPROVE' |
| 46 | +}); |
| 47 | +
|
| 48 | +// attach automerge label |
| 49 | +await .issues.addLabels({ |
| 50 | +owner: context.repo.owner, |
| 51 | +repo: context.repo.repo, |
| 52 | +issue_number: context.payload.pull_request.number, |
| 53 | +labels: ['automerge'] |
| 54 | +}); |
0 commit comments