Skip to content

Commit

Permalink
feat(options): add new options to avoid stale based on comments
Browse files Browse the repository at this point in the history
Helping to close #441, #470, #435?
Closes #390 due to no activity

BREAKING CHANGES: the options related to remove-stale-when-updated will only check the updates, not the comment. It is only impactint the configurations using the value at false
  • Loading branch information
C0ZEN committed Jun 7, 2021
1 parent 5f6f311 commit 3502077
Show file tree
Hide file tree
Showing 18 changed files with 914 additions and 195 deletions.
119 changes: 70 additions & 49 deletions README.md

Large diffs are not rendered by default.

28 changes: 12 additions & 16 deletions __tests__/any-of-labels.spec.ts
Expand Up @@ -1112,29 +1112,25 @@ class IssuesProcessorBuilder {

issues(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
})
);

return this;
}

prs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
})
);

return this;
Expand Down
3 changes: 3 additions & 0 deletions __tests__/constants/default-processor-options.ts
Expand Up @@ -29,6 +29,9 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
removeStaleWhenUpdated: false,
removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined,
removeStaleWhenCommented: false,
removeIssueStaleWhenCommented: undefined,
removePrStaleWhenCommented: undefined,
ascending: false,
deleteBranch: false,
startDate: '',
Expand Down
12 changes: 5 additions & 7 deletions __tests__/functions/generate-issue.ts
Expand Up @@ -32,12 +32,10 @@ export function generateIssue(
title: milestone
}
: undefined,
assignees: assignees.map(
(assignee: Readonly<string>): IAssignee => {
return {
login: assignee
};
}
)
assignees: assignees.map((assignee: Readonly<string>): IAssignee => {
return {
login: assignee
};
})
});
}
39 changes: 34 additions & 5 deletions __tests__/main.spec.ts
Expand Up @@ -1220,7 +1220,7 @@ test('stale issues should not be closed if days is set to -1', async () => {
});

test('stale label should be removed if a comment was added to a stale issue', async () => {
const opts = {...DefaultProcessorOptions, removeStaleWhenUpdated: true};
const opts = {...DefaultProcessorOptions, removeStaleWhenCommented: true};
const TestIssueList: Issue[] = [
generateIssue(
opts,
Expand Down Expand Up @@ -1255,8 +1255,37 @@ test('stale label should be removed if a comment was added to a stale issue', as
expect(processor.removedLabelIssues).toHaveLength(1);
});

test('stale label should not be removed if a comment was added by the bot (and the issue should be closed)', async () => {
test('stale label should be removed if a stale issue was updated', async () => {
const opts = {...DefaultProcessorOptions, removeStaleWhenUpdated: true};
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue that should un-stale',
new Date().toDateString(),
'2020-01-01T17:00:00Z',
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => '2020-01-02T17:00:00Z'
);

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

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

test('stale label should not be removed if a comment was added by the bot (and the issue should be closed)', async () => {
const opts = {...DefaultProcessorOptions, removeStaleWhenCommented: true};
github.context.actor = 'abot';
const TestIssueList: Issue[] = [
generateIssue(
Expand Down Expand Up @@ -1295,7 +1324,7 @@ test('stale label should not be removed if a comment was added by the bot (and t
test('stale label containing a space should be removed if a comment was added to a stale issue', async () => {
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
removeStaleWhenUpdated: true,
removeStaleWhenCommented: true,
staleIssueLabel: 'stat: stale'
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -2234,7 +2263,7 @@ test('processing an issue stale since less than the daysBeforeStale with a stale
daysBeforeStale: 30,
daysBeforeClose: 7,
closeIssueMessage: 'close message',
removeStaleWhenUpdated: false
removeStaleWhenCommented: false
};
const now: Date = new Date();
const updatedAt: Date = new Date(now.setDate(now.getDate() - 9));
Expand Down Expand Up @@ -2276,7 +2305,7 @@ test('processing an issue stale since less than the daysBeforeStale without a st
daysBeforeStale: 30,
daysBeforeClose: 7,
closeIssueMessage: 'close message',
removeStaleWhenUpdated: false
removeStaleWhenCommented: false
};
const now: Date = new Date();
const updatedAt: Date = new Date(now.setDate(now.getDate() - 9));
Expand Down
28 changes: 12 additions & 16 deletions __tests__/only-labels.spec.ts
Expand Up @@ -1112,29 +1112,25 @@ class IssuesProcessorBuilder {

issues(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
})
);

return this;
}

prs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
})
);

return this;
Expand Down
22 changes: 10 additions & 12 deletions __tests__/operations-per-run.spec.ts
Expand Up @@ -188,18 +188,16 @@ class SUT {
}

private _setTestIssueList(): SUT {
this._testIssueList = this._sutIssues.map(
(sutIssue: SUTIssue): Issue => {
return generateIssue(
this._opts,
1,
'My first issue',
sutIssue.updatedAt,
sutIssue.updatedAt,
false
);
}
);
this._testIssueList = this._sutIssues.map((sutIssue: SUTIssue): Issue => {
return generateIssue(
this._opts,
1,
'My first issue',
sutIssue.updatedAt,
sutIssue.updatedAt,
false
);
});

return this;
}
Expand Down

0 comments on commit 3502077

Please sign in to comment.