mirror of
https://github.com/actions/stale.git
synced 2026-01-01 12:58:18 +00:00
* feat(exempt): add new options to exempt the milestones closes #270 * test(milestones): add coverage * test(issue): add coverage * chore(rebase): fix all errors due to the rebase also made some changes regarding the change I made with the lint scripts and prettier. I did not saw that some scripts were already here and I created to more to keep the old ones as well * test(milestone): add coverage * chore(index): update index * fix(checks): remove checks over optional number options the code was actually handling the case where the values are NaN so it's fine
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import deburr from 'lodash.deburr';
|
|
import {wordsToList} from '../functions/words-to-list';
|
|
import {IssueProcessorOptions} from '../IssueProcessor';
|
|
import {Issue} from './issue';
|
|
|
|
type CleanMilestone = string;
|
|
|
|
export class Milestones {
|
|
private static _cleanMilestone(label: Readonly<string>): CleanMilestone {
|
|
return deburr(label.toLowerCase());
|
|
}
|
|
|
|
private readonly _options: IssueProcessorOptions;
|
|
private readonly _issue: Issue;
|
|
|
|
constructor(options: Readonly<IssueProcessorOptions>, issue: Issue) {
|
|
this._options = options;
|
|
this._issue = issue;
|
|
}
|
|
|
|
shouldExemptMilestones(): boolean {
|
|
const exemptMilestones: string[] = this._getExemptMilestones();
|
|
|
|
return exemptMilestones.some((exemptMilestone: Readonly<string>): boolean =>
|
|
this._hasMilestone(exemptMilestone)
|
|
);
|
|
}
|
|
|
|
private _getExemptMilestones(): string[] {
|
|
return wordsToList(
|
|
this._issue.isPullRequest
|
|
? this._getExemptPullRequestMilestones()
|
|
: this._getExemptIssueMilestones()
|
|
);
|
|
}
|
|
|
|
private _getExemptIssueMilestones(): string {
|
|
return this._options.exemptIssueMilestones !== ''
|
|
? this._options.exemptIssueMilestones
|
|
: this._options.exemptMilestones;
|
|
}
|
|
|
|
private _getExemptPullRequestMilestones(): string {
|
|
return this._options.exemptPrMilestones !== ''
|
|
? this._options.exemptPrMilestones
|
|
: this._options.exemptMilestones;
|
|
}
|
|
|
|
private _hasMilestone(milestone: Readonly<string>): boolean {
|
|
if (!this._issue.milestone) {
|
|
return false;
|
|
}
|
|
|
|
return (
|
|
Milestones._cleanMilestone(milestone) ===
|
|
Milestones._cleanMilestone(this._issue.milestone.title)
|
|
);
|
|
}
|
|
}
|