Skip to content

Commit

Permalink
Prevent processing of locked/closed issues/PRs (#52)
Browse files Browse the repository at this point in the history
Fixes #50
Fixes #51
  • Loading branch information
JamesMGreene authored Apr 27, 2020
1 parent a23bda3 commit ae2c5c5
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 2 deletions.
136 changes: 134 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
};
}

Expand Down Expand Up @@ -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, [
Expand Down
12 changes: 12 additions & 0 deletions src/IssueProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface Issue {
updated_at: string;
labels: Label[];
pull_request: any;
state: string;
locked: boolean;
}

export interface Label {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ae2c5c5

Please sign in to comment.