From d418b85c2841bae307731c7c8f241cdaf43f6939 Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 16:07:43 +0800 Subject: [PATCH] feat: add automatic PR labeler in github workflow --- .github/workflows/label.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/label.yml diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml new file mode 100644 index 00000000..12a22b04 --- /dev/null +++ b/.github/workflows/label.yml @@ -0,0 +1,23 @@ +name: Automatic PR Labeler +on: + pull_request: + types: [opened, reopened, edited] + +jobs: + labeler: + runs-on: ubuntu-latest + steps: + - name: Label PR + uses: actions/github-script@v5 + with: + script: | + const { owner, repo, number: issue_number } = context.issue; + const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number }); + const title = pr.data.title; + const labRegex = /\[LAB(\d+)\]/i; + + const match = title.match(labRegex); + if (match) { + const labelToAdd = 'lab' + match[1]; + await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [labelToAdd] }); + }