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 committed by GitHub
parent a23bda33c4
commit ae2c5c5308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 146 additions and 2 deletions

View File

@ -14,7 +14,9 @@ function generateIssue(
title: string, title: string,
updatedAt: string, updatedAt: string,
isPullRequest: boolean = false, isPullRequest: boolean = false,
labels: string[] = [] labels: string[] = [],
isClosed: boolean = false,
isLocked: boolean = false
): Issue { ): Issue {
return { return {
number: id, number: id,
@ -23,7 +25,9 @@ function generateIssue(
}), }),
title: title, title: title,
updated_at: updatedAt, 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); 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 () => { test('exempt issue labels will not be marked stale', async () => {
const TestIssueList: Issue[] = [ const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [ generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [

View File

@ -10,6 +10,8 @@ export interface Issue {
updated_at: string; updated_at: string;
labels: Label[]; labels: Label[];
pull_request: any; pull_request: any;
state: string;
locked: boolean;
} }
export interface Label { export interface Label {
@ -100,6 +102,16 @@ export class IssueProcessor {
continue; 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 ( if (
exemptLabels.some((exemptLabel: string) => exemptLabels.some((exemptLabel: string) =>
IssueProcessor.isLabeled(issue, exemptLabel) IssueProcessor.isLabeled(issue, exemptLabel)