From aa83d1f45873404bf5238e8342f7ea4402dd2ca3 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sat, 6 Jul 2024 15:47:44 +0200 Subject: [PATCH 1/2] Bug Fix Label action --- .github/workflows/label-bug-fix.yml | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/label-bug-fix.yml diff --git a/.github/workflows/label-bug-fix.yml b/.github/workflows/label-bug-fix.yml new file mode 100644 index 000000000000..23ca3af815c8 --- /dev/null +++ b/.github/workflows/label-bug-fix.yml @@ -0,0 +1,40 @@ +name: "Bug Fix label" +on: + pull_request: + types: [ opened,edited ] +jobs: + assign-label: + runs-on: ubuntu-latest + steps: + - name: label + env: + TITLE: ${{ github.event.pull_request.title }} + LABEL: Bug Fix - Sooner than Very Soon + uses: actions/github-script@v7 + with: + script: | + if(process.env.TITLE.split(":")[0].toUpperCase().includes("FIX")){ + github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: [process.env.LABEL] + }) + }else{ + const {data} = await github.rest.issues.listLabelsOnIssue({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }) + const filtered = data.filter(label => label.name == process.env.LABEL) + if(filtered.length == 1){ + github.rest.issues.removeLabel({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + name: process.env.LABEL + }) + } + } + + From 3551ca5cfaab5c65c7c74af22590917dff7a9f4e Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sun, 7 Jul 2024 12:51:44 +0200 Subject: [PATCH 2/2] Correct permissions --- .github/workflows/label-bug-fix.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/label-bug-fix.yml b/.github/workflows/label-bug-fix.yml index 23ca3af815c8..37e2296a9fb5 100644 --- a/.github/workflows/label-bug-fix.yml +++ b/.github/workflows/label-bug-fix.yml @@ -1,10 +1,14 @@ name: "Bug Fix label" on: - pull_request: + pull_request_target: types: [ opened,edited ] jobs: assign-label: runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + contents: read steps: - name: label env: @@ -12,6 +16,7 @@ jobs: LABEL: Bug Fix - Sooner than Very Soon uses: actions/github-script@v7 with: + github-token: ${{ secrets.GITHUB_TOKEN}} script: | if(process.env.TITLE.split(":")[0].toUpperCase().includes("FIX")){ github.rest.issues.addLabels({ @@ -36,5 +41,3 @@ jobs: }) } } - -