You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add 'changed-files-labels-limit' and 'max-files-changed' configs to allow capping number of labels added (#923)
* README.md: drop trailing whitespace
* Add 'changed-files-labels-limit' config to allow capping number of labels 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.
* Add 'max-files-changed' config to allow capping number of files for labelling
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#486
| `changed-files-labels-limit` | Maximum number of new labels to apply based on changed files (must be a non-negative integer). If exceeded, no changed-files labels are applied for that run. |
163
+
| `max-files-changed` | Maximum number of total changed files (must be a non-negative integer). If exceeded, all file-based labeling is skipped. |
164
+
165
+
##### Limiting changed-files labels
166
+
167
+
When working with large PRs (e.g., tree-wide refactors) that touch many components, you may want to prevent the labeler from adding too many labels. Set `changed-files-labels-limit` in your `.github/labeler.yml` configuration file to limit the number of labels that can be applied based on changed files patterns.
168
+
169
+
**Important behaviors:**
170
+
171
+
- The limit counts only **new** labels that would be added by changed-files rules. Labels already present on the PR are not counted toward the limit.
172
+
- If the number of new changed-files labels **exceeds** the limit, **all** new changed-files labels are skipped for that run.
173
+
- If the number of new changed-files labels **equals** the limit, labels are still applied normally.
174
+
- Labels based on branch conditions (`head-branch`, `base-branch`) are **not affected** by the limit.
175
+
- **Any label definition that includes a `changed-files` rule is considered a changed-files label** and is subject to the limit, regardless of which condition caused the label to match. For example, a label with both `head-branch` and `changed-files` rules will be subject to the limit even if it matches via the branch rule.
176
+
- If both `max-files-changed` and `changed-files-labels-limit` are configured at the same time, `max-files-changed` is evaluated first, and if it triggers, `changed-files-labels-limit` is not evaluated.
177
+
178
+
##### Example
179
+
180
+
```yml
181
+
# .github/labeler.yml
182
+
183
+
# Limit changed-files based labels to 5
184
+
changed-files-labels-limit: 5
185
+
186
+
# Label definitions - these are subject to the limit
187
+
frontend:
188
+
- changed-files:
189
+
- any-glob-to-any-file: 'src/frontend/**'
190
+
191
+
backend:
192
+
- changed-files:
193
+
- any-glob-to-any-file: 'src/backend/**'
194
+
195
+
docs:
196
+
- changed-files:
197
+
- any-glob-to-any-file: 'docs/**'
198
+
199
+
# This label has both branch and changed-files rules.
200
+
# It is still subject to the limit because it includes changed-files.
201
+
mixed:
202
+
- any:
203
+
- head-branch: '^feature/'
204
+
- changed-files:
205
+
- any-glob-to-any-file: 'src/mixed/**'
206
+
207
+
# Branch-based labels are NOT affected by the limit
208
+
feature:
209
+
- head-branch: '^feature/'
210
+
```
211
+
212
+
##### Skipping labeling for large PRs
213
+
214
+
When a PR modifies a very large number of files (e.g., tree-wide refactors, automated code formatting), you may want to skip file-based labeling entirely. Set `max-files-changed` in your `.github/labeler.yml` configuration file to skip all file-based labeling when the total number of changed files exceeds the threshold.
215
+
216
+
**Important behaviors:**
217
+
218
+
- If the total number of changed files **exceeds** the limit, all file-based labeling is skipped entirely.
219
+
- If the total number of changed files **equals** the limit, labels are still applied normally.
220
+
- Labels based **only** on branch conditions (`head-branch`, `base-branch`) are **not affected** by the limit.
221
+
- **Any label definition that includes a `changed-files` rule is considered a file-based label** and will be skipped, regardless of which condition caused the label to match. For example, a label with both `head-branch` and `changed-files` rules will be skipped even if it would match via the branch rule.
222
+
- Pre-existing labels on the PR are **preserved** — changed-files configs are not evaluated at all, so `sync-labels` will not remove them.
223
+
224
+
##### Example
225
+
226
+
```yml
227
+
# .github/labeler.yml
228
+
229
+
# Skip file-based labeling if more than 100 files changed
230
+
max-files-changed: 100
231
+
232
+
# These labels will be skipped if > 100 files changed
233
+
frontend:
234
+
- changed-files:
235
+
- any-glob-to-any-file: 'src/frontend/**'
236
+
237
+
backend:
238
+
- changed-files:
239
+
- any-glob-to-any-file: 'src/backend/**'
240
+
241
+
# Branch-based labels are NOT affected
242
+
release:
243
+
- base-branch: 'main'
244
+
```
245
+
156
246
### Create Workflow
157
247
158
248
Create a workflow (e.g. `.github/workflows/labeler.yml` see [Creating a Workflow file](https://docs.github.com/en/actions/writing-workflows/quickstart#creating-your-first-workflow)) to utilize the labeler action with content:
@@ -213,10 +303,10 @@ jobs:
213
303
pull-requests: write
214
304
runs-on: ubuntu-latest
215
305
steps:
216
-
306
+
217
307
# Label PRs 1, 2, and 3
218
308
- uses: actions/labeler@v6
219
-
with:
309
+
with:
220
310
pr-number: |
221
311
1
222
312
2
@@ -225,9 +315,9 @@ jobs:
225
315
226
316
**Note:** in normal usage the `pr-number` input is not required as the action will detect the PR number from the workflow context.
@@ -291,7 +381,7 @@ To ensure the action works correctly, include the following permissions in your
291
381
issues: write
292
382
```
293
383
294
-
### Manual Label Creation as an Alternative to Granting issues write Permission
384
+
### Manual Label Creation as an Alternative to Granting issues write Permission
295
385
296
386
If you prefer not to grant the `issues: write` permission in your workflow, you can manually create all required labels in the repository before the action runs.
0 commit comments