2021-01-19 11:54:16 +01:00
|
|
|
import deburr from 'lodash.deburr';
|
|
|
|
|
import {wordsToList} from '../functions/words-to-list';
|
2021-02-13 12:09:37 +01:00
|
|
|
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
|
2021-01-19 11:54:16 +01:00
|
|
|
import {Issue} from './issue';
|
|
|
|
|
|
|
|
|
|
type CleanMilestone = string;
|
|
|
|
|
|
|
|
|
|
export class Milestones {
|
|
|
|
|
private static _cleanMilestone(label: Readonly<string>): CleanMilestone {
|
|
|
|
|
return deburr(label.toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-13 12:09:37 +01:00
|
|
|
private readonly _options: IIssuesProcessorOptions;
|
2021-01-19 11:54:16 +01:00
|
|
|
private readonly _issue: Issue;
|
|
|
|
|
|
2021-02-13 12:09:37 +01:00
|
|
|
constructor(options: Readonly<IIssuesProcessorOptions>, issue: Issue) {
|
2021-01-19 11:54:16 +01:00
|
|
|
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)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|