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

@@ -0,0 +1,36 @@
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
repoToken: 'none',
staleIssueMessage: 'This issue is stale',
stalePrMessage: 'This PR is stale',
closeIssueMessage: 'This issue is being closed',
closePrMessage: 'This PR is being closed',
daysBeforeStale: 1,
daysBeforeIssueStale: NaN,
daysBeforePrStale: NaN,
daysBeforeClose: 30,
daysBeforeIssueClose: NaN,
daysBeforePrClose: NaN,
staleIssueLabel: 'Stale',
closeIssueLabel: '',
exemptIssueLabels: '',
stalePrLabel: 'Stale',
closePrLabel: '',
exemptPrLabels: '',
onlyLabels: '',
operationsPerRun: 100,
debugOnly: true,
removeStaleWhenUpdated: false,
ascending: false,
skipStaleIssueMessage: false,
skipStalePrMessage: false,
deleteBranch: false,
startDate: '',
exemptMilestones: '',
exemptIssueMilestones: '',
exemptPrMilestones: '',
exemptAllMilestones: false,
exemptAllIssueMilestones: undefined,
exemptAllPrMilestones: undefined
});

View File

@@ -0,0 +1,34 @@
import {Issue} from '../../src/classes/issue';
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
import {IsoDateString} from '../../src/types/iso-date-string';
export function generateIssue(
options: IIssuesProcessorOptions,
id: number,
title: string,
updatedAt: IsoDateString,
createdAt: IsoDateString = updatedAt,
isPullRequest = false,
labels: string[] = [],
isClosed = false,
isLocked = false,
milestone: string | undefined = undefined
): Issue {
return new Issue(options, {
number: id,
labels: labels.map(l => {
return {name: l};
}),
title,
created_at: createdAt,
updated_at: updatedAt,
pull_request: isPullRequest ? {} : null,
state: isClosed ? 'closed' : 'open',
locked: isLocked,
milestone: milestone
? {
title: milestone
}
: undefined
});
}

View File

@@ -1,70 +1,9 @@
import * as github from '@actions/github';
import {Issue} from '../src/classes/issue';
import {IssuesProcessor} from '../src/classes/issues-processor';
import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options';
import {IsoDateString} from '../src/types/iso-date-string';
function generateIssue(
options: IIssuesProcessorOptions,
id: number,
title: string,
updatedAt: IsoDateString,
createdAt: IsoDateString = updatedAt,
isPullRequest = false,
labels: string[] = [],
isClosed = false,
isLocked = false,
milestone = ''
): Issue {
return new Issue(options, {
number: id,
labels: labels.map(l => {
return {name: l};
}),
title,
created_at: createdAt,
updated_at: updatedAt,
pull_request: isPullRequest ? {} : null,
state: isClosed ? 'closed' : 'open',
locked: isLocked,
milestone: {
title: milestone
}
});
}
const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
repoToken: 'none',
staleIssueMessage: 'This issue is stale',
stalePrMessage: 'This PR is stale',
closeIssueMessage: 'This issue is being closed',
closePrMessage: 'This PR is being closed',
daysBeforeStale: 1,
daysBeforeIssueStale: NaN,
daysBeforePrStale: NaN,
daysBeforeClose: 30,
daysBeforeIssueClose: NaN,
daysBeforePrClose: NaN,
staleIssueLabel: 'Stale',
closeIssueLabel: '',
exemptIssueLabels: '',
stalePrLabel: 'Stale',
closePrLabel: '',
exemptPrLabels: '',
onlyLabels: '',
operationsPerRun: 100,
debugOnly: true,
removeStaleWhenUpdated: false,
ascending: false,
skipStaleIssueMessage: false,
skipStalePrMessage: false,
deleteBranch: false,
startDate: '',
exemptMilestones: '',
exemptIssueMilestones: '',
exemptPrMilestones: ''
});
import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue';
test('empty issue list results in 1 operation', async () => {
const processor = new IssuesProcessor(
@@ -1991,279 +1930,6 @@ test('an issue with an exempted milestone and with an exempted issue milestone w
expect(processor.removedLabelIssues.length).toStrictEqual(0);
});
test('a PR without a milestone will be marked as stale', async () => {
expect.assertions(3);
const TestIssueList: Issue[] = [
generateIssue(
DefaultProcessorOptions,
1,
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
true,
undefined,
undefined,
undefined,
''
)
];
const processor = new IssuesProcessor(
DefaultProcessorOptions,
async () => 'abot',
async p => (p == 1 ? TestIssueList : []),
async (num: number, dt: string) => [],
async (issue: Issue, label: string) => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toStrictEqual(1);
expect(processor.closedIssues.length).toStrictEqual(0);
expect(processor.removedLabelIssues.length).toStrictEqual(0);
});
test('a PR without an exempted milestone will be marked as stale', async () => {
expect.assertions(3);
const opts = {...DefaultProcessorOptions};
opts.exemptMilestones = 'Milestone1';
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
true,
undefined,
undefined,
undefined,
'Milestone'
)
];
const processor = new IssuesProcessor(
opts,
async () => 'abot',
async p => (p == 1 ? TestIssueList : []),
async (num: number, dt: string) => [],
async (issue: Issue, label: string) => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toStrictEqual(1);
expect(processor.closedIssues.length).toStrictEqual(0);
expect(processor.removedLabelIssues.length).toStrictEqual(0);
});
test('a PR with an exempted milestone will not be marked as stale', async () => {
expect.assertions(3);
const opts = {...DefaultProcessorOptions};
opts.exemptMilestones = 'Milestone1';
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
true,
undefined,
undefined,
undefined,
'Milestone1'
)
];
const processor = new IssuesProcessor(
opts,
async () => 'abot',
async p => (p == 1 ? TestIssueList : []),
async (num: number, dt: string) => [],
async (issue: Issue, label: string) => 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(0);
});
test('a PR with an exempted milestone will not be marked as stale (multi milestones with spaces)', async () => {
expect.assertions(3);
const opts = {...DefaultProcessorOptions};
opts.exemptMilestones = 'Milestone1, Milestone2';
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
true,
undefined,
undefined,
undefined,
'Milestone2'
)
];
const processor = new IssuesProcessor(
opts,
async () => 'abot',
async p => (p == 1 ? TestIssueList : []),
async (num: number, dt: string) => [],
async (issue: Issue, label: string) => 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(0);
});
test('a PR with an exempted milestone will not be marked as stale (multi milestones without spaces)', async () => {
expect.assertions(3);
const opts = {...DefaultProcessorOptions};
opts.exemptMilestones = 'Milestone1,Milestone2';
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
true,
undefined,
undefined,
undefined,
'Milestone2'
)
];
const processor = new IssuesProcessor(
opts,
async () => 'abot',
async p => (p == 1 ? TestIssueList : []),
async (num: number, dt: string) => [],
async (issue: Issue, label: string) => 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(0);
});
test('a PR with an exempted milestone but without an exempted issue milestone will not be marked as stale', async () => {
expect.assertions(3);
const opts = {...DefaultProcessorOptions};
opts.exemptMilestones = 'Milestone1';
opts.exemptPrMilestones = '';
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
true,
undefined,
undefined,
undefined,
'Milestone1'
)
];
const processor = new IssuesProcessor(
opts,
async () => 'abot',
async p => (p == 1 ? TestIssueList : []),
async (num: number, dt: string) => [],
async (issue: Issue, label: string) => 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(0);
});
test('a PR with an exempted milestone but with another exempted issue milestone will be marked as stale', async () => {
expect.assertions(3);
const opts = {...DefaultProcessorOptions};
opts.exemptMilestones = 'Milestone1';
opts.exemptPrMilestones = 'Milestone2';
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
true,
undefined,
undefined,
undefined,
'Milestone1'
)
];
const processor = new IssuesProcessor(
opts,
async () => 'abot',
async p => (p == 1 ? TestIssueList : []),
async (num: number, dt: string) => [],
async (issue: Issue, label: string) => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toStrictEqual(1);
expect(processor.closedIssues.length).toStrictEqual(0);
expect(processor.removedLabelIssues.length).toStrictEqual(0);
});
test('a PR with an exempted milestone and with an exempted issue milestone will not be marked as stale', async () => {
expect.assertions(3);
const opts = {...DefaultProcessorOptions};
opts.exemptMilestones = 'Milestone1';
opts.exemptPrMilestones = 'Milestone1';
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
true,
undefined,
undefined,
undefined,
'Milestone1'
)
];
const processor = new IssuesProcessor(
opts,
async () => 'abot',
async p => (p == 1 ? TestIssueList : []),
async (num: number, dt: string) => [],
async (issue: Issue, label: string) => 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(0);
});
test('processing an issue opened since 2 days and with the option "daysBeforeIssueStale" at 3 will not make it stale', async () => {
expect.assertions(2);
const opts: IIssuesProcessorOptions = {

3413
__tests__/milestones.spec.ts Normal file

File diff suppressed because it is too large Load Diff