|
| 1 | +name: "Author Labeler" |
| 2 | + |
| 3 | +on: # zizmor: ignore[dangerous-triggers] - needs pull_request_target for a |
| 4 | + # writable token on fork PRs; the script only reads the opaque author |
| 5 | + # login/number fields below, never PR-controlled free text (title, body, |
| 6 | + # branch), and nothing is interpolated into a shell `run:` |
| 7 | + pull_request_target: |
| 8 | + branches: [master] |
| 9 | + types: [opened] |
| 10 | + issues: |
| 11 | + types: [opened] |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.issue.number }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + label: |
| 22 | + name: Label |
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + issues: write # to add a roster label to a matching issue |
| 26 | + pull-requests: write # to add a roster label to a matching PR |
| 27 | + runs-on: ubuntu-slim |
| 28 | + steps: |
| 29 | + - name: Label if the author is on a wiki roster |
| 30 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 31 | + with: |
| 32 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + script: | |
| 34 | + // Rosters live on the wiki so committers can edit them without a |
| 35 | + // PR: https://github.com/apache/superset/wiki/Label-Rosters |
| 36 | + // Each `## heading` on that page is a label; each list item under |
| 37 | + // it is a GitHub handle. |
| 38 | + const ROSTER_PAGE = 'Label-Rosters'; |
| 39 | +
|
| 40 | + // The wiki can only assign labels named here. Wiki edits are not |
| 41 | + // reviewed, and some labels drive other workflows (`hold`, |
| 42 | + // showtime), so adding a label to this list takes a PR while |
| 43 | + // adding handles to a roster does not. |
| 44 | + const ALLOWED_LABELS = ['utsc2026']; |
| 45 | +
|
| 46 | + const { owner, repo } = context.repo; |
| 47 | + const url = `https://raw.githubusercontent.com/wiki/${owner}/${repo}/${ROSTER_PAGE}.md`; |
| 48 | + let response; |
| 49 | + try { |
| 50 | + response = await fetch(url); |
| 51 | + } catch (error) { |
| 52 | + core.warning(`Could not read ${url} (${error.message}); no roster labels applied.`); |
| 53 | + return; |
| 54 | + } |
| 55 | + if (!response.ok) { |
| 56 | + core.warning(`Could not read ${url} (HTTP ${response.status}); no roster labels applied.`); |
| 57 | + return; |
| 58 | + } |
| 59 | +
|
| 60 | + const rosters = new Map(); |
| 61 | + let label = null; |
| 62 | + for (const line of (await response.text()).split('\n')) { |
| 63 | + const heading = line.match(/^##\s+`?([^`]+?)`?\s*$/); |
| 64 | + if (heading) { |
| 65 | + label = heading[1]; |
| 66 | + continue; |
| 67 | + } |
| 68 | + const handle = line.match(/^\s*[-*]\s+@?([A-Za-z0-9-]+)\s*$/); |
| 69 | + if (label && handle) { |
| 70 | + if (!rosters.has(label)) rosters.set(label, new Set()); |
| 71 | + rosters.get(label).add(handle[1].toLowerCase()); |
| 72 | + } |
| 73 | + } |
| 74 | +
|
| 75 | + const target = context.payload.pull_request ?? context.payload.issue; |
| 76 | + const author = target.user.login.toLowerCase(); |
| 77 | + const labels = [...rosters.keys()].filter(name => rosters.get(name).has(author)); |
| 78 | +
|
| 79 | + const blocked = labels.filter(name => !ALLOWED_LABELS.includes(name)); |
| 80 | + if (blocked.length) { |
| 81 | + core.warning(`Skipping roster label(s) missing from ALLOWED_LABELS: ${blocked.join(', ')}`); |
| 82 | + } |
| 83 | + const allowed = labels.filter(name => ALLOWED_LABELS.includes(name)); |
| 84 | + if (!allowed.length) { |
| 85 | + return; |
| 86 | + } |
| 87 | +
|
| 88 | + await github.rest.issues.addLabels({ |
| 89 | + owner, |
| 90 | + repo, |
| 91 | + issue_number: target.number, |
| 92 | + labels: allowed, |
| 93 | + }); |
0 commit comments