Implement automatic PR labeling system with 46 labels#192
Conversation
- Add .github/labeler.yml with 35+ label categories - Add setup-labels.yml workflow for label creation - Add labeler.yml workflow for automatic PR labeling - Add LABELS.md documentation with comprehensive guide - Update README.md to reference label system - Categories: content, technology, data, i18n, ISMS, infrastructure, quality, AI - Security hardened workflows (SHA pinning, step-security/harden-runner) - Automatic size labels based on PR diff - PR comment with label summary on new PRs Co-authored-by: pethers <[email protected]>
- Add section 16 documenting automatic PR labeling system - Update workflow inventory (15 → 17 workflows) - Document setup-labels.yml and labeler.yml workflows - Add labeling examples and troubleshooting guide - Include label categories and application logic - Add reference to LABELS.md - Update version to 3.0, date to 2026-02-15 Co-authored-by: pethers <[email protected]>
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
There was a problem hiding this comment.
Pull request overview
This PR implements a comprehensive automatic PR labeling system for the Riksdagsmonitor repository. The system categorizes pull requests based on file changes, titles, and descriptions using 46 labels across 12 categories (Content, Technology, Data, I18n, ISMS, Infrastructure, Quality, Standard, AI, Priority, Size, Status). The implementation follows security best practices with SHA-pinned actions, harden-runner enabled, and least-privilege permissions.
Changes:
- Adds automated labeling workflows with security hardening and comprehensive label coverage
- Creates 46-label taxonomy aligned with repository architecture (content, technology, compliance, quality)
- Provides complete documentation with setup guides, troubleshooting, and usage examples
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/setup-labels.yml |
New workflow for creating/updating 46 repository labels with idempotent label management |
.github/workflows/labeler.yml |
New workflow for automatic PR labeling with size calculation and summary comments |
.github/labeler.yml |
Configuration defining 452 lines of labeling rules based on file paths, titles, and body patterns |
LABELS.md |
Comprehensive 439-line documentation covering all 46 labels with examples and troubleshooting |
WORKFLOWS.md |
Adds section 16 documenting the labeling system and updates workflow inventory to 17 total |
README.md |
Adds LABELS.md reference to project documentation list |
LABELS.md
Outdated
|
|
||
| ### Key Features | ||
| - ✅ **Automatic labeling** based on file paths, PR titles, and descriptions | ||
| - ✅ **35+ labels** covering all aspects of the project |
There was a problem hiding this comment.
The label count is inconsistent. The documentation states "35+ labels" but the PR description and setup-labels.yml workflow define exactly 46 labels. Update this to "46 labels" for accuracy and consistency with the PR description and implementation.
| - ✅ **35+ labels** covering all aspects of the project | |
| - ✅ **46 labels** covering all aspects of the project |
There was a problem hiding this comment.
Fixed in e59a547. Updated label count from "35+" to "46" for accuracy in LABELS.md line 16.
.github/workflows/setup-labels.yml
Outdated
| if [ "$label_count" -lt 35 ]; then | ||
| echo "⚠️ Warning: Expected at least 35 labels, but found only $label_count" |
There was a problem hiding this comment.
The label verification threshold should be updated to 46 (not "at least 35") to match the actual number of labels defined in this workflow. This ensures the verification step accurately validates that all labels were created successfully.
| if [ "$label_count" -lt 35 ]; then | |
| echo "⚠️ Warning: Expected at least 35 labels, but found only $label_count" | |
| if [ "$label_count" -ne 46 ]; then | |
| echo "⚠️ Error: Expected 46 labels, but found $label_count" |
There was a problem hiding this comment.
Fixed in e59a547. Updated verification to expect exactly 46 labels (not "at least 35") in setup-labels.yml line 176.
.github/workflows/labeler.yml
Outdated
| EOF | ||
|
|
||
| # Replace placeholder with actual labels | ||
| sed -i "s/\$LABELS/$LABELS/" /tmp/comment.md |
There was a problem hiding this comment.
The sed command to replace $LABELS placeholder could fail if label names contain special characters like forward slashes, ampersands, or backslashes. Consider using a safer approach like using a different sed delimiter or using alternative string replacement methods that don't interpret special characters. For example: sed -i "s|\$LABELS|$LABELS|" /tmp/comment.md (using | as delimiter) or properly escaping the LABELS variable.
| sed -i "s/\$LABELS/$LABELS/" /tmp/comment.md | |
| ESCAPED_LABELS=${LABELS//\\/\\\\} | |
| ESCAPED_LABELS=${ESCAPED_LABELS//&/\\&} | |
| ESCAPED_LABELS=${ESCAPED_LABELS//\//\\/} | |
| sed -i "s/\$LABELS/$ESCAPED_LABELS/" /tmp/comment.md |
There was a problem hiding this comment.
Fixed in e59a547. Added proper escaping for backslash, ampersand, and forward slash characters before sed replacement in labeler.yml lines 169-172.
.github/workflows/setup-labels.yml
Outdated
| - name: Setup GitHub CLI | ||
| run: | | ||
| echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token | ||
|
|
There was a problem hiding this comment.
The "Setup GitHub CLI" step with gh auth login --with-token is unnecessary. GitHub CLI automatically authenticates using the GH_TOKEN or GITHUB_TOKEN environment variable when available. Since subsequent steps already set GH_TOKEN in their env sections, this explicit login step can be removed for simplicity.
| - name: Setup GitHub CLI | |
| run: | | |
| echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token |
There was a problem hiding this comment.
Fixed in e59a547. Removed the unnecessary GitHub CLI setup step since GH_TOKEN auto-authenticates from setup-labels.yml lines 30-32.
|
@copilot apply changes based on the comments in this thread |
- Update label count from "35+" to "46" for accuracy (LABELS.md) - Fix verification threshold to expect exactly 46 labels (setup-labels.yml) - Escape special characters in sed replacement for label names (labeler.yml) - Remove unnecessary GitHub CLI setup step (setup-labels.yml) All changes validated with YAML syntax check. Co-authored-by: pethers <[email protected]>
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
Setup Automatic Labeling Based on Repository Context
✅ Implementation Complete - Code Review Addressed
All phases of the automatic labeling system have been successfully implemented, documented, and code review feedback has been addressed.
🔄 Code Review Changes (Latest Commit)
Fixed Issues
All changes validated with YAML syntax check.
📋 Implementation Phases
Phase 1: Analysis & Design ✅
Phase 2: Label Configuration ✅
.github/labeler.yml(13 KB, 400+ lines)Phase 3: Label Setup Workflow ✅
.github/workflows/setup-labels.yml(9 KB)Phase 4: Auto-Labeler Workflow ✅
.github/workflows/labeler.yml(7 KB)Phase 5: Testing & Validation ✅
Phase 6: Documentation ✅
LABELS.md(15 KB) - Comprehensive label guideREADME.md- Added LABELS.md referenceWORKFLOWS.md(Section 16) - Label system documentation🎯 Deliverables
Files Created
.github/labeler.yml.github/workflows/setup-labels.yml.github/workflows/labeler.ymlLABELS.mdREADME.md(updated)WORKFLOWS.md(updated)Total: 6 files, ~44 KB of new content
🏷️ Label System Summary
46 Labels Across 12 Categories
Key Features
🔒 Security Compliance
All workflows follow Hack23 ISMS requirements:
✅ SHA-pinned actions (no tags/branches)
step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e(v2.14.2)actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd(v6.0.2)actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b(v6.0.1)✅ Security hardening
step-security/harden-runnerenabled (all workflows)✅ Least privilege permissions
contents: readissues: writepull-requests: write✅ No secrets exposure
$GITHUB_TOKEN🚀 Next Steps
Immediate Testing
Run setup-labels workflow
This will create all 46 labels in the repository.
Verify label creation
Test on this PR
Monitor labeler workflow
Production Deployment
Once testing is successful:
.github/labeler.ymlif needed✅ Acceptance Criteria Met
🎉 Summary
The automatic labeling system is fully implemented, code-reviewed, and ready for testing. All code, workflows, and documentation are complete. Code review feedback has been addressed. The system follows Hack23 ISMS security requirements and provides comprehensive coverage of all riksdagsmonitor repository aspects.
Ready for:
Implementation by: devops-engineer agent
Date: 2026-02-15
Version: 1.1 (code review addressed)
Status: ✅ Complete
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.