From 870312340ace4ee544ab63385f87edf97fb0a005 Mon Sep 17 00:00:00 2001 From: Philippe Serhal Date: Sat, 28 Mar 2026 15:33:25 -0400 Subject: [PATCH] ci: label PRs that don't respect PR template --- .github/PULL_REQUEST_TEMPLATE.md | 2 ++ .github/scripts/sync-pr-body-007-label.mjs | 33 ++++++++++++++++++++++ .github/workflows/pr-body-007-label.yml | 29 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .github/scripts/sync-pr-body-007-label.mjs create mode 100644 .github/workflows/pr-body-007-label.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6731f10e1e..bd8b7f6453 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,3 +1,5 @@ + + ### 🔗 Linked issue diff --git a/.github/scripts/sync-pr-body-007-label.mjs b/.github/scripts/sync-pr-body-007-label.mjs new file mode 100644 index 0000000000..2339b4060d --- /dev/null +++ b/.github/scripts/sync-pr-body-007-label.mjs @@ -0,0 +1,33 @@ +export default async function syncLabel({ github, context, label, marker }) { + const owner = context.repo.owner + const repo = context.repo.repo + const issue_number = context.payload.pull_request.number + const body = context.payload.pull_request.body || '' + + const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ + owner, + repo, + issue_number, + }) + + const hasLabel = currentLabels.some(({ name }) => name === label) + const wantsLabel = body.includes(marker) + + if (wantsLabel && !hasLabel) { + await github.rest.issues.addLabels({ + owner, + repo, + issue_number, + labels: [label], + }) + } + + if (!wantsLabel && hasLabel) { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number, + name: label, + }) + } +} diff --git a/.github/workflows/pr-body-007-label.yml b/.github/workflows/pr-body-007-label.yml new file mode 100644 index 0000000000..de727425b4 --- /dev/null +++ b/.github/workflows/pr-body-007-label.yml @@ -0,0 +1,29 @@ +name: PR Body 007 Label + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + sync-007-label: + if: github.repository == 'npmx-dev/npmx.dev' + runs-on: ubuntu-slim + permissions: + contents: read + issues: write + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Sync 007 label + uses: actions/github-script@ed59741142d356d3eca8bc5478a0bee8cb865736 # v8.0.0 + env: + LABEL_NAME: '007' + BODY_MARKER: 'If you are a human, please delete this line' + with: + script: | + const { default: syncLabel } = await import('./.github/scripts/sync-pr-body-007-label.mjs'); + await syncLabel({ github, context, label: process.env.LABEL_NAME, marker: process.env.BODY_MARKER });