Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update how stale handles exempt items #874

Merged
merged 6 commits into from Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -246,17 +246,17 @@ Required Permission: `pull-requests: write`

#### exempt-issue-labels

The label(s) that can exempt to automatically mark as stale the issues.
It can be a comma separated list of labels (e.g: `question,bug`).
Comma separated list of labels that can be assigned to issues to exclude them from being marked as stale
johnsudol marked this conversation as resolved.
Show resolved Hide resolved
(e.g: `question,bug`)

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

Default value: unset

#### exempt-pr-labels

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

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

Expand Down
38 changes: 0 additions & 38 deletions __tests__/main.spec.ts
Expand Up @@ -1094,44 +1094,6 @@ test('exempt pr labels will not be marked stale', async () => {
expect(processor.staleIssues).toHaveLength(2); // PR should get processed even though it has an exempt **issue** label
});

test('exempt issue labels will not be marked stale and will remove the existing stale label', async () => {
expect.assertions(3);
const opts = {...DefaultProcessorOptions};
opts.exemptIssueLabels = 'Exempt';
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
['Exempt', 'Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
},
body: 'Body'
}
], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
);

// process our fake issue list
await processor.processIssues(1);

expect(processor.staleIssues.length).toStrictEqual(0);
expect(processor.closedIssues.length).toStrictEqual(0);
expect(processor.removedLabelIssues.length).toStrictEqual(1);
});

test('stale issues should not be closed if days is set to -1', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeClose = -1;
Expand Down
13 changes: 5 additions & 8 deletions dist/index.js
Expand Up @@ -523,20 +523,17 @@ class IssuesProcessor {
}
}
if (issue.isStale) {
issueLogger.info(`This $$type has a stale label`);
issueLogger.info(`This $$type includes a stale label`);
}
else {
issueLogger.info(`This $$type hasn't a stale label`);
issueLogger.info(`This $$type does not include a stale label`);
johnsudol marked this conversation as resolved.
Show resolved Hide resolved
}
const exemptLabels = words_to_list_1.wordsToList(issue.isPullRequest
? this.options.exemptPrLabels
: this.options.exemptIssueLabels);
if (exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel))) {
if (issue.isStale) {
issueLogger.info(`An exempt label was added after the stale label.`);
yield this._removeStaleLabel(issue, staleLabel);
}
issueLogger.info(`Skipping this $$type because it has an exempt label`);
const hasExemptLabel = exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel));
if (hasExemptLabel) {
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`);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process exempt issues
}
Expand Down
24 changes: 12 additions & 12 deletions src/classes/issues-processor.ts
Expand Up @@ -321,9 +321,9 @@ export class IssuesProcessor {
}

if (issue.isStale) {
issueLogger.info(`This $$type has a stale label`);
issueLogger.info(`This $$type includes a stale label`);
} else {
issueLogger.info(`This $$type hasn't a stale label`);
issueLogger.info(`This $$type does not include a stale label`);
}

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

if (
exemptLabels.some((exemptLabel: Readonly<string>): boolean =>
isLabeled(issue, exemptLabel)
)
) {
if (issue.isStale) {
issueLogger.info(`An exempt label was added after the stale label.`);
await this._removeStaleLabel(issue, staleLabel);
}
const hasExemptLabel = exemptLabels.some((exemptLabel: Readonly<string>) =>
isLabeled(issue, exemptLabel)
);

issueLogger.info(`Skipping this $$type because it has an exempt label`);
if (hasExemptLabel) {
issueLogger.info(
`Skipping this $$type because it contains an exempt label, see ${issueLogger.createOptionLink(
issue.isPullRequest ? Option.ExemptPrLabels : Option.ExemptIssueLabels
)} for more details`
);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process exempt issues
}
Expand Down Expand Up @@ -427,6 +426,7 @@ export class IssuesProcessor {
// Determine if this issue needs to be marked stale first
if (!issue.isStale) {
issueLogger.info(`This $$type is not stale`);

const shouldIgnoreUpdates: boolean = new IgnoreUpdates(
this.options,
issue
Expand Down