Add Ready to merge label #932
This file contains 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: Add Ready to merge label | |
on: | |
pull_request_review: | |
types: | |
- 'edited' | |
- 'dismissed' | |
- 'submitted' | |
jobs: | |
your-action: | |
runs-on: 'ubuntu-latest' | |
steps: | |
- uses: actions/checkout@v3 | |
- id: 'reviews' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const script = require('./scripts/gh-get-review-counts.js') | |
await script({github, context, core}) | |
- name: Add Label if 2 Approvals | |
if: 'steps.reviews.outputs.approved >= 2 && steps.reviews.outputs.changes_requested == 0' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.rest.issues.addLabels({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: ["ready to merge"] | |
}) | |
- name: Remove Label if less than 2 approvals or change requested | |
if: 'steps.reviews.outputs.approved < 2 || steps.reviews.outputs.changes_requested > 0' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.rest.issues.removeLabel({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
name: "ready to merge" | |
}).catch(function(error) { | |
if (error.status === 404) { | |
return; | |
} else { | |
throw error; | |
} | |
}) |