Skip to content

Commit

Permalink
feat(label): remove the stale label when labeled with an exempt one
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed Jan 16, 2021
1 parent 0e4efa3 commit b0083fa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
33 changes: 31 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ test('stale locked prs will not be closed', async () => {
});

test('exempt issue labels will not be marked stale', async () => {
expect.assertions(3);
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [
'Exempt'
Expand All @@ -819,6 +820,34 @@ test('exempt issue labels will not be marked stale', async () => {

expect(processor.staleIssues.length).toEqual(0);
expect(processor.closedIssues.length).toEqual(0);
expect(processor.removedLabelIssues.length).toEqual(0);
});

test('exempt issue labels will not be marked stale and will remove the existing stale label', async () => {
expect.assertions(3);
const opts = {...DefaultProcessorOptions};
opts.exemptIssueLabels = 'Exempt';

const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [
opts.exemptIssueLabels, opts.staleIssueLabel
])
];

const processor = new IssueProcessor(
opts,
async () => 'abot',
async p => (p == 1 ? TestIssueList : []),
async (num: number, dt: string) => [],
async (issue: Issue, label: string) => new Date().toDateString()
);

// process our fake issue list
await processor.processIssues(1);

expect(processor.staleIssues.length).toEqual(0);
expect(processor.closedIssues.length).toEqual(0);
expect(processor.removedLabelIssues.length).toEqual(1);
});

test('exempt issue labels will not be marked stale (multi issue label with spaces)', async () => {
Expand Down Expand Up @@ -1150,7 +1179,7 @@ test('skips stale message on issues when skip-stale-issue-message is set', async
);

// for sake of testing, mocking private function
const markSpy = jest.spyOn(processor as any, 'markStale');
const markSpy = jest.spyOn(processor as any, '_markStale');

await processor.processIssues(1);

Expand Down Expand Up @@ -1195,7 +1224,7 @@ test('skips stale message on prs when skip-stale-pr-message is set', async () =>
);

// for sake of testing, mocking private function
const markSpy = jest.spyOn(processor as any, 'markStale');
const markSpy = jest.spyOn(processor as any, '_markStale');

await processor.processIssues(1);

Expand Down
27 changes: 15 additions & 12 deletions src/IssueProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,7 @@ export class IssueProcessor {
continue; // don't process locked issues
}

if (
exemptLabels.some((exemptLabel: string) =>
isLabeled(issue, exemptLabel)
)
) {
issueLogger.info(
`Skipping ${issueType} because it has an exempt label`
);
continue; // don't process exempt issues
}

// does this issue have a stale label?
// Does this issue have a stale label?
let isStale: boolean = isLabeled(issue, staleLabel);

if (isStale) {
Expand All @@ -224,6 +213,20 @@ export class IssueProcessor {
issueLogger.info(`This issue hasn't a stale label`);
}

if (
exemptLabels.some((exemptLabel: Readonly<string>): boolean =>
isLabeled(issue, exemptLabel)
)
) {
if (isStale) {
core.info(`An exempt label was added after the stale label.`);
await this._removeStaleLabel(issue, staleLabel);
}

core.info(`Skipping ${issueType} because it has an exempt label`);
continue; // don't process exempt issues
}

// should this issue be marked stale?
const shouldBeStale = !IssueProcessor._updatedSince(
issue.updated_at,
Expand Down

0 comments on commit b0083fa

Please sign in to comment.