Skip to content

Commit

Permalink
feat(remove-stale-when-updated): split remote-stale-when-updated opti…
Browse files Browse the repository at this point in the history
…on into remote-stale-when-updated and remote-stale-when-commented
  • Loading branch information
francoiscampbell committed Mar 28, 2021
1 parent b717aa9 commit dccf347
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Every argument is optional.
| `only-pr-labels` | Only PRs with ALL these labels are checked.<br>Separate multiple labels with commas (eg. "question,answered").<br>_Override `only-labels`_. |
| `any-of-labels` | Only issues and PRs with ANY of these labels are checked.<br>Separate multiple labels with commas (eg. "incomplete,waiting-feedback"). |
| `operations-per-run` | Maximum number of operations per run.<br>GitHub API CRUD related.<br>_Defaults to **30**_. |
| `remove-stale-when-updated` | Remove stale label from issue/PR on updates or comments.<br>_Defaults to **true**_. |
| `remove-stale-when-commented` | Remove stale label from issue/PR on comments.<br>_Defaults to **true**_. |
| `remove-stale-when-updated` | Remove stale label from issue/PR on any update, including comments.<br>_Defaults to **true**_. |
| `debug-only` | Dry-run on action.<br>_Defaults to **false**_. |
| `ascending` | Order to get issues/PR.<br>`true` is ascending, `false` is descending.<br>_Defaults to **false**_. |
| `skip-stale-issue-message` | Skip adding stale message on stale issue.<br>_Defaults to **false**_. |
Expand Down
1 change: 1 addition & 0 deletions __tests__/constants/default-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
anyOfLabels: '',
operationsPerRun: 100,
debugOnly: true,
removeStaleWhenCommented: false,
removeStaleWhenUpdated: false,
ascending: false,
skipStaleIssueMessage: false,
Expand Down
44 changes: 39 additions & 5 deletions __tests__/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,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};
opts.removeStaleWhenUpdated = true;
opts.removeStaleWhenCommented = true;
const TestIssueList: Issue[] = [
generateIssue(
opts,
Expand Down Expand Up @@ -1256,9 +1256,43 @@ test('stale label should be removed if a comment was added to a stale issue', as
expect(processor.removedLabelIssues.length).toEqual(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};
opts.removeStaleWhenUpdated = true;

const issueCreatedAt = '2020-01-01T17:00:00Z';
const staleLabelDate = '2020-01-02T17:00:00Z';
const issueUpdatedAt = new Date().toDateString();
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue that should un-stale',
issueUpdatedAt,
issueCreatedAt,
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => staleLabelDate
);

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

expect(processor.closedIssues.length).toEqual(0);
expect(processor.staleIssues.length).toEqual(0);
expect(processor.removedLabelIssues.length).toEqual(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};
opts.removeStaleWhenCommented = true;
github.context.actor = 'abot';
const TestIssueList: Issue[] = [
generateIssue(
Expand Down Expand Up @@ -1297,7 +1331,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 @@ -2214,7 +2248,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 @@ -2256,7 +2290,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
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ class IssuesProcessor {
const issueHasUpdate = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose);
issueLogger.info(`$$type has been updated: ${issueHasUpdate}`);
// should we un-stale this issue?
if (this.options.removeStaleWhenUpdated && issueHasComments) {
if ((this.options.removeStaleWhenCommented && issueHasComments) ||
(this.options.removeStaleWhenUpdated && issueHasUpdate)) {
yield this._removeStaleLabel(issue, staleLabel);
}
// now start closing logic
Expand Down Expand Up @@ -1547,6 +1548,7 @@ function _getAndValidateArgs() {
onlyPrLabels: core.getInput('only-pr-labels'),
anyOfLabels: core.getInput('any-of-labels'),
operationsPerRun: parseInt(core.getInput('operations-per-run', { required: true })),
removeStaleWhenCommented: !(core.getInput('remove-stale-when-commented') === 'false'),
removeStaleWhenUpdated: !(core.getInput('remove-stale-when-updated') === 'false'),
debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true',
Expand Down
1 change: 1 addition & 0 deletions src/classes/issue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Issue', (): void => {
onlyPrLabels: '',
anyOfLabels: '',
operationsPerRun: 0,
removeStaleWhenCommented: false,
removeStaleWhenUpdated: false,
repoToken: '',
skipStaleIssueMessage: false,
Expand Down
5 changes: 4 additions & 1 deletion src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ export class IssuesProcessor {
issueLogger.info(`$$type has been updated: ${issueHasUpdate}`);

// should we un-stale this issue?
if (this.options.removeStaleWhenUpdated && issueHasComments) {
if (
(this.options.removeStaleWhenCommented && issueHasComments) ||
(this.options.removeStaleWhenUpdated && issueHasUpdate)
) {
await this._removeStaleLabel(issue, staleLabel);
}

Expand Down
1 change: 1 addition & 0 deletions src/interfaces/issues-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IIssuesProcessorOptions {
onlyPrLabels: string;
anyOfLabels: string;
operationsPerRun: number;
removeStaleWhenCommented: boolean;
removeStaleWhenUpdated: boolean;
debugOnly: boolean;
ascending: boolean;
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
operationsPerRun: parseInt(
core.getInput('operations-per-run', {required: true})
),
removeStaleWhenCommented: !(
core.getInput('remove-stale-when-commented') === 'false'
),
removeStaleWhenUpdated: !(
core.getInput('remove-stale-when-updated') === 'false'
),
Expand Down

0 comments on commit dccf347

Please sign in to comment.