feat(milestones): add new options to exempt all milestones (#291)

* refactor: move and rename the interfaces/classes

closes #272

* docs: update the readme and action to describe the new options for milestones

* refactor: split the tests into multiple files

* feat(milestones): add new options to exempt all milestones

* test: add coverage for the default values

* test(milestones): add more coverage (wip)

* test(milestones): add more coverage for the multiple exempt milestones

* test: reduce duplicated code

* test: change some describes

* test: add more coverage

* test: add more coverage

* test: add final coverage

* build(tsc): add missing project flag to build with the right tsconfig

* test(milestones): use each to reduce the complexity of the tests

* chore: fix an eslint issue with prettier on windows

the end of line was wrong each time the os process the files

* docs: move the contribution section to a dedicated file

add more content to help the debug

* chore: make sure the rebase is ok
This commit is contained in:
Geoffrey Testelin
2021-02-16 12:18:48 +01:00
committed by GitHub
parent 07f3f88b6d
commit 6a493760cf
20 changed files with 3728 additions and 420 deletions

View File

@@ -39,7 +39,10 @@ describe('Issue', (): void => {
stalePrMessage: '',
startDate: undefined,
stalePrLabel: 'dummy-stale-pr-label',
staleIssueLabel: 'dummy-stale-issue-label'
staleIssueLabel: 'dummy-stale-issue-label',
exemptAllMilestones: false,
exemptAllIssueMilestones: undefined,
exemptAllPrMilestones: undefined
};
issueInterface = {
title: 'dummy-title',

View File

@@ -39,7 +39,10 @@ describe('Milestones', (): void => {
startDate: undefined,
exemptIssueMilestones: '',
exemptPrMilestones: '',
exemptMilestones: ''
exemptMilestones: '',
exemptAllMilestones: false,
exemptAllIssueMilestones: undefined,
exemptAllPrMilestones: undefined
};
issueInterface = {
created_at: '',

View File

@@ -19,6 +19,10 @@ export class Milestones {
}
shouldExemptMilestones(): boolean {
if (this._shouldExemptAllMilestones()) {
return true;
}
const exemptMilestones: string[] = this._getExemptMilestones();
return exemptMilestones.some((exemptMilestone: Readonly<string>): boolean =>
@@ -56,4 +60,34 @@ export class Milestones {
Milestones._cleanMilestone(this._issue.milestone.title)
);
}
private _shouldExemptAllMilestones(): boolean {
if (this._issue.milestone) {
return this._issue.isPullRequest
? this._shouldExemptAllPullRequestMilestones()
: this._shouldExemptAllIssueMilestones();
}
return false;
}
private _shouldExemptAllIssueMilestones(): boolean {
if (this._options.exemptAllIssueMilestones === true) {
return true;
} else if (this._options.exemptAllIssueMilestones === false) {
return false;
}
return this._options.exemptAllMilestones;
}
private _shouldExemptAllPullRequestMilestones(): boolean {
if (this._options.exemptAllPrMilestones === true) {
return true;
} else if (this._options.exemptAllPrMilestones === false) {
return false;
}
return this._options.exemptAllMilestones;
}
}

View File

@@ -30,4 +30,7 @@ export interface IIssuesProcessorOptions {
exemptMilestones: string;
exemptIssueMilestones: string;
exemptPrMilestones: string;
exemptAllMilestones: boolean;
exemptAllIssueMilestones: boolean | undefined;
exemptAllPrMilestones: boolean | undefined;
}

View File

@@ -3,9 +3,9 @@ import {isValidDate} from './functions/dates/is-valid-date';
import {IssuesProcessor} from './classes/issues-processor';
import {IIssuesProcessorOptions} from './interfaces/issues-processor-options';
async function run(): Promise<void> {
async function _run(): Promise<void> {
try {
const args = getAndValidateArgs();
const args = _getAndValidateArgs();
const processor: IssuesProcessor = new IssuesProcessor(args);
await processor.processIssues();
@@ -15,7 +15,7 @@ async function run(): Promise<void> {
}
}
function getAndValidateArgs(): IIssuesProcessorOptions {
function _getAndValidateArgs(): IIssuesProcessorOptions {
const args: IIssuesProcessorOptions = {
repoToken: core.getInput('repo-token'),
staleIssueMessage: core.getInput('stale-issue-message'),
@@ -56,7 +56,10 @@ function getAndValidateArgs(): IIssuesProcessorOptions {
: undefined,
exemptMilestones: core.getInput('exempt-milestones'),
exemptIssueMilestones: core.getInput('exempt-issue-milestones'),
exemptPrMilestones: core.getInput('exempt-pr-milestones')
exemptPrMilestones: core.getInput('exempt-pr-milestones'),
exemptAllMilestones: core.getInput('exempt-all-milestones') === 'true',
exemptAllIssueMilestones: _toOptionalBoolean('exempt-all-issue-milestones'),
exemptAllPrMilestones: _toOptionalBoolean('exempt-all-pr-milestones')
};
for (const numberInput of [
@@ -83,4 +86,18 @@ function getAndValidateArgs(): IIssuesProcessorOptions {
return args;
}
run();
function _toOptionalBoolean(
argumentName: Readonly<string>
): boolean | undefined {
const argument: string = core.getInput(argumentName);
if (argument === 'true') {
return true;
} else if (argument === 'false') {
return false;
}
return undefined;
}
_run();