Prevent processing of locked/closed issues/PRs (#52)

Fixes #50
Fixes #51
This commit is contained in:
James M. Greene 2020-04-27 06:53:58 -05:00 коммит произвёл GitHub
Родитель a23bda33c4
Коммит ae2c5c5308
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 146 добавлений и 2 удалений

Просмотреть файл

@ -14,7 +14,9 @@ function generateIssue(
title: string,
updatedAt: string,
isPullRequest: boolean = false,
labels: string[] = []
labels: string[] = [],
isClosed: boolean = false,
isLocked: boolean = false
): Issue {
return {
number: id,
@ -23,7 +25,9 @@ function generateIssue(
}),
title: title,
updated_at: updatedAt,
pull_request: isPullRequest ? {} : null
pull_request: isPullRequest ? {} : null,
state: isClosed ? 'closed' : 'open',
locked: isLocked
};
}
@ -100,6 +104,134 @@ test('processing a stale PR will close it', async () => {
expect(processor.closedIssues.length).toEqual(1);
});
test('closed issues will not be marked stale', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [], true)
];
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('stale closed issues will not be closed', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale'], true)
];
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('closed prs will not be marked stale', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, [], true)
];
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('stale closed prs will not be closed', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, ['Stale'], true)
];
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('locked issues will not be marked stale', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [], false, true)
];
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('stale locked issues will not be closed', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale'], false, true)
];
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('locked prs will not be marked stale', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, [], false, true)
];
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('stale locked prs will not be closed', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, ['Stale'], false, true)
];
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', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [

Просмотреть файл

@ -10,6 +10,8 @@ export interface Issue {
updated_at: string;
labels: Label[];
pull_request: any;
state: string;
locked: boolean;
}
export interface Label {
@ -100,6 +102,16 @@ export class IssueProcessor {
continue;
}
if (issue.state === 'closed') {
core.debug(`Skipping ${issueType} because it is closed`);
continue; // don't process closed issues
}
if (issue.locked) {
core.debug(`Skipping ${issueType} because it is locked`);
continue; // don't process locked issues
}
if (
exemptLabels.some((exemptLabel: string) =>
IssueProcessor.isLabeled(issue, exemptLabel)