mirror of
https://github.com/actions/stale.git
synced 2025-12-18 17:56:46 +00:00
Move processor to use its own types so testing is easier
This commit is contained in:
@@ -2,60 +2,66 @@ import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
import {Octokit} from '@octokit/rest';
|
||||
|
||||
import {IssueProcessor, IssueProcessorOptions} from '../src/IssueProcessor';
|
||||
import {
|
||||
IssueProcessor,
|
||||
Issue,
|
||||
Label,
|
||||
IssueProcessorOptions
|
||||
} from '../src/IssueProcessor';
|
||||
|
||||
type Issue = Octokit.IssuesListForRepoResponseItem;
|
||||
type IssueLabel = Octokit.IssuesListForRepoResponseItemLabelsItem;
|
||||
type IssueList = Octokit.Response<Octokit.IssuesListForRepoResponse>;
|
||||
function generateIssue(
|
||||
id: number,
|
||||
title: string,
|
||||
updatedAt: string,
|
||||
isPullRequest: boolean = false
|
||||
): Issue {
|
||||
return {
|
||||
number: id,
|
||||
labels: [],
|
||||
title: title,
|
||||
updated_at: updatedAt,
|
||||
pull_request: isPullRequest ? {} : null
|
||||
};
|
||||
}
|
||||
|
||||
const FakeHeaders = {
|
||||
date: 'none',
|
||||
'x-ratelimit-limit': '',
|
||||
'x-ratelimit-remaining': '',
|
||||
'x-ratelimit-reset': '',
|
||||
'x-Octokit-request-id': '',
|
||||
'x-Octokit-media-type': '',
|
||||
link: '',
|
||||
'last-modified': '',
|
||||
etag: '',
|
||||
status: ''
|
||||
};
|
||||
|
||||
const EmptyIssueList: IssueList = {
|
||||
data: [],
|
||||
status: 200,
|
||||
headers: FakeHeaders,
|
||||
|
||||
*[Symbol.iterator]() {
|
||||
for (let i of this.data) {
|
||||
yield i;
|
||||
}
|
||||
}
|
||||
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
|
||||
};
|
||||
|
||||
test('empty issue list results in 1 operation', async () => {
|
||||
const options: 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
|
||||
};
|
||||
const processor = new IssueProcessor(options);
|
||||
const processor = new IssueProcessor(DefaultProcessorOptions, async () => []);
|
||||
|
||||
// process our fake issue list
|
||||
const operationsLeft = await processor.processIssues(
|
||||
1,
|
||||
() => new Promise<IssueList>(resolve => resolve(EmptyIssueList))
|
||||
);
|
||||
const operationsLeft = await processor.processIssues(1);
|
||||
|
||||
// processing an empty issue list should result in 1 operation
|
||||
expect(operationsLeft).toEqual(99);
|
||||
});
|
||||
|
||||
test('processing an issue with no label will not make it stale', async () => {
|
||||
const TestIssueList: Issue[] = [
|
||||
generateIssue(1, 'My first issue', Date.now().toString())
|
||||
];
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => TestIssueList
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
const operationsLeft = await processor.processIssues(1);
|
||||
|
||||
// processing an empty issue list should result in 1 operation
|
||||
expect(operationsLeft).toBeLessThan(100);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user