2020-04-16 22:48:59 +08:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as github from '@actions/github';
|
|
|
|
import {Octokit} from '@octokit/rest';
|
|
|
|
|
2020-04-16 23:47:06 +08:00
|
|
|
import {
|
|
|
|
IssueProcessor,
|
|
|
|
Issue,
|
|
|
|
Label,
|
|
|
|
IssueProcessorOptions
|
|
|
|
} from '../src/IssueProcessor';
|
2020-04-16 22:48:59 +08:00
|
|
|
|
2020-04-16 23:47:06 +08:00
|
|
|
function generateIssue(
|
|
|
|
id: number,
|
|
|
|
title: string,
|
|
|
|
updatedAt: string,
|
2020-04-17 01:36:59 +08:00
|
|
|
isPullRequest: boolean = false,
|
|
|
|
labels: string[] = []
|
2020-04-16 23:47:06 +08:00
|
|
|
): Issue {
|
|
|
|
return {
|
|
|
|
number: id,
|
2020-04-17 01:36:59 +08:00
|
|
|
labels: labels.map(l => {
|
|
|
|
return {name: l};
|
|
|
|
}),
|
2020-04-16 23:47:06 +08:00
|
|
|
title: title,
|
|
|
|
updated_at: updatedAt,
|
|
|
|
pull_request: isPullRequest ? {} : null
|
|
|
|
};
|
|
|
|
}
|
2020-04-16 22:48:59 +08:00
|
|
|
|
2020-04-16 23:47:06 +08:00
|
|
|
const DefaultProcessorOptions: IssueProcessorOptions = {
|
|
|
|
repoToken: 'none',
|
|
|
|
staleIssueMessage: 'This issue is stale',
|
|
|
|
stalePrMessage: 'This PR is stale',
|
|
|
|
daysBeforeStale: 1,
|
|
|
|
daysBeforeClose: 1,
|
|
|
|
staleIssueLabel: 'Stale',
|
|
|
|
exemptIssueLabels: '',
|
|
|
|
stalePrLabel: 'Stale',
|
|
|
|
exemptPrLabels: '',
|
|
|
|
onlyLabels: '',
|
|
|
|
operationsPerRun: 100,
|
|
|
|
debugOnly: true
|
2020-04-16 22:48:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
test('empty issue list results in 1 operation', async () => {
|
2020-04-16 23:47:06 +08:00
|
|
|
const processor = new IssueProcessor(DefaultProcessorOptions, async () => []);
|
2020-04-16 22:48:59 +08:00
|
|
|
|
|
|
|
// process our fake issue list
|
2020-04-16 23:47:06 +08:00
|
|
|
const operationsLeft = await processor.processIssues(1);
|
2020-04-16 22:48:59 +08:00
|
|
|
|
|
|
|
// processing an empty issue list should result in 1 operation
|
|
|
|
expect(operationsLeft).toEqual(99);
|
2019-08-04 09:34:59 +08:00
|
|
|
});
|
2020-04-16 23:47:06 +08:00
|
|
|
|
2020-04-17 01:36:59 +08:00
|
|
|
test('processing an issue with no label will make it stale', async () => {
|
2020-04-16 23:47:06 +08:00
|
|
|
const TestIssueList: Issue[] = [
|
2020-04-17 01:36:59 +08:00
|
|
|
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z')
|
2020-04-16 23:47:06 +08:00
|
|
|
];
|
|
|
|
|
2020-04-17 01:51:24 +08:00
|
|
|
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
|
|
p == 1 ? TestIssueList : []
|
2020-04-16 23:47:06 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
// process our fake issue list
|
2020-04-17 01:36:59 +08:00
|
|
|
await processor.processIssues(1);
|
2020-04-16 23:47:06 +08:00
|
|
|
|
2020-04-17 01:36:59 +08:00
|
|
|
expect(processor.staleIssues.length).toEqual(1);
|
|
|
|
expect(processor.closedIssues.length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('processing a stale issue will close it', async () => {
|
|
|
|
const TestIssueList: Issue[] = [
|
|
|
|
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale'])
|
|
|
|
];
|
|
|
|
|
2020-04-17 01:51:24 +08:00
|
|
|
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
|
|
p == 1 ? TestIssueList : []
|
|
|
|
);
|
|
|
|
|
|
|
|
// process our fake issue list
|
|
|
|
await processor.processIssues(1);
|
|
|
|
|
|
|
|
expect(processor.staleIssues.length).toEqual(0);
|
|
|
|
expect(processor.closedIssues.length).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('processing a stale PR will close it', async () => {
|
|
|
|
const TestIssueList: Issue[] = [
|
|
|
|
generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, ['Stale'])
|
|
|
|
];
|
|
|
|
|
|
|
|
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
|
|
p == 1 ? TestIssueList : []
|
2020-04-17 01:36:59 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
// process our fake issue list
|
|
|
|
await processor.processIssues(1);
|
|
|
|
|
|
|
|
expect(processor.staleIssues.length).toEqual(0);
|
|
|
|
expect(processor.closedIssues.length).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('exempt issue labels will not be marked stale', async () => {
|
|
|
|
const TestIssueList: Issue[] = [
|
|
|
|
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [
|
|
|
|
'Exempt'
|
|
|
|
])
|
|
|
|
];
|
|
|
|
|
|
|
|
let opts = DefaultProcessorOptions;
|
|
|
|
opts.exemptIssueLabels = 'Exempt';
|
|
|
|
|
2020-04-17 01:51:24 +08:00
|
|
|
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
|
|
p == 1 ? TestIssueList : []
|
|
|
|
);
|
|
|
|
|
|
|
|
// process our fake issue list
|
|
|
|
await processor.processIssues(1);
|
|
|
|
|
|
|
|
expect(processor.staleIssues.length).toEqual(0);
|
|
|
|
expect(processor.closedIssues.length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('exempt issue labels will not be marked stale (multi issue label with spaces)', async () => {
|
|
|
|
const TestIssueList: Issue[] = [
|
|
|
|
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool'])
|
|
|
|
];
|
|
|
|
|
|
|
|
let opts = DefaultProcessorOptions;
|
|
|
|
opts.exemptIssueLabels = 'Exempt, Cool, None';
|
|
|
|
|
|
|
|
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
|
|
p == 1 ? TestIssueList : []
|
2020-04-17 01:36:59 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
// process our fake issue list
|
|
|
|
await processor.processIssues(1);
|
|
|
|
|
|
|
|
expect(processor.staleIssues.length).toEqual(0);
|
|
|
|
expect(processor.closedIssues.length).toEqual(0);
|
2020-04-16 23:47:06 +08:00
|
|
|
});
|
2020-04-17 01:51:24 +08:00
|
|
|
|
|
|
|
test('exempt issue labels will not be marked stale (multi issue label)', async () => {
|
|
|
|
const TestIssueList: Issue[] = [
|
|
|
|
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool'])
|
|
|
|
];
|
|
|
|
|
|
|
|
let opts = DefaultProcessorOptions;
|
|
|
|
opts.exemptIssueLabels = 'Exempt,Cool,None';
|
|
|
|
|
|
|
|
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
|
|
p == 1 ? TestIssueList : []
|
|
|
|
);
|
|
|
|
|
|
|
|
// process our fake issue list
|
|
|
|
await processor.processIssues(1);
|
|
|
|
|
|
|
|
expect(processor.staleIssues.length).toEqual(0);
|
|
|
|
expect(processor.closedIssues.length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('exempt pr labels will not be marked stale', async () => {
|
|
|
|
const TestIssueList: Issue[] = [
|
|
|
|
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool']),
|
|
|
|
generateIssue(2, 'My first PR', '2020-01-01T17:00:00Z', true, ['Cool']),
|
|
|
|
generateIssue(3, 'Another issue', '2020-01-01T17:00:00Z', false)
|
|
|
|
];
|
|
|
|
|
|
|
|
let opts = DefaultProcessorOptions;
|
|
|
|
opts.exemptIssueLabels = 'Cool';
|
|
|
|
|
|
|
|
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
|
|
p == 1 ? TestIssueList : []
|
|
|
|
);
|
|
|
|
|
|
|
|
// process our fake issue list
|
|
|
|
await processor.processIssues(1);
|
|
|
|
|
|
|
|
expect(processor.staleIssues.length).toEqual(2); // PR should get processed even though it has an exempt **issue** label
|
|
|
|
});
|