Sunshine/.github/workflows/autoupdate-labeler.yml

73 lines
2.4 KiB
YAML
Raw Normal View History

2022-12-10 15:27:26 +00:00
---
# This action is centrally managed in https://github.com/<organization>/.github/
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
# the above-mentioned repo.
2023-01-01 03:38:46 +00:00
# Label PRs with `autoupdate` if various conditions are met, otherwise, remove the label.
2022-12-10 15:27:26 +00:00
name: Label PR autoupdate
on:
2022-12-13 01:04:06 +00:00
pull_request_target:
2022-12-10 15:27:26 +00:00
types:
- edited
- opened
2022-12-23 03:47:24 +00:00
- reopened
2022-12-13 01:04:06 +00:00
- synchronize
2022-12-10 15:27:26 +00:00
jobs:
label_pr:
if: >-
startsWith(github.repository, 'LizardByte/') &&
2022-12-13 01:04:06 +00:00
contains(github.event.pull_request.body, fromJSON('"] I want maintainers to keep my branch updated"'))
2022-12-10 15:27:26 +00:00
runs-on: ubuntu-latest
2022-12-13 01:04:06 +00:00
env:
GH_TOKEN: ${{ github.token }}
2022-12-10 15:27:26 +00:00
steps:
2022-12-13 01:04:06 +00:00
- name: Check if member
id: org_member
run: |
status="true"
gh api \
-H "Accept: application/vnd.github+json" \
/orgs/${{ github.repository_owner }}/members/${{ github.actor }} || status="false"
echo "result=${status}" >> $GITHUB_OUTPUT
2022-12-10 15:27:26 +00:00
- name: Label autoupdate
if: >-
2022-12-13 01:04:06 +00:00
steps.org_member.outputs.result == 'true' &&
contains(github.event.pull_request.labels.*.name, 'autoupdate') == false &&
2022-12-10 15:27:26 +00:00
contains(github.event.pull_request.body,
2022-12-23 03:47:24 +00:00
fromJSON('"\n- [x] I want maintainers to keep my branch updated"')) == true
2022-12-10 15:27:26 +00:00
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['autoupdate']
})
- name: Unlabel autoupdate
if: >-
2022-12-13 01:04:06 +00:00
contains(github.event.pull_request.labels.*.name, 'autoupdate') &&
(
(github.event.action == 'synchronize' && steps.org_member.outputs.result == 'false') ||
(contains(github.event.pull_request.body,
fromJSON('"\n- [x] I want maintainers to keep my branch updated"')) == false
)
)
2022-12-10 15:27:26 +00:00
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ['autoupdate']
})