Skip to content

Commit eed91cb

Browse files
authored
Update how stale handles exempt items (#874)
1 parent 10dc265 commit eed91cb

File tree

4 files changed

+21
-62
lines changed

4 files changed

+21
-62
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,17 @@ Required Permission: `pull-requests: write`
246246

247247
#### exempt-issue-labels
248248

249-
The label(s) that can exempt to automatically mark as stale the issues.
250-
It can be a comma separated list of labels (e.g: `question,bug`).
249+
Comma separated list of labels that can be assigned to issues to exclude them from being marked as stale
250+
(e.g: `question,bug`)
251251

252252
If unset (or an empty string), this option will not alter the stale workflow.
253253

254254
Default value: unset
255255

256256
#### exempt-pr-labels
257257

258-
The label(s) that can exempt to automatically mark as stale the pull requests.
259-
It can be a comma separated list of labels (e.g: `need-help,WIP`).
258+
Comma separated list of labels that can be assigned to pull requests to exclude them from being marked as stale
259+
(e.g: `need-help,WIP`)
260260

261261
If unset (or an empty string), this option will not alter the stale workflow.
262262

__tests__/main.spec.ts

-38
Original file line numberDiff line numberDiff line change
@@ -1094,44 +1094,6 @@ test('exempt pr labels will not be marked stale', async () => {
10941094
expect(processor.staleIssues).toHaveLength(2); // PR should get processed even though it has an exempt **issue** label
10951095
});
10961096

1097-
test('exempt issue labels will not be marked stale and will remove the existing stale label', async () => {
1098-
expect.assertions(3);
1099-
const opts = {...DefaultProcessorOptions};
1100-
opts.exemptIssueLabels = 'Exempt';
1101-
const TestIssueList: Issue[] = [
1102-
generateIssue(
1103-
opts,
1104-
1,
1105-
'My first issue',
1106-
'2020-01-01T17:00:00Z',
1107-
'2020-01-01T17:00:00Z',
1108-
false,
1109-
['Exempt', 'Stale']
1110-
)
1111-
];
1112-
const processor = new IssuesProcessorMock(
1113-
opts,
1114-
async p => (p === 1 ? TestIssueList : []),
1115-
async () => [
1116-
{
1117-
user: {
1118-
login: 'notme',
1119-
type: 'User'
1120-
},
1121-
body: 'Body'
1122-
}
1123-
], // return a fake comment to indicate there was an update
1124-
async () => new Date().toDateString()
1125-
);
1126-
1127-
// process our fake issue list
1128-
await processor.processIssues(1);
1129-
1130-
expect(processor.staleIssues.length).toStrictEqual(0);
1131-
expect(processor.closedIssues.length).toStrictEqual(0);
1132-
expect(processor.removedLabelIssues.length).toStrictEqual(1);
1133-
});
1134-
11351097
test('stale issues should not be closed if days is set to -1', async () => {
11361098
const opts = {...DefaultProcessorOptions};
11371099
opts.daysBeforeClose = -1;

dist/index.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -523,20 +523,17 @@ class IssuesProcessor {
523523
}
524524
}
525525
if (issue.isStale) {
526-
issueLogger.info(`This $$type has a stale label`);
526+
issueLogger.info(`This $$type includes a stale label`);
527527
}
528528
else {
529-
issueLogger.info(`This $$type hasn't a stale label`);
529+
issueLogger.info(`This $$type does not include a stale label`);
530530
}
531531
const exemptLabels = words_to_list_1.wordsToList(issue.isPullRequest
532532
? this.options.exemptPrLabels
533533
: this.options.exemptIssueLabels);
534-
if (exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel))) {
535-
if (issue.isStale) {
536-
issueLogger.info(`An exempt label was added after the stale label.`);
537-
yield this._removeStaleLabel(issue, staleLabel);
538-
}
539-
issueLogger.info(`Skipping this $$type because it has an exempt label`);
534+
const hasExemptLabel = exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel));
535+
if (hasExemptLabel) {
536+
issueLogger.info(`Skipping this $$type because it contains an exempt label, see ${issueLogger.createOptionLink(issue.isPullRequest ? option_1.Option.ExemptPrLabels : option_1.Option.ExemptIssueLabels)} for more details`);
540537
IssuesProcessor._endIssueProcessing(issue);
541538
return; // Don't process exempt issues
542539
}

src/classes/issues-processor.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ export class IssuesProcessor {
321321
}
322322

323323
if (issue.isStale) {
324-
issueLogger.info(`This $$type has a stale label`);
324+
issueLogger.info(`This $$type includes a stale label`);
325325
} else {
326-
issueLogger.info(`This $$type hasn't a stale label`);
326+
issueLogger.info(`This $$type does not include a stale label`);
327327
}
328328

329329
const exemptLabels: string[] = wordsToList(
@@ -332,17 +332,16 @@ export class IssuesProcessor {
332332
: this.options.exemptIssueLabels
333333
);
334334

335-
if (
336-
exemptLabels.some((exemptLabel: Readonly<string>): boolean =>
337-
isLabeled(issue, exemptLabel)
338-
)
339-
) {
340-
if (issue.isStale) {
341-
issueLogger.info(`An exempt label was added after the stale label.`);
342-
await this._removeStaleLabel(issue, staleLabel);
343-
}
335+
const hasExemptLabel = exemptLabels.some((exemptLabel: Readonly<string>) =>
336+
isLabeled(issue, exemptLabel)
337+
);
344338

345-
issueLogger.info(`Skipping this $$type because it has an exempt label`);
339+
if (hasExemptLabel) {
340+
issueLogger.info(
341+
`Skipping this $$type because it contains an exempt label, see ${issueLogger.createOptionLink(
342+
issue.isPullRequest ? Option.ExemptPrLabels : Option.ExemptIssueLabels
343+
)} for more details`
344+
);
346345
IssuesProcessor._endIssueProcessing(issue);
347346
return; // Don't process exempt issues
348347
}
@@ -427,6 +426,7 @@ export class IssuesProcessor {
427426
// Determine if this issue needs to be marked stale first
428427
if (!issue.isStale) {
429428
issueLogger.info(`This $$type is not stale`);
429+
430430
const shouldIgnoreUpdates: boolean = new IgnoreUpdates(
431431
this.options,
432432
issue

0 commit comments

Comments
 (0)