diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6731f10e1..bd8b7f645 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 000000000..2339b4060 --- /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 000000000..de727425b --- /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 });