Commit 2b8fa47da0
Unsigned
Layout: unified · split
.github/workflows/pr-comment.yml +65
| @@ -6,6 +6,8 @@ on: | ||
| 6 | 6 | types: [completed] |
| 7 | 7 | pull_request_review: |
| 8 | 8 | types: [submitted] |
| 9 | pull_request_target: | |
| 10 | types: [opened, edited, reopened] | |
| 9 | 11 | |
| 10 | 12 | permissions: |
| 11 | 13 | actions: read |
| @@ -253,3 +255,66 @@ jobs: | ||
| 253 | 255 | } catch (err) { |
| 254 | 256 | console.log(`Failed to assign Lissy93: ${err.message}`); |
| 255 | 257 | } |
| 258 | ||
| 259 | # Applies a label matching the "Type" picked in the PR template. Non-critical and | |
| 260 | # fully self-contained: it never fails the run, and runs independently of the checks. | |
| 261 | label-type: | |
| 262 | name: Apply type label | |
| 263 | runs-on: ubuntu-latest | |
| 264 | if: github.event_name == 'pull_request_target' | |
| 265 | permissions: | |
| 266 | issues: write | |
| 267 | pull-requests: write | |
| 268 | concurrency: | |
| 269 | group: label-type-${{ github.event.pull_request.number }} | |
| 270 | cancel-in-progress: true | |
| 271 | steps: | |
| 272 | - name: Apply label from PR type | |
| 273 | continue-on-error: true | |
| 274 | uses: actions/github-script@v8 | |
| 275 | with: | |
| 276 | github-token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} | |
| 277 | script: | | |
| 278 | try { | |
| 279 | const { owner, repo } = context.repo; | |
| 280 | const pr = context.payload.pull_request; | |
| 281 | ||
| 282 | // Template "Type" token -> label to apply | |
| 283 | const TYPES = [ | |
| 284 | ['Addition', 'Addition'], | |
| 285 | ['Amendment', 'Amendment'], | |
| 286 | ['Removal', 'Removal'], | |
| 287 | ['Spelling or Grammar', 'Grammar'], | |
| 288 | ['Website', 'Website'], | |
| 289 | ['Scripts', 'Scripts'], | |
| 290 | ['Misc', 'Misc'], | |
| 291 | ]; | |
| 292 | const managed = [...TYPES.map(t => t[1]), 'Uncategorized']; | |
| 293 | ||
| 294 | // Isolate the "### Type" section, drop HTML comments, lowercase for matching | |
| 295 | const body = pr.body || ''; | |
| 296 | const m = body.match(/###\s*Type\b([\s\S]*?)(?:\n\s*###|\n\s*---|$)/i); | |
| 297 | const section = (m ? m[1] : '').replace(/<!--[\s\S]*?-->/g, '').toLowerCase(); | |
| 298 | ||
| 299 | // A correctly filled template leaves exactly one type; otherwise Uncategorized | |
| 300 | const matched = TYPES.filter(t => section.includes(t[0].toLowerCase())).map(t => t[1]); | |
| 301 | const desired = matched.length === 1 ? matched[0] : 'Uncategorized'; | |
| 302 | ||
| 303 | const current = (pr.labels || []).map(l => l.name); | |
| 304 | for (const name of current.filter(l => managed.includes(l) && l !== desired)) { | |
| 305 | await github.rest.issues.removeLabel({ owner, repo, issue_number: pr.number, name }) | |
| 306 | .catch(e => console.log(`Skip remove ${name}: ${e.message}`)); | |
| 307 | } | |
| 308 | ||
| 309 | if (!current.includes(desired)) { | |
| 310 | await github.rest.issues.getLabel({ owner, repo, name: desired }).catch(async e => { | |
| 311 | if (e.status === 404) { | |
| 312 | await github.rest.issues.createLabel({ owner, repo, name: desired, color: 'ededed' }); | |
| 313 | } | |
| 314 | }); | |
| 315 | await github.rest.issues.addLabels({ owner, repo, issue_number: pr.number, labels: [desired] }); | |
| 316 | } | |
| 317 | console.log(`Type label: ${desired} (matched ${matched.length})`); | |
| 318 | } catch (err) { | |
| 319 | console.log(`Type labeling skipped: ${err.message}`); | |
| 320 | } | |
lib/review-listings.py +1 −3
| @@ -827,9 +827,7 @@ def main(): | ||
| 827 | 827 | token = args.token or os.environ.get("GITHUB_TOKEN", "") |
| 828 | 828 | api_token = os.environ.get("API_TOKEN", "") |
| 829 | 829 | |
| 830 | # A targeted review (single entry/diff) runs token-gated checks unauthenticated, accepting | |
| 831 | # rate limits. A full review skips them without a token, to avoid hammering the APIs across | |
| 832 | # every listing once limits are hit. | |
| 830 | # A targeted review (single entry/diff) runs external checks unauthenticated, as probz won't hit rate limit | |
| 833 | 831 | targeted = bool(args.service or args.category or args.section or args.changed_since) |
| 834 | 832 | |
| 835 | 833 | if not token: |