Skip to content

Commit 75d4d95

Browse files
authored
Remove labels on stale (#959)
1 parent 01aa532 commit 75d4d95

File tree

11 files changed

+1398
-1315
lines changed

11 files changed

+1398
-1315
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Every argument is optional.
6363
| [remove-issue-stale-when-updated](#remove-issue-stale-when-updated) | Remove stale label from issues on updates/comments | |
6464
| [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | |
6565
| [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | |
66+
| [labels-to-remove-when-stale](#labels-to-remove-when-stale) | Remove specified labels from issues/PRs when they become stale | |
6667
| [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | |
6768
| [debug-only](#debug-only) | Dry-run | `false` |
6869
| [ascending](#ascending) | Order to get issues/PRs | `false` |
@@ -358,6 +359,15 @@ A comma delimited list of labels to add when a stale issue or pull request recei
358359

359360
Default value: unset
360361

362+
#### labels-to-remove-when-stale
363+
364+
A comma delimited list of labels to remove when an issue or pull request becomes stale and has the [stale-issue-label](#stale-issue-label) or [stale-pr-label](#stale-pr-label) added to it.
365+
366+
Warning: each label results in a unique API call which can drastically consume the limit of [operations-per-run](#operations-per-run).
367+
368+
Default value: unset
369+
Required Permission: `pull-requests: write`
370+
361371
#### labels-to-remove-when-unstale
362372

363373
A comma delimited list of labels to remove when a stale issue or pull request receives activity and has the [stale-issue-label](#stale-issue-label) or [stale-pr-label](#stale-pr-label) removed from it.

__tests__/constants/default-processor-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
4747
exemptAllIssueAssignees: undefined,
4848
exemptAllPrAssignees: undefined,
4949
enableStatistics: true,
50+
labelsToRemoveWhenStale: '',
5051
labelsToRemoveWhenUnstale: '',
5152
labelsToAddWhenUnstale: '',
5253
ignoreUpdates: false,

__tests__/main.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,48 @@ test('when the option "labelsToAddWhenUnstale" is set, the labels should be adde
12201220
expect(processor.addedLabelIssues).toHaveLength(1);
12211221
});
12221222

1223+
test('when the option "labelsToRemoveWhenStale" is set, the labels should be removed when stale', async () => {
1224+
expect.assertions(3);
1225+
const opts = {
1226+
...DefaultProcessorOptions,
1227+
removeStaleWhenUpdated: true,
1228+
labelsToRemoveWhenStale: 'test'
1229+
};
1230+
const TestIssueList: Issue[] = [
1231+
generateIssue(
1232+
opts,
1233+
1,
1234+
'An issue that should have labels removed to it when stale',
1235+
'2020-01-01T17:00:00Z',
1236+
'2020-01-01T17:00:00Z',
1237+
false,
1238+
['Stale', 'test']
1239+
)
1240+
];
1241+
const processor = new IssuesProcessorMock(
1242+
opts,
1243+
async p => (p === 1 ? TestIssueList : []),
1244+
async () => [
1245+
{
1246+
user: {
1247+
login: 'notme',
1248+
type: 'User'
1249+
},
1250+
body: 'Body'
1251+
}
1252+
], // return a fake comment to indicate there was an update
1253+
async () => new Date().toDateString()
1254+
);
1255+
1256+
// process our fake issue list
1257+
await processor.processIssues(1);
1258+
1259+
expect(processor.closedIssues).toHaveLength(0);
1260+
expect(processor.staleIssues).toHaveLength(0);
1261+
// test label should have been removed
1262+
expect(processor.removedLabelIssues).toHaveLength(1);
1263+
});
1264+
12231265
test('stale label should not be removed if a comment was added by the bot (and the issue should be closed)', async () => {
12241266
const opts = {...DefaultProcessorOptions, removeStaleWhenUpdated: true};
12251267
github.context.actor = 'abot';

action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,15 @@ inputs:
177177
default: 'true'
178178
required: false
179179
labels-to-add-when-unstale:
180-
description: 'A comma delimited list of labels to add when a stale issue or pull request receives activity and has the stale-issue-label or stale-pr-label removed from it.'
180+
description: 'A comma delimited list of labels to add when an issue or pull request becomes unstale.'
181+
default: ''
182+
required: false
183+
labels-to-remove-when-stale:
184+
description: 'A comma delimited list of labels to remove when an issue or pull request becomes stale.'
181185
default: ''
182186
required: false
183187
labels-to-remove-when-unstale:
184-
description: 'A comma delimited list of labels to remove when a stale issue or pull request receives activity and has the stale-issue-label or stale-pr-label removed from it.'
188+
description: 'A comma delimited list of labels to remove when an issue or pull request becomes unstale.'
185189
default: ''
186190
required: false
187191
ignore-updates:

0 commit comments

Comments
 (0)