From 705a5976b36b708c52f58cdeee1f54d020f6446f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lehoczky=20Zolt=C3=A1n?= Date: Sun, 26 Nov 2023 10:02:29 +0100 Subject: [PATCH 1/5] ci: label pull requests based on their target branch --- .github/workflows/label-pr.yml | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/label-pr.yml diff --git a/.github/workflows/label-pr.yml b/.github/workflows/label-pr.yml new file mode 100644 index 000000000000..32198c30621f --- /dev/null +++ b/.github/workflows/label-pr.yml @@ -0,0 +1,39 @@ +name: Label PR + +on: + pull_request: + types: + - opened + branches: + - main + - 2.x + +jobs: + add-pr-label: + name: Add PR label + runs-on: ubuntu-latest + permissions: + pull-requests: write + if: github.repository == 'nuxt/nuxt' + steps: + - uses: actions/github-script@v6 + with: + script: | + const baseName = "${{github.event.pull_request.base.label}}" + const PRNumber = "${{github.event.pull_request.number}}" + + if(baseName === "nuxt:2.x") { + github.rest.issues.addLabels({ + issue_number: PRNumber, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ["2.x"] + }) + } else if(baseName === "nuxt:main") { + github.rest.issues.addLabels({ + issue_number: PRNumber, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ["3.x"] + }) + } From 997c5b7b9af39215699316e257803439203fb8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lehoczky=20Zolt=C3=A1n?= Date: Sun, 26 Nov 2023 10:20:09 +0100 Subject: [PATCH 2/5] fix permission error --- .github/workflows/label-pr.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/label-pr.yml b/.github/workflows/label-pr.yml index 32198c30621f..d8c50c33d494 100644 --- a/.github/workflows/label-pr.yml +++ b/.github/workflows/label-pr.yml @@ -8,16 +8,20 @@ on: - main - 2.x +permissions: + contents: read + issues: write + pull-requests: write + jobs: add-pr-label: name: Add PR label runs-on: ubuntu-latest - permissions: - pull-requests: write if: github.repository == 'nuxt/nuxt' steps: - uses: actions/github-script@v6 with: + github-token: ${{ secrets.GITHUB_TOKEN }} script: | const baseName = "${{github.event.pull_request.base.label}}" const PRNumber = "${{github.event.pull_request.number}}" From 4da57af8ce36a1cd65322232d49fb03e9b6f0378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lehoczky=20Zolt=C3=A1n?= Date: Sun, 26 Nov 2023 10:21:42 +0100 Subject: [PATCH 3/5] temporarily run label action on pr updates --- .github/workflows/label-pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/label-pr.yml b/.github/workflows/label-pr.yml index d8c50c33d494..9fdd791a088f 100644 --- a/.github/workflows/label-pr.yml +++ b/.github/workflows/label-pr.yml @@ -2,8 +2,8 @@ name: Label PR on: pull_request: - types: - - opened + # types: + # - opened branches: - main - 2.x From dc0c8ac8a24d6cb6808abaf1c08d553fffdbeaa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lehoczky=20Zolt=C3=A1n?= Date: Thu, 30 Nov 2023 21:04:27 +0100 Subject: [PATCH 4/5] update workflow --- .github/workflows/label-pr.yml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/label-pr.yml b/.github/workflows/label-pr.yml index 9fdd791a088f..d83ca6a4c39b 100644 --- a/.github/workflows/label-pr.yml +++ b/.github/workflows/label-pr.yml @@ -1,30 +1,26 @@ name: Label PR on: - pull_request: - # types: - # - opened + pull_request_target: + types: + - opened branches: - main - 2.x -permissions: - contents: read - issues: write - pull-requests: write - jobs: add-pr-label: name: Add PR label runs-on: ubuntu-latest + permissions: + pull-requests: write if: github.repository == 'nuxt/nuxt' steps: - uses: actions/github-script@v6 with: - github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const baseName = "${{github.event.pull_request.base.label}}" - const PRNumber = "${{github.event.pull_request.number}}" + const baseName = "${{ github.event.pull_request.base.label }}" + const PRNumber = "${{ github.event.pull_request.number }}" if(baseName === "nuxt:2.x") { github.rest.issues.addLabels({ From 9bc7f135f40e1d9ada5beb9345c625e98061b4e6 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 1 Dec 2023 11:46:34 +0100 Subject: [PATCH 5/5] chore: use pinned version of github-script --- .github/workflows/label-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-pr.yml b/.github/workflows/label-pr.yml index d83ca6a4c39b..8429de7f03d3 100644 --- a/.github/workflows/label-pr.yml +++ b/.github/workflows/label-pr.yml @@ -16,7 +16,7 @@ jobs: pull-requests: write if: github.repository == 'nuxt/nuxt' steps: - - uses: actions/github-script@v6 + - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 with: script: | const baseName = "${{ github.event.pull_request.base.label }}"