From 8b2642b0ba1971d90697bb854ab9e7680d1dcd2d Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 1 May 2025 15:23:56 +1200 Subject: [PATCH 1/5] Add workflow to check mismatching labels --- .github/workflows/needs-docs.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/needs-docs.yml diff --git a/.github/workflows/needs-docs.yml b/.github/workflows/needs-docs.yml new file mode 100644 index 0000000000..8c430dacb0 --- /dev/null +++ b/.github/workflows/needs-docs.yml @@ -0,0 +1,25 @@ +name: Check labels + +on: + pull_request: + types: [labeled, unlabeled] + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - name: Check for needs-docs label + uses: actions/github-script@v7.0.1 + with: + script: | + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + const hasParent = labels.find(label => label.name === 'has-parent'); + const current = labels.find(label => label.name === 'current'); + if (hasParent && current) { + core.setFailed('Pull request has parent code PR but is targetting current. Please change the target branch to next.'); + } From 7438748e0b0171c5011ac7006e004000e40b1389 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 1 May 2025 15:28:11 +1200 Subject: [PATCH 2/5] Also require changes --- .github/workflows/needs-docs.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/needs-docs.yml b/.github/workflows/needs-docs.yml index 8c430dacb0..d36579b878 100644 --- a/.github/workflows/needs-docs.yml +++ b/.github/workflows/needs-docs.yml @@ -21,5 +21,14 @@ jobs: const hasParent = labels.find(label => label.name === 'has-parent'); const current = labels.find(label => label.name === 'current'); if (hasParent && current) { - core.setFailed('Pull request has parent code PR but is targetting current. Please change the target branch to next.'); + core.setFailed('Pull request has a linked PR in https://github.com/esphome/esphome but is targeting current. Please change the target branch to next.'); } + + const reviewMessage = 'Pull request has a linked PR in https://github.com/esphome/esphome but is targeting current. Please change the target branch to next.'; + await github.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + event: 'REQUEST_CHANGES', + body: reviewMessage + }); From f44e01964e7dc7fcf5d4da7d8a44f44b6f0619e5 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 1 May 2025 15:36:51 +1200 Subject: [PATCH 3/5] Fix and add wrong-base-branch label --- .github/workflows/needs-docs.yml | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/needs-docs.yml b/.github/workflows/needs-docs.yml index d36579b878..5fab0a4941 100644 --- a/.github/workflows/needs-docs.yml +++ b/.github/workflows/needs-docs.yml @@ -21,14 +21,20 @@ jobs: const hasParent = labels.find(label => label.name === 'has-parent'); const current = labels.find(label => label.name === 'current'); if (hasParent && current) { - core.setFailed('Pull request has a linked PR in https://github.com/esphome/esphome but is targeting current. Please change the target branch to next.'); - } + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: ['wrong-base-branch'] + }); - const reviewMessage = 'Pull request has a linked PR in https://github.com/esphome/esphome but is targeting current. Please change the target branch to next.'; - await github.pulls.createReview({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.issue.number, - event: 'REQUEST_CHANGES', - body: reviewMessage - }); + await github.rest.pulls.createReview({ + pull_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + event: 'REQUEST_CHANGES', + body: "As this is a feature matched with a PR in https://github.com/esphome/esphome, please target your PR to the 'next' branch and rebase." + }); + + core.setFailed('As this is a feature matched with a PR in https://github.com/esphome/esphome, please target your PR to the 'next' branch and rebase.'); + } From a5233543d819c29331e60e385ab32b51f637e06c Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 1 May 2025 15:42:59 +1200 Subject: [PATCH 4/5] Fix again --- .../workflows/{needs-docs.yml => check-labels.yml} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename .github/workflows/{needs-docs.yml => check-labels.yml} (81%) diff --git a/.github/workflows/needs-docs.yml b/.github/workflows/check-labels.yml similarity index 81% rename from .github/workflows/needs-docs.yml rename to .github/workflows/check-labels.yml index 5fab0a4941..881ccdf385 100644 --- a/.github/workflows/needs-docs.yml +++ b/.github/workflows/check-labels.yml @@ -9,7 +9,7 @@ jobs: name: Check runs-on: ubuntu-latest steps: - - name: Check for needs-docs label + - name: Check labels uses: actions/github-script@v7.0.1 with: script: | @@ -18,23 +18,23 @@ jobs: repo: context.repo.repo, issue_number: context.issue.number }); - const hasParent = labels.find(label => label.name === 'has-parent'); - const current = labels.find(label => label.name === 'current'); + const hasParent = labels.find(label => label.name === "has-parent"); + const current = labels.find(label => label.name === "current"); if (hasParent && current) { await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, - labels: ['wrong-base-branch'] + labels: ["wrong-base-branch"] }); await github.rest.pulls.createReview({ pull_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - event: 'REQUEST_CHANGES', - body: "As this is a feature matched with a PR in https://github.com/esphome/esphome, please target your PR to the 'next' branch and rebase." + event: "REQUEST_CHANGES", + body: "As this is a feature matched with a PR in https://github.com/esphome/esphome, please target your PR to the `next` branch and rebase." }); - core.setFailed('As this is a feature matched with a PR in https://github.com/esphome/esphome, please target your PR to the 'next' branch and rebase.'); + core.setFailed("As this is a feature matched with a PR in https://github.com/esphome/esphome, please target your PR to the 'next' branch and rebase."); } From e561a10e303c22bee185b0cb74eeaab8471b61b0 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 1 May 2025 15:47:27 +1200 Subject: [PATCH 5/5] Use target so workflow has permissions to do the things --- .github/workflows/check-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml index 881ccdf385..cc2d7901da 100644 --- a/.github/workflows/check-labels.yml +++ b/.github/workflows/check-labels.yml @@ -1,7 +1,7 @@ name: Check labels on: - pull_request: + pull_request_target: types: [labeled, unlabeled] jobs: