This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
Add "ready-to-merge" and "delegated" label from PR review #66216
Workflow file for this run
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" and "delegated" label from PR review | |
on: | |
pull_request_review: | |
types: [submitted] | |
jobs: | |
add_ready_to_merge_label: | |
name: Add ready-to-merge label | |
if: (startsWith(github.event.review.body, 'bors r+') || contains(toJSON(github.event.review.body), '\r\nbors r+') || startsWith(github.event.review.body, 'bors merge') || contains(toJSON(github.event.review.body), '\r\nbors merge')) | |
runs-on: ubuntu-latest | |
steps: | |
- uses: octokit/[email protected] | |
name: Get PR head | |
id: get_pr_head | |
with: | |
route: GET /repos/:repository/pulls/:pull_number | |
repository: ${{ github.repository }} | |
pull_number: ${{ github.event.pull_request.number }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }} | |
# Parse steps.get_pr_head.outputs.data, since it is a string | |
- id: parse_pr_head | |
name: Parse PR head | |
uses: gr2m/[email protected] | |
with: | |
json: ${{ steps.get_pr_head.outputs.data }} | |
head_user: 'head.user.login' | |
# we skip the rest if this PR is from a fork, | |
# since the GITHUB_TOKEN doesn't have write perms | |
- if: steps.parse_pr_head.outputs.head_user == 'leanprover-community' | |
uses: octokit/[email protected] | |
name: Get comment author | |
id: get_user | |
with: | |
route: GET /repos/:repository/collaborators/:username/permission | |
repository: ${{ github.repository }} | |
username: ${{ github.event.review.user.login }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }} | |
# Parse steps.get_user.outputs.data, since it is a string | |
- if: steps.parse_pr_head.outputs.head_user == 'leanprover-community' | |
id: parse_user | |
name: Parse comment author permission | |
uses: gr2m/[email protected] | |
with: | |
json: ${{ steps.get_user.outputs.data }} | |
permission: 'permission' | |
- if: (steps.parse_pr_head.outputs.head_user == 'leanprover-community') && (steps.parse_user.outputs.permission == 'admin') | |
uses: octokit/[email protected] | |
id: add_label | |
name: Add label | |
with: | |
route: POST /repos/:repository/issues/:issue_number/labels | |
repository: ${{ github.repository }} | |
issue_number: ${{ github.event.pull_request.number }} | |
labels: '["ready-to-merge"]' | |
env: | |
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }} | |
- if: (steps.parse_pr_head.outputs.head_user == 'leanprover-community') && (steps.parse_user.outputs.permission == 'admin') | |
id: remove_labels | |
name: Remove "awaiting-review" and "awaiting-author" | |
# we use curl rather than octokit/request-action so that the job won't fail | |
# (and send an annoying email) if the labels don't exist | |
run: | | |
curl --request DELETE \ | |
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/awaiting-review \ | |
--header 'authorization: Bearer ${{ secrets.TRIAGE_TOKEN }}' | |
curl --request DELETE \ | |
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/awaiting-author \ | |
--header 'authorization: Bearer ${{ secrets.TRIAGE_TOKEN }}' | |
add_delegated_label: | |
name: Add delegated label | |
if: (startsWith(github.event.review.body, 'bors d') || contains(toJSON(github.event.review.body), '\r\nbors d')) | |
runs-on: ubuntu-latest | |
steps: | |
- uses: octokit/[email protected] | |
name: Get PR head | |
id: get_pr_head | |
with: | |
route: GET /repos/:repository/pulls/:pull_number | |
repository: ${{ github.repository }} | |
pull_number: ${{ github.event.pull_request.number }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }} | |
# Parse steps.get_pr_head.outputs.data, since it is a string | |
- id: parse_pr_head | |
name: Parse PR head | |
uses: gr2m/[email protected] | |
with: | |
json: ${{ steps.get_pr_head.outputs.data }} | |
head_user: 'head.user.login' | |
# we skip the rest if this PR is from a fork, | |
# since the GITHUB_TOKEN doesn't have write perms | |
- if: steps.parse_pr_head.outputs.head_user == 'leanprover-community' | |
uses: octokit/[email protected] | |
name: Get comment author | |
id: get_user | |
with: | |
route: GET /repos/:repository/collaborators/:username/permission | |
repository: ${{ github.repository }} | |
username: ${{ github.event.review.user.login }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }} | |
# Parse steps.get_user.outputs.data, since it is a string | |
- if: steps.parse_pr_head.outputs.head_user == 'leanprover-community' | |
id: parse_user | |
name: Parse comment author permission | |
uses: gr2m/[email protected] | |
with: | |
json: ${{ steps.get_user.outputs.data }} | |
permission: 'permission' | |
- if: (steps.parse_pr_head.outputs.head_user == 'leanprover-community') && (steps.parse_user.outputs.permission == 'admin') | |
uses: octokit/[email protected] | |
id: add_label | |
name: Add label | |
with: | |
route: POST /repos/:repository/issues/:issue_number/labels | |
repository: ${{ github.repository }} | |
issue_number: ${{ github.event.pull_request.number }} | |
labels: '["delegated"]' | |
env: | |
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }} | |
- if: (steps.parse_pr_head.outputs.head_user == 'leanprover-community') && (steps.parse_user.outputs.permission == 'admin') | |
id: remove_labels | |
name: Remove "awaiting-review" | |
# we use curl rather than octokit/request-action so that the job won't fail | |
# (and send an annoying email) if the labels don't exist | |
run: | | |
curl --request DELETE \ | |
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/awaiting-review \ | |
--header 'authorization: Bearer ${{ secrets.TRIAGE_TOKEN }}' |