Add 'changed-files-labels-limit' and 'max-files-changed' configs to allow capping number of labels added#923
Conversation
|
Example of a PR where the labeling gets out of hands and spams the discussion page: systemd/systemd#40624 |
There was a problem hiding this comment.
Pull request overview
This PR adds a changed-files-limit configuration option to the labeler action to prevent label spam when large refactors touch many components. When the number of new changed-files labels exceeds the configured limit, all new changed-files labels are skipped, while branch-based labels and preexisting labels remain unaffected.
Changes:
- Added
changed-files-limittop-level configuration option to cap the number of changed-files labels - Implemented logic to track and differentiate between changed-files labels and branch-based labels
- Added comprehensive test coverage with 8 new test cases covering various limit scenarios
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/labeler.ts | Implements limit checking logic that tracks changed-files labels and removes them if the limit is exceeded |
| src/api/get-label-configs.ts | Adds parsing and validation for the new changed-files-limit config option and a helper function to identify changed-files labels |
| dist/index.js | Compiled JavaScript output reflecting the TypeScript changes |
| tests/main.test.ts | Adds 8 integration test cases covering various limit scenarios including edge cases with preexisting labels |
| tests/labeler.test.ts | Adds unit tests for the new parsing logic and configUsesChangedFiles helper function |
| tests/fixtures/*.yml | Four new YAML test fixtures with different limit configurations |
| README.md | Comprehensive documentation of the new feature with examples and usage guidance |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 11 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi 👋 thanks again for working on this — the option added in #923 to cap how many changed-files labels get applied is very useful for preventing label spam in large PRs. One nuance though: it seems to address a slightly different problem than the original request in #486.
Would you be open to extending this PR or adding a follow-up to support something like: If the total changed files exceed N, file-based labeling could be skipped entirely. This would align more closely with the original goal in #486 and also avoid unnecessary pattern scanning on very large PRs. While reviewing the implementation and README, I also noted a few smaller suggestions: 1. Naming & SemanticsThe name Suggestion Consider renaming to something clearer like If renaming could break configs, we could support both names and treat 2. Stricter Configuration ParsingThe current parsing uses Examples:
To make configuration validation stricter and safer:
Potential tests:
3. Clarifying the Definition of a “Changed-Files Label”One subtle behavior worth documenting is how the limit interacts with mixed rules. Example: Even if the label matches via the branch rule, the presence of a `changed-files` rule causes it to be treated as a changed-files label and therefore subject to the limit. It might help to document something like:
Adding a small dedicated test fixture could also help make this behavior explicit. 4. README DocumentationThe new Configuration Options section is a great addition 👍. It might help to explicitly mention:
|
|
@chiranjib-swain thanks for the review, applied all suggestions and requests |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
a07363b to
ce49779
Compare
|
Fixes the formatting issue (hopefully) |
|
@chiranjib-swain anything else I can do here? Thanks |
|
Hi @bluca ,Really nice work on this 👏 — the addition of 🔹 Suggestion: Improve parseNonNegativeInteger One small suggestion regarding Currently the regex check runs directly on the raw string value. This means inputs like " 30 " would be rejected even though they represent a valid integer. It might be worth trimming the string before applying the regex so that common whitespace cases are handled more gracefully. Since the regex already guarantees that the string contains only digits, we could also use Finally, the non-negativity check ( Something along these lines could work: This is a fairly small refinement, but it could make the validation a bit more robust while keeping the current behavior intact. 🔹 Suggestion: Clarify Threshold Semantics Additionally, one small suggestion regarding threshold semantics: If both limits are introduced/configured (e.g.,
Documenting this precedence explicitly could help avoid confusion and make the behavior more predictable. 🔹 Suggestion: Reserved Keys Clarification Using keys like Currently, this results in an error like:
We should either document these as reserved keys or improve the error message, e.g.:
🔹 Suggestion: PR Title Improvement Your current title: has a typo (the same option is repeated) and it doesn’t mention |
…bels added When a repository has many components, each with a changed-files label, a large refactor ends up with the labeler spamming the pull request with label changes. The end result is not very useful as it's not very readable, and due to how github automatically hides comments when label changes overflow the discussion tab, it means useful information is hidden and one has to manually click "Load more..." dozens of time every time the page is loaded. Add a changed-files-labels-limit top level config knob. If more than the configured limit of labels is set to be added, none are added. This only affects changed-files labels.
|
@chiranjib-swain thank you, updated as requested, PTAL |
|
CI failures look to be unrelated (dependencies audit) |
|
Thanks for the improvements here — the new caps for changed-files labeling look really useful, especially for large refactors. One thing before we can proceed: the Also, small docs nits for clarity:
Thanks again! |
|
Hi - I've ran |
Changed
There already is: Would you like me to reword it or move it? |
This is on Debian unstable with NPM 9.2.0 |
|
Hi @bluca The Labeler repository now officially runs on Node.js 24, as reflected in its workflows and documentation. Please use Node.js version 24 / npm version 11+ when running the command to ensure the check dist workflow passes. |
…abelling When a PR modifies a very large number of files (e.g., tree-wide refactors, automated code formatting), this new options allows skipping file-based labeling entirely when the number of files that are changed hits the configured limit. Fixes actions#486
@HarithaVattikuti got it thanks, rerun with npm 11.12.0 and now it did update it, pushed it |
…v6.0.1 → v6.1.0) (#384) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [https://github.com/actions/labeler](https://github.com/actions/labeler) | action | minor | `v6.0.1` → `v6.1.0` | --- ### Release Notes <details> <summary>actions/labeler (https://github.com/actions/labeler)</summary> ### [`v6.1.0`](https://github.com/actions/labeler/releases/tag/v6.1.0) [Compare Source](actions/labeler@v6.0.1...v6.1.0) #### Enhancements - Add changed-files-labels-limit and max-files-changed configuration options to cap the number of labels added by [@​bluca](https://github.com/bluca) in [#​923](actions/labeler#923) #### Bug Fixes - Improve Labeler Action documentation and permission error handling by [@​chiranjib-swain](https://github.com/chiranjib-swain) in [#​897](actions/labeler#897) - Preserve manually added labels during workflow runs and refine label synchronization logic by [@​chiranjib-swain](https://github.com/chiranjib-swain) in [#​917](actions/labeler#917) #### Dependency Updates - Upgrade brace-expansion from 1.1.11 to 1.1.12 and document breaking changes in v6 by [@​dependabot](https://github.com/dependabot) in [#​877](actions/labeler#877) - Upgrade minimatch from 10.0.1 to 10.2.3 by [@​dependabot](https://github.com/dependabot) in [#​926](actions/labeler#926) - Upgrade dependencies ([@​actions/core](https://github.com/actions/core), [@​actions/github](https://github.com/actions/github), js-yaml, minimatch, [@​typescript-eslint](https://github.com/typescript-eslint)) by [@​Copilot](https://github.com/Copilot) in [#​934](actions/labeler#934) #### New Contributors - [@​chiranjib-swain](https://github.com/chiranjib-swain) made their first contribution in [#​897](actions/labeler#897) - [@​bluca](https://github.com/bluca) made their first contribution in [#​923](actions/labeler#923) - [@​Copilot](https://github.com/Copilot) made their first contribution in [#​934](actions/labeler#934) **Full Changelog**: <actions/labeler@v6...v6.1.0> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9naXRodWItYWN0aW9uIiwidHlwZS9taW5vciJdfQ==--> Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/384
Description:
When a repository has many components, each with a changed-files label, a large refactor ends up with the labeler spamming the pull request with label changes. The end result is not very useful as it's not very readable, and due to how github automatically hides comments when label changes overflow the discussion tab, it means useful information is hidden and one has to manually click "Load more..." dozens of time every time the page is loaded.
Add a changed-files-limit top level config knob. If more than the configured limit of labels is set to be added, none are added. This only affects changed-files labels.
Check list: