|
| 1 | +--- |
| 2 | +# This action is centrally managed in https://github.com/<organization>/.github/ |
| 3 | +# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in |
| 4 | +# the above-mentioned repo. |
| 5 | + |
| 6 | +# Label PRs with `autoupdate` if various conditions are met, otherwise, remove the label. |
| 7 | + |
| 8 | +name: Label PR autoupdate |
| 9 | + |
| 10 | +on: |
| 11 | + pull_request_target: |
| 12 | + types: |
| 13 | + - edited |
| 14 | + - opened |
| 15 | + - reopened |
| 16 | + - synchronize |
| 17 | + |
| 18 | +jobs: |
| 19 | + label_pr: |
| 20 | + if: >- |
| 21 | + startsWith(github.repository, 'LizardByte/') && |
| 22 | + contains(github.event.pull_request.body, fromJSON('"] I want maintainers to keep my branch updated"')) |
| 23 | + runs-on: ubuntu-latest |
| 24 | + env: |
| 25 | + GH_TOKEN: ${{ github.token }} |
| 26 | + steps: |
| 27 | + - name: Check if member |
| 28 | + id: org_member |
| 29 | + run: | |
| 30 | + status="true" |
| 31 | + gh api \ |
| 32 | + -H "Accept: application/vnd.github+json" \ |
| 33 | + /orgs/${{ github.repository_owner }}/members/${{ github.actor }} || status="false" |
| 34 | +
|
| 35 | + echo "result=${status}" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + - name: Label autoupdate |
| 38 | + if: >- |
| 39 | + steps.org_member.outputs.result == 'true' && |
| 40 | + contains(github.event.pull_request.labels.*.name, 'autoupdate') == false && |
| 41 | + contains(github.event.pull_request.body, |
| 42 | + fromJSON('"\n- [x] I want maintainers to keep my branch updated"')) == true |
| 43 | + uses: actions/github-script@v6 |
| 44 | + with: |
| 45 | + github-token: ${{ secrets.GH_BOT_TOKEN }} |
| 46 | + script: | |
| 47 | + github.rest.issues.addLabels({ |
| 48 | + issue_number: context.issue.number, |
| 49 | + owner: context.repo.owner, |
| 50 | + repo: context.repo.repo, |
| 51 | + labels: ['autoupdate'] |
| 52 | + }) |
| 53 | +
|
| 54 | + - name: Unlabel autoupdate |
| 55 | + if: >- |
| 56 | + contains(github.event.pull_request.labels.*.name, 'autoupdate') && |
| 57 | + ( |
| 58 | + (github.event.action == 'synchronize' && steps.org_member.outputs.result == 'false') || |
| 59 | + (contains(github.event.pull_request.body, |
| 60 | + fromJSON('"\n- [x] I want maintainers to keep my branch updated"')) == false |
| 61 | + ) |
| 62 | + ) |
| 63 | + uses: actions/github-script@v6 |
| 64 | + with: |
| 65 | + github-token: ${{ secrets.GH_BOT_TOKEN }} |
| 66 | + script: | |
| 67 | + github.rest.issues.removeLabel({ |
| 68 | + issue_number: context.issue.number, |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + name: ['autoupdate'] |
| 72 | + }) |
0 commit comments