diff --git a/README.md b/README.md index 67da8251c..ef500f5d1 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,8 @@ Every argument is optional. | [any-of-issue-labels](#any-of-issue-labels) | Only issues with ANY of these labels are checked | | | [any-of-pr-labels](#any-of-pr-labels) | Only PRs with ANY of these labels are checked | | | [operations-per-run](#operations-per-run) | Max number of operations per run | `30` | -| [remove-stale-when-updated](#remove-stale-when-updated) | Remove stale label from issues/PRs on updates | `true` | -| [remove-issue-stale-when-updated](#remove-issue-stale-when-updated) | Remove stale label from issues on updates/comments | | -| [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | | +| [remove-issue-stale-when-updated](#remove-issue-stale-when-updated) | Remove stale label from issues on updates/comments | `true` | +| [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | `true` | | [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | | | [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | | | [debug-only](#debug-only) | Dry-run | `false` | @@ -315,25 +314,19 @@ Only the [actor](#repo-token) and the batch of issues (100 per batch) will consu Default value: `30` -#### remove-stale-when-updated - -Automatically remove the stale label when the issues or the pull requests are updated (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) or commented. - -Default value: `true` -Required Permission: `issues: write` and `pull-requests: write` - #### remove-issue-stale-when-updated -Override [remove-stale-when-updated](#remove-stale-when-updated) but only to automatically remove the stale label when the issues are updated (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) or commented. +Automatically remove the stale label when the issues are updated (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) or commented. -Default value: unset +Default value: `true` Required Permission: `issues: write` #### remove-pr-stale-when-updated -Override [remove-stale-when-updated](#remove-stale-when-updated) but only to automatically remove the stale label when the pull requests are updated (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) or commented. +Automatically remove the stale label when the pull requests are updated (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) or commented. -Default value: unset +Default value: `true` +Required Permission: `pull-requests: write` #### labels-to-add-when-unstale diff --git a/__tests__/constants/default-processor-options.ts b/__tests__/constants/default-processor-options.ts index 8cfc06706..3286bd4e3 100644 --- a/__tests__/constants/default-processor-options.ts +++ b/__tests__/constants/default-processor-options.ts @@ -24,9 +24,8 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({ anyOfPrLabels: '', operationsPerRun: 100, debugOnly: true, - removeStaleWhenUpdated: false, - removeIssueStaleWhenUpdated: undefined, - removePrStaleWhenUpdated: undefined, + removeIssueStaleWhenUpdated: false, + removePrStaleWhenUpdated: false, ascending: false, deleteBranch: false, startDate: '', diff --git a/__tests__/main.spec.ts b/__tests__/main.spec.ts index 59f8418c4..9cec6b51e 100644 --- a/__tests__/main.spec.ts +++ b/__tests__/main.spec.ts @@ -598,9 +598,10 @@ test('processing a stale PR will close it when days-before-pr-stale override day }); test('processing a stale issue will close it even if configured not to mark as stale', async () => { - const opts = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, - daysBeforeStale: -1, + daysBeforeIssueStale: -1, + daysBeforePrStale: -1, staleIssueMessage: '' }; const TestIssueList: Issue[] = [ @@ -629,10 +630,10 @@ test('processing a stale issue will close it even if configured not to mark as s }); test('processing a stale issue will close it even if configured not to mark as stale when days-before-issue-stale override days-before-stale', async () => { - const opts = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, - daysBeforeStale: 0, daysBeforeIssueStale: -1, + daysBeforePrStale: 0, staleIssueMessage: '' }; const TestIssueList: Issue[] = [ @@ -661,9 +662,10 @@ test('processing a stale issue will close it even if configured not to mark as s }); test('processing a stale PR will close it even if configured not to mark as stale', async () => { - const opts = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, - daysBeforeStale: -1, + daysBeforeIssueStale: -1, + daysBeforePrStale: -1, stalePrMessage: '' }; const TestIssueList: Issue[] = [ @@ -692,9 +694,9 @@ test('processing a stale PR will close it even if configured not to mark as stal }); test('processing a stale PR will close it even if configured not to mark as stale when days-before-pr-stale override days-before-stale', async () => { - const opts = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, - daysBeforeStale: 0, + daysBeforeIssueStale: 0, daysBeforePrStale: -1, stalePrMessage: '' }; @@ -938,7 +940,7 @@ test('stale locked prs will not be closed', async () => { test('exempt issue labels will not be marked stale', async () => { expect.assertions(3); - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.exemptIssueLabels = 'Exempt'; const TestIssueList: Issue[] = [ generateIssue( @@ -967,7 +969,7 @@ test('exempt issue labels will not be marked stale', async () => { }); test('exempt issue labels will not be marked stale (multi issue label with spaces)', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.exemptIssueLabels = 'Exempt, Cool, None'; const TestIssueList: Issue[] = [ generateIssue( @@ -995,7 +997,7 @@ test('exempt issue labels will not be marked stale (multi issue label with space }); test('exempt issue labels will not be marked stale (multi issue label)', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.exemptIssueLabels = 'Exempt,Cool,None'; const TestIssueList: Issue[] = [ generateIssue( @@ -1024,7 +1026,7 @@ test('exempt issue labels will not be marked stale (multi issue label)', async ( }); test('exempt pr labels will not be marked stale', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.exemptIssueLabels = 'Cool'; const TestIssueList: Issue[] = [ generateIssue( @@ -1069,7 +1071,7 @@ test('exempt pr labels will not be marked stale', async () => { test('exempt issue labels will not be marked stale and will remove the existing stale label', async () => { expect.assertions(3); - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.exemptIssueLabels = 'Exempt'; const TestIssueList: Issue[] = [ generateIssue( @@ -1106,7 +1108,7 @@ test('exempt issue labels will not be marked stale and will remove the existing }); test('stale issues should not be closed if days is set to -1', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.daysBeforeIssueClose = -1; opts.daysBeforePrClose = -1; const TestIssueList: Issue[] = [ @@ -1153,7 +1155,11 @@ 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: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + removeIssueStaleWhenUpdated: true, + removePrStaleWhenUpdated: true + }; const TestIssueList: Issue[] = [ generateIssue( opts, @@ -1190,9 +1196,10 @@ test('stale label should be removed if a comment was added to a stale issue', as test('when the option "labelsToAddWhenUnstale" is set, the labels should be added when unstale', async () => { expect.assertions(4); - const opts = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, - removeStaleWhenUpdated: true, + removeIssueStaleWhenUpdated: true, + removePrStaleWhenUpdated: true, labelsToAddWhenUnstale: 'test' }; const TestIssueList: Issue[] = [ @@ -1233,7 +1240,11 @@ test('when the option "labelsToAddWhenUnstale" is set, the labels should be adde }); 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, removeStaleWhenUpdated: true}; + const opts: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + removeIssueStaleWhenUpdated: true, + removePrStaleWhenUpdated: true + }; github.context.actor = 'abot'; const TestIssueList: Issue[] = [ generateIssue( @@ -1272,7 +1283,8 @@ 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, + removeIssueStaleWhenUpdated: true, + removePrStaleWhenUpdated: true, staleIssueLabel: 'stat: stale' }; const TestIssueList: Issue[] = [ @@ -1302,7 +1314,7 @@ test('stale label containing a space should be removed if a comment was added to }); test('stale issues should not be closed until after the closed number of days', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.daysBeforeIssueStale = 5; // stale after 5 days opts.daysBeforeIssueClose = 1; // closes after 6 days const lastUpdate = new Date(); @@ -1333,7 +1345,7 @@ test('stale issues should not be closed until after the closed number of days', }); test('stale issues should be closed if the closed nubmer of days (additive) is also passed', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.daysBeforeIssueStale = 5; // stale after 5 days opts.daysBeforeIssueClose = 1; // closes after 6 days const lastUpdate = new Date(); @@ -1365,7 +1377,7 @@ test('stale issues should be closed if the closed nubmer of days (additive) is a }); test('stale issues should not be closed until after the closed number of days (long)', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.daysBeforeIssueStale = 5; // stale after 5 days opts.daysBeforeIssueClose = 20; // closes after 25 days const lastUpdate = new Date(); @@ -1396,7 +1408,7 @@ test('stale issues should not be closed until after the closed number of days (l }); test('skips stale message on issues when stale-issue-message is empty', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.daysBeforeIssueStale = 5; // stale after 5 days opts.daysBeforeIssueClose = 20; // closes after 25 days opts.staleIssueMessage = ''; @@ -1440,7 +1452,7 @@ test('skips stale message on issues when stale-issue-message is empty', async () }); test('send stale message on issues when stale-issue-message is not empty', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.daysBeforeIssueStale = 5; // stale after 5 days opts.daysBeforeIssueClose = 20; // closes after 25 days opts.staleIssueMessage = 'dummy issue message'; @@ -1484,7 +1496,7 @@ test('send stale message on issues when stale-issue-message is not empty', async }); test('skips stale message on prs when stale-pr-message is empty', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.daysBeforeIssueStale = 5; // stale after 5 days opts.daysBeforeIssueClose = 20; // closes after 25 days opts.stalePrMessage = ''; @@ -1528,7 +1540,7 @@ test('skips stale message on prs when stale-pr-message is empty', async () => { }); test('send stale message on prs when stale-pr-message is not empty', async () => { - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.daysBeforeIssueStale = 5; // stale after 5 days opts.daysBeforeIssueClose = 20; // closes after 25 days opts.stalePrMessage = 'dummy pr message'; @@ -1572,7 +1584,10 @@ test('send stale message on prs when stale-pr-message is not empty', async () => }); test('git branch is deleted when option is enabled', async () => { - const opts = {...DefaultProcessorOptions, deleteBranch: true}; + const opts: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + deleteBranch: true + }; const isPullRequest = true; const TestIssueList: Issue[] = [ generateIssue( @@ -1601,7 +1616,10 @@ test('git branch is deleted when option is enabled', async () => { }); test('git branch is not deleted when issue is not pull request', async () => { - const opts = {...DefaultProcessorOptions, deleteBranch: true}; + const opts: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + deleteBranch: true + }; const isPullRequest = false; const TestIssueList: Issue[] = [ generateIssue( @@ -1662,7 +1680,7 @@ test('an issue without a milestone will be marked as stale', async () => { test('an issue without an exempted milestone will be marked as stale', async () => { expect.assertions(3); - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.exemptIssueMilestones = 'Milestone1'; const TestIssueList: Issue[] = [ generateIssue( @@ -1695,7 +1713,7 @@ test('an issue without an exempted milestone will be marked as stale', async () test('an issue with an exempted milestone will not be marked as stale', async () => { expect.assertions(3); - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.exemptIssueMilestones = 'Milestone1'; const TestIssueList: Issue[] = [ generateIssue( @@ -1728,7 +1746,7 @@ test('an issue with an exempted milestone will not be marked as stale', async () test('an issue with an exempted milestone will not be marked as stale (multi milestones with spaces)', async () => { expect.assertions(3); - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.exemptIssueMilestones = 'Milestone1, Milestone2'; const TestIssueList: Issue[] = [ generateIssue( @@ -1761,7 +1779,7 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil test('an issue with an exempted milestone will not be marked as stale (multi milestones without spaces)', async () => { expect.assertions(3); - const opts = {...DefaultProcessorOptions}; + const opts: IIssuesProcessorOptions = {...DefaultProcessorOptions}; opts.exemptIssueMilestones = 'Milestone1,Milestone2'; const TestIssueList: Issue[] = [ generateIssue( @@ -2079,7 +2097,8 @@ test('processing an issue stale since less than the daysBeforeStale with a stale daysBeforeIssueStale: 30, daysBeforeIssueClose: 7, closeIssueMessage: 'close message', - removeStaleWhenUpdated: false + removeIssueStaleWhenUpdated: false, + removePrStaleWhenUpdated: false }; const now: Date = new Date(); const updatedAt: Date = new Date(now.setDate(now.getDate() - 9)); @@ -2120,7 +2139,8 @@ test('processing an issue stale since less than the daysBeforeStale without a st daysBeforeIssueStale: 30, daysBeforeIssueClose: 7, closeIssueMessage: 'close message', - removeStaleWhenUpdated: false + removeIssueStaleWhenUpdated: false, + removePrStaleWhenUpdated: false }; const now: Date = new Date(); const updatedAt: Date = new Date(now.setDate(now.getDate() - 9)); diff --git a/__tests__/remove-stale-when-updated.spec.ts b/__tests__/remove-stale-when-updated.spec.ts index 79ff5e629..c74992d1a 100644 --- a/__tests__/remove-stale-when-updated.spec.ts +++ b/__tests__/remove-stale-when-updated.spec.ts @@ -1,555 +1,263 @@ -import {Issue} from '../src/classes/issue'; -import {IIssue} from '../src/interfaces/issue'; -import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options'; -import {ILabel} from '../src/interfaces/label'; -import {IssuesProcessorMock} from './classes/issues-processor-mock'; -import {DefaultProcessorOptions} from './constants/default-processor-options'; -import {generateIssue} from './functions/generate-issue'; - -let issuesProcessorBuilder: IssuesProcessorBuilder; -let issuesProcessor: IssuesProcessorMock; - -/** - * @description - * Assuming there is a comment on the issue - */ -describe('remove-stale-when-updated option', (): void => { - beforeEach((): void => { - issuesProcessorBuilder = new IssuesProcessorBuilder(); - }); - - describe('when the option "remove-stale-when-updated" is disabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.keepStaleWhenUpdated(); - }); - - test('should not remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - - test('should not remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - }); - - describe('when the option "remove-stale-when-updated" is enabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.removeStaleWhenUpdated(); - }); - - test('should remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - - test('should remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - }); -}); - -describe('remove-issue-stale-when-updated option', (): void => { - beforeEach((): void => { - issuesProcessorBuilder = new IssuesProcessorBuilder(); - }); - - describe('when the option "remove-stale-when-updated" is disabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.keepStaleWhenUpdated(); - }); - - describe('when the option "remove-issue-stale-when-updated" is unset', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.unsetIssueStaleWhenUpdated(); - }); - - test('should not remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - - test('should not remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - }); - - describe('when the option "remove-issue-stale-when-updated" is disabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.keepIssueStaleWhenUpdated(); - }); - - test('should not remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - - test('should not remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - }); - - describe('when the option "remove-issue-stale-when-updated" is enabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.removeIssueStaleWhenUpdated(); - }); - - test('should remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - - test('should not remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - }); - }); - - describe('when the option "remove-stale-when-updated" is enabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.removeStaleWhenUpdated(); - }); - - describe('when the option "remove-issue-stale-when-updated" is unset', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.unsetIssueStaleWhenUpdated(); - }); - - test('should remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - - test('should remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - }); - - describe('when the option "remove-issue-stale-when-updated" is disabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.keepIssueStaleWhenUpdated(); - }); - - test('should not remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - - test('should remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - }); - - describe('when the option "remove-issue-stale-when-updated" is enabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.removeIssueStaleWhenUpdated(); - }); - - test('should remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - - test('should remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - }); - }); -}); - -describe('remove-pr-stale-when-updated option', (): void => { - beforeEach((): void => { - issuesProcessorBuilder = new IssuesProcessorBuilder(); - }); - - describe('when the option "remove-stale-when-updated" is disabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.keepStaleWhenUpdated(); - }); - - describe('when the option "remove-pr-stale-when-updated" is unset', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.unsetPrStaleWhenUpdated(); - }); - - test('should not remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - - test('should not remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - }); - - describe('when the option "remove-pr-stale-when-updated" is disabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.keepPrStaleWhenUpdated(); - }); - - test('should not remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - - test('should not remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - }); - - describe('when the option "remove-pr-stale-when-updated" is enabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.removePrStaleWhenUpdated(); - }); - - test('should not remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - - test('should remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - }); - }); - - describe('when the option "remove-stale-when-updated" is enabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.removeStaleWhenUpdated(); - }); - - describe('when the option "remove-pr-stale-when-updated" is unset', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.unsetPrStaleWhenUpdated(); - }); - - test('should remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - - test('should remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - }); - - describe('when the option "remove-pr-stale-when-updated" is disabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.keepPrStaleWhenUpdated(); - }); - - test('should remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - - test('should not remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(0); - }); - }); - - describe('when the option "remove-pr-stale-when-updated" is enabled', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.removePrStaleWhenUpdated(); - }); - - test('should remove the stale label on the issue', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - - test('should remove the stale label on the pull request', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.removedLabelIssues).toHaveLength(1); - }); - }); - }); -}); - -class IssuesProcessorBuilder { - private _options: IIssuesProcessorOptions = { - ...DefaultProcessorOptions - }; - private _issues: Issue[] = []; - - keepStaleWhenUpdated(): IssuesProcessorBuilder { - this._options.removeStaleWhenUpdated = false; - - return this; - } - - removeStaleWhenUpdated(): IssuesProcessorBuilder { - this._options.removeStaleWhenUpdated = true; - - return this; - } - - unsetIssueStaleWhenUpdated(): IssuesProcessorBuilder { - delete this._options.removeIssueStaleWhenUpdated; - - return this; - } - - keepIssueStaleWhenUpdated(): IssuesProcessorBuilder { - this._options.removeIssueStaleWhenUpdated = false; - - return this; - } - - removeIssueStaleWhenUpdated(): IssuesProcessorBuilder { - this._options.removeIssueStaleWhenUpdated = true; - - return this; - } - - unsetPrStaleWhenUpdated(): IssuesProcessorBuilder { - delete this._options.removePrStaleWhenUpdated; - - return this; - } - - keepPrStaleWhenUpdated(): IssuesProcessorBuilder { - this._options.removePrStaleWhenUpdated = false; - - return this; - } - - removePrStaleWhenUpdated(): IssuesProcessorBuilder { - this._options.removePrStaleWhenUpdated = true; - - return this; - } - - issuesOrPrs(issues: Partial[]): IssuesProcessorBuilder { - this._issues = issues.map( - (issue: Readonly>, index: Readonly): Issue => - generateIssue( - this._options, - index, - issue.title ?? 'dummy-title', - issue.updated_at ?? new Date().toDateString(), - issue.created_at ?? new Date().toDateString(), - !!issue.pull_request, - issue.labels ? issue.labels.map(label => label.name) : [] - ) - ); - - return this; - } - - issues(issues: Partial[]): IssuesProcessorBuilder { - this.issuesOrPrs( - issues.map((issue: Readonly>): Partial => { - return { - ...issue, - pull_request: null - }; - }) - ); - - return this; - } - - staleIssues(issues: Partial[]): IssuesProcessorBuilder { - this.issues( - issues.map((issue: Readonly>): Partial => { - return { - ...issue, - updated_at: '2020-01-01T17:00:00Z', - created_at: '2020-01-01T17:00:00Z', - labels: issue.labels?.map((label: Readonly): ILabel => { - return { - ...label, - name: 'Stale' - }; - }) ?? [ - { - name: 'Stale' - } - ] - }; - }) - ); - - return this; - } - - prs(issues: Partial[]): IssuesProcessorBuilder { - this.issuesOrPrs( - issues.map((issue: Readonly>): Partial => { - return { - ...issue, - pull_request: {key: 'value'} - }; - }) - ); - - return this; - } - - stalePrs(issues: Partial[]): IssuesProcessorBuilder { - this.prs( - issues.map((issue: Readonly>): Partial => { - return { - ...issue, - updated_at: '2020-01-01T17:00:00Z', - created_at: '2020-01-01T17:00:00Z', - labels: issue.labels?.map((label: Readonly): ILabel => { - return { - ...label, - name: 'Stale' - }; - }) ?? [ - { - name: 'Stale' - } - ] - }; - }) - ); - - return this; - } - - build(): IssuesProcessorMock { - return new IssuesProcessorMock( - this._options, - async p => (p === 1 ? this._issues : []), - async () => [ - { - user: { - login: 'notme', - type: 'User' - }, - body: 'body' - } - ], - async () => new Date().toDateString() - ); - } -} +import {Issue} from '../src/classes/issue'; +import {IIssue} from '../src/interfaces/issue'; +import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options'; +import {ILabel} from '../src/interfaces/label'; +import {IssuesProcessorMock} from './classes/issues-processor-mock'; +import {DefaultProcessorOptions} from './constants/default-processor-options'; +import {generateIssue} from './functions/generate-issue'; + +let issuesProcessorBuilder: IssuesProcessorBuilder; +let issuesProcessor: IssuesProcessorMock; + +/** + * @description + * Assuming there is a comment on the issue + */ +describe('remove-issue-stale-when-updated option', (): void => { + beforeEach((): void => { + issuesProcessorBuilder = new IssuesProcessorBuilder(); + }); + + describe('when the option "remove-issue-stale-when-updated" is disabled', (): void => { + beforeEach((): void => { + issuesProcessorBuilder.keepIssueStaleWhenUpdated(); + }); + + test('should not remove the stale label on the issue', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.removedLabelIssues).toHaveLength(0); + }); + + test('should remove the stale label on the pull request', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.removedLabelIssues).toHaveLength(1); + }); + }); + + describe('when the option "remove-issue-stale-when-updated" is enabled', (): void => { + beforeEach((): void => { + issuesProcessorBuilder.removeIssueStaleWhenUpdated(); + }); + + test('should remove the stale label on the issue', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.removedLabelIssues).toHaveLength(1); + }); + + test('should remove the stale label on the pull request', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.removedLabelIssues).toHaveLength(1); + }); + }); +}); + +describe('remove-pr-stale-when-updated option', (): void => { + beforeEach((): void => { + issuesProcessorBuilder = new IssuesProcessorBuilder(); + }); + + describe('when the option "remove-pr-stale-when-updated" is disabled', (): void => { + beforeEach((): void => { + issuesProcessorBuilder.keepPrStaleWhenUpdated(); + }); + + test('should remove the stale label on the issue', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.removedLabelIssues).toHaveLength(1); + }); + + test('should not remove the stale label on the pull request', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.removedLabelIssues).toHaveLength(0); + }); + }); + + describe('when the option "remove-pr-stale-when-updated" is enabled', (): void => { + beforeEach((): void => { + issuesProcessorBuilder.removePrStaleWhenUpdated(); + }); + + test('should remove the stale label on the issue', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.removedLabelIssues).toHaveLength(1); + }); + + test('should remove the stale label on the pull request', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.removedLabelIssues).toHaveLength(1); + }); + }); +}); + +class IssuesProcessorBuilder { + private _options: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + removeIssueStaleWhenUpdated: true, + removePrStaleWhenUpdated: true + }; + private _issues: Issue[] = []; + + keepIssueStaleWhenUpdated(): IssuesProcessorBuilder { + this._options.removeIssueStaleWhenUpdated = false; + + return this; + } + + removeIssueStaleWhenUpdated(): IssuesProcessorBuilder { + this._options.removeIssueStaleWhenUpdated = true; + + return this; + } + + keepPrStaleWhenUpdated(): IssuesProcessorBuilder { + this._options.removePrStaleWhenUpdated = false; + + return this; + } + + removePrStaleWhenUpdated(): IssuesProcessorBuilder { + this._options.removePrStaleWhenUpdated = true; + + return this; + } + + issuesOrPrs(issues: Partial[]): IssuesProcessorBuilder { + this._issues = issues.map( + (issue: Readonly>, index: Readonly): Issue => + generateIssue( + this._options, + index, + issue.title ?? 'dummy-title', + issue.updated_at ?? new Date().toDateString(), + issue.created_at ?? new Date().toDateString(), + !!issue.pull_request, + issue.labels ? issue.labels.map(label => label.name) : [] + ) + ); + + return this; + } + + issues(issues: Partial[]): IssuesProcessorBuilder { + this.issuesOrPrs( + issues.map((issue: Readonly>): Partial => { + return { + ...issue, + pull_request: null + }; + }) + ); + + return this; + } + + staleIssues(issues: Partial[]): IssuesProcessorBuilder { + this.issues( + issues.map((issue: Readonly>): Partial => { + return { + ...issue, + updated_at: '2020-01-01T17:00:00Z', + created_at: '2020-01-01T17:00:00Z', + labels: issue.labels?.map((label: Readonly): ILabel => { + return { + ...label, + name: 'Stale' + }; + }) ?? [ + { + name: 'Stale' + } + ] + }; + }) + ); + + return this; + } + + prs(issues: Partial[]): IssuesProcessorBuilder { + this.issuesOrPrs( + issues.map((issue: Readonly>): Partial => { + return { + ...issue, + pull_request: {key: 'value'} + }; + }) + ); + + return this; + } + + stalePrs(issues: Partial[]): IssuesProcessorBuilder { + this.prs( + issues.map((issue: Readonly>): Partial => { + return { + ...issue, + updated_at: '2020-01-01T17:00:00Z', + created_at: '2020-01-01T17:00:00Z', + labels: issue.labels?.map((label: Readonly): ILabel => { + return { + ...label, + name: 'Stale' + }; + }) ?? [ + { + name: 'Stale' + } + ] + }; + }) + ); + + return this; + } + + build(): IssuesProcessorMock { + return new IssuesProcessorMock( + this._options, + async p => (p === 1 ? this._issues : []), + async () => [ + { + user: { + login: 'notme', + type: 'User' + }, + body: 'body' + } + ], + async () => new Date().toDateString() + ); + } +} diff --git a/action.yml b/action.yml index 430dcbc21..18170ed57 100644 --- a/action.yml +++ b/action.yml @@ -92,17 +92,13 @@ inputs: description: 'The maximum number of operations per run, used to control rate limiting (GitHub API CRUD related).' default: '30' required: false - remove-stale-when-updated: - description: 'Remove stale labels from issues and pull requests when they are updated or commented on.' - default: 'true' - required: false remove-issue-stale-when-updated: - description: 'Remove stale labels from issues when they are updated or commented on. Override "remove-stale-when-updated" option regarding only the issues.' - default: '' + description: 'Remove stale labels from issues when they are updated or commented on.' + default: 'true' required: false remove-pr-stale-when-updated: - description: 'Remove stale labels from pull requests when they are updated or commented on. Override "remove-stale-when-updated" option regarding only the pull requests.' - default: '' + description: 'Remove stale labels from pull requests when they are updated or commented on.' + default: 'true' required: false debug-only: description: 'Run the processor in debug mode without actually performing any operations on live issues.' diff --git a/dist/index.js b/dist/index.js index 28b9b8f1c..3f9271797 100644 --- a/dist/index.js +++ b/dist/index.js @@ -297,7 +297,6 @@ const clean_label_1 = __nccwpck_require__(7752); const get_humanized_date_1 = __nccwpck_require__(965); const is_date_more_recent_than_1 = __nccwpck_require__(1473); const is_valid_date_1 = __nccwpck_require__(891); -const is_boolean_1 = __nccwpck_require__(8236); const is_labeled_1 = __nccwpck_require__(6792); const should_mark_when_stale_1 = __nccwpck_require__(2461); const words_to_list_1 = __nccwpck_require__(1883); @@ -675,7 +674,7 @@ class IssuesProcessor { const issueHasUpdate = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose); issueLogger.info(`$$type has been updated: ${logger_service_1.LoggerService.cyan(issueHasUpdate)}`); const shouldRemoveStaleWhenUpdated = this._shouldRemoveStaleWhenUpdated(issue); - issueLogger.info(`The option ${issueLogger.createOptionLink(this._getRemoveStaleWhenUpdatedUsedOptionName(issue))} is: ${logger_service_1.LoggerService.cyan(shouldRemoveStaleWhenUpdated)}`); + issueLogger.info(`The option ${issueLogger.createOptionLink(IssuesProcessor._getRemoveStaleWhenUpdatedUsedOptionName(issue))} is: ${logger_service_1.LoggerService.cyan(shouldRemoveStaleWhenUpdated)}`); if (shouldRemoveStaleWhenUpdated) { issueLogger.info(`The stale label should not be removed`); } @@ -903,16 +902,9 @@ class IssuesProcessor { return this.options.anyOfIssueLabels; } _shouldRemoveStaleWhenUpdated(issue) { - if (issue.isPullRequest) { - if (is_boolean_1.isBoolean(this.options.removePrStaleWhenUpdated)) { - return this.options.removePrStaleWhenUpdated; - } - return this.options.removeStaleWhenUpdated; - } - if (is_boolean_1.isBoolean(this.options.removeIssueStaleWhenUpdated)) { - return this.options.removeIssueStaleWhenUpdated; - } - return this.options.removeStaleWhenUpdated; + return issue.isPullRequest + ? this.options.removePrStaleWhenUpdated + : this.options.removeIssueStaleWhenUpdated; } _removeLabelsWhenUnstale(issue, removeLabels) { return __awaiter(this, void 0, void 0, function* () { @@ -987,22 +979,15 @@ class IssuesProcessor { ? option_1.Option.DaysBeforePrStale : option_1.Option.DaysBeforeIssueStale; } + static _getRemoveStaleWhenUpdatedUsedOptionName(issue) { + return issue.isPullRequest + ? option_1.Option.RemovePrStaleWhenUpdated + : option_1.Option.RemoveIssueStaleWhenUpdated; + } _consumeIssueOperation(issue) { this.operations.consumeOperation(); issue.operations.consumeOperation(); } - _getRemoveStaleWhenUpdatedUsedOptionName(issue) { - if (issue.isPullRequest) { - if (is_boolean_1.isBoolean(this.options.removePrStaleWhenUpdated)) { - return option_1.Option.RemovePrStaleWhenUpdated; - } - return option_1.Option.RemoveStaleWhenUpdated; - } - if (is_boolean_1.isBoolean(this.options.removeIssueStaleWhenUpdated)) { - return option_1.Option.RemoveIssueStaleWhenUpdated; - } - return option_1.Option.RemoveStaleWhenUpdated; - } } exports.IssuesProcessor = IssuesProcessor; @@ -1730,7 +1715,6 @@ var Option; Option["AnyOfIssueLabels"] = "any-of-issue-labels"; Option["AnyOfPrLabels"] = "any-of-pr-labels"; Option["OperationsPerRun"] = "operations-per-run"; - Option["RemoveStaleWhenUpdated"] = "remove-stale-when-updated"; Option["RemoveIssueStaleWhenUpdated"] = "remove-issue-stale-when-updated"; Option["RemovePrStaleWhenUpdated"] = "remove-pr-stale-when-updated"; Option["DebugOnly"] = "debug-only"; @@ -1849,21 +1833,6 @@ function isValidDate(date) { exports.isValidDate = isValidDate; -/***/ }), - -/***/ 8236: -/***/ ((__unused_webpack_module, exports) => { - -"use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isBoolean = void 0; -function isBoolean(value) { - return value === true || value === false; -} -exports.isBoolean = isBoolean; - - /***/ }), /***/ 6792: @@ -2030,9 +1999,8 @@ function _getAndValidateArgs() { anyOfIssueLabels: core.getInput('any-of-issue-labels'), anyOfPrLabels: core.getInput('any-of-pr-labels'), operationsPerRun: parseInt(core.getInput('operations-per-run', { required: true })), - removeStaleWhenUpdated: !(core.getInput('remove-stale-when-updated') === 'false'), - removeIssueStaleWhenUpdated: _toOptionalBoolean('remove-issue-stale-when-updated'), - removePrStaleWhenUpdated: _toOptionalBoolean('remove-pr-stale-when-updated'), + removeIssueStaleWhenUpdated: !(core.getInput('remove-issue-stale-when-updated') === 'false'), + removePrStaleWhenUpdated: !(core.getInput('remove-pr-stale-when-updated') === 'false'), debugOnly: core.getInput('debug-only') === 'true', ascending: core.getInput('ascending') === 'true', deleteBranch: core.getInput('delete-branch') === 'true', @@ -2085,27 +2053,6 @@ function processOutput(staledIssues, closedIssues) { core.setOutput('closed-issues-prs', JSON.stringify(closedIssues)); }); } -/** - * @description - * From an argument name, get the value as an optional boolean - * This is very useful for all the arguments that override others - * It will allow us to easily use the original one when the return value is `undefined` - * Which is different from `true` or `false` that consider the argument as set - * - * @param {Readonly} argumentName The name of the argument to check - * - * @returns {boolean | undefined} The value matching the given argument name - */ -function _toOptionalBoolean(argumentName) { - const argument = core.getInput(argumentName); - if (argument === 'true') { - return true; - } - else if (argument === 'false') { - return false; - } - return undefined; -} void _run(); diff --git a/src/classes/issue.spec.ts b/src/classes/issue.spec.ts index df833f220..b01b5b703 100644 --- a/src/classes/issue.spec.ts +++ b/src/classes/issue.spec.ts @@ -30,9 +30,8 @@ describe('Issue', (): void => { anyOfIssueLabels: '', anyOfPrLabels: '', operationsPerRun: 0, - removeStaleWhenUpdated: false, - removeIssueStaleWhenUpdated: undefined, - removePrStaleWhenUpdated: undefined, + removeIssueStaleWhenUpdated: false, + removePrStaleWhenUpdated: false, repoToken: '', staleIssueMessage: '', stalePrMessage: '', diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 33d3ef56a..d90dda12b 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -7,7 +7,6 @@ import {cleanLabel} from '../functions/clean-label'; import {getHumanizedDate} from '../functions/dates/get-humanized-date'; import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than'; import {isValidDate} from '../functions/dates/is-valid-date'; -import {isBoolean} from '../functions/is-boolean'; import {isLabeled} from '../functions/is-labeled'; import {shouldMarkWhenStale} from '../functions/should-mark-when-stale'; import {wordsToList} from '../functions/words-to-list'; @@ -660,7 +659,7 @@ export class IssuesProcessor { issueLogger.info( `The option ${issueLogger.createOptionLink( - this._getRemoveStaleWhenUpdatedUsedOptionName(issue) + IssuesProcessor._getRemoveStaleWhenUpdatedUsedOptionName(issue) )} is: ${LoggerService.cyan(shouldRemoveStaleWhenUpdated)}` ); @@ -974,19 +973,9 @@ export class IssuesProcessor { } private _shouldRemoveStaleWhenUpdated(issue: Issue): boolean { - if (issue.isPullRequest) { - if (isBoolean(this.options.removePrStaleWhenUpdated)) { - return this.options.removePrStaleWhenUpdated; - } - - return this.options.removeStaleWhenUpdated; - } - - if (isBoolean(this.options.removeIssueStaleWhenUpdated)) { - return this.options.removeIssueStaleWhenUpdated; - } - - return this.options.removeStaleWhenUpdated; + return issue.isPullRequest + ? this.options.removePrStaleWhenUpdated + : this.options.removeIssueStaleWhenUpdated; } private async _removeLabelsWhenUnstale( @@ -1113,29 +1102,16 @@ export class IssuesProcessor { : Option.DaysBeforeIssueStale; } + private static _getRemoveStaleWhenUpdatedUsedOptionName( + issue: Readonly + ): Option.RemovePrStaleWhenUpdated | Option.RemoveIssueStaleWhenUpdated { + return issue.isPullRequest + ? Option.RemovePrStaleWhenUpdated + : Option.RemoveIssueStaleWhenUpdated; + } + private _consumeIssueOperation(issue: Readonly): void { this.operations.consumeOperation(); issue.operations.consumeOperation(); } - - private _getRemoveStaleWhenUpdatedUsedOptionName( - issue: Readonly - ): - | Option.RemovePrStaleWhenUpdated - | Option.RemoveStaleWhenUpdated - | Option.RemoveIssueStaleWhenUpdated { - if (issue.isPullRequest) { - if (isBoolean(this.options.removePrStaleWhenUpdated)) { - return Option.RemovePrStaleWhenUpdated; - } - - return Option.RemoveStaleWhenUpdated; - } - - if (isBoolean(this.options.removeIssueStaleWhenUpdated)) { - return Option.RemoveIssueStaleWhenUpdated; - } - - return Option.RemoveStaleWhenUpdated; - } } diff --git a/src/enums/option.ts b/src/enums/option.ts index 5d7d61b0a..99c8cdb17 100644 --- a/src/enums/option.ts +++ b/src/enums/option.ts @@ -19,7 +19,6 @@ export enum Option { AnyOfIssueLabels = 'any-of-issue-labels', AnyOfPrLabels = 'any-of-pr-labels', OperationsPerRun = 'operations-per-run', - RemoveStaleWhenUpdated = 'remove-stale-when-updated', RemoveIssueStaleWhenUpdated = 'remove-issue-stale-when-updated', RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated', DebugOnly = 'debug-only', diff --git a/src/interfaces/issues-processor-options.ts b/src/interfaces/issues-processor-options.ts index 21419d0a3..0e2930670 100644 --- a/src/interfaces/issues-processor-options.ts +++ b/src/interfaces/issues-processor-options.ts @@ -21,9 +21,8 @@ export interface IIssuesProcessorOptions { anyOfIssueLabels: string; anyOfPrLabels: string; operationsPerRun: number; - removeStaleWhenUpdated: boolean; - removeIssueStaleWhenUpdated: boolean | undefined; - removePrStaleWhenUpdated: boolean | undefined; + removeIssueStaleWhenUpdated: boolean; + removePrStaleWhenUpdated: boolean; debugOnly: boolean; ascending: boolean; deleteBranch: boolean; diff --git a/src/main.ts b/src/main.ts index 46df34cc1..767efcb9f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,14 +53,11 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { operationsPerRun: parseInt( core.getInput('operations-per-run', {required: true}) ), - removeStaleWhenUpdated: !( - core.getInput('remove-stale-when-updated') === 'false' + removeIssueStaleWhenUpdated: !( + core.getInput('remove-issue-stale-when-updated') === 'false' ), - removeIssueStaleWhenUpdated: _toOptionalBoolean( - 'remove-issue-stale-when-updated' - ), - removePrStaleWhenUpdated: _toOptionalBoolean( - 'remove-pr-stale-when-updated' + removePrStaleWhenUpdated: !( + core.getInput('remove-pr-stale-when-updated') === 'false' ), debugOnly: core.getInput('debug-only') === 'true', ascending: core.getInput('ascending') === 'true', @@ -123,29 +120,4 @@ async function processOutput( core.setOutput('closed-issues-prs', JSON.stringify(closedIssues)); } -/** - * @description - * From an argument name, get the value as an optional boolean - * This is very useful for all the arguments that override others - * It will allow us to easily use the original one when the return value is `undefined` - * Which is different from `true` or `false` that consider the argument as set - * - * @param {Readonly} argumentName The name of the argument to check - * - * @returns {boolean | undefined} The value matching the given argument name - */ -function _toOptionalBoolean( - argumentName: Readonly -): boolean | undefined { - const argument: string = core.getInput(argumentName); - - if (argument === 'true') { - return true; - } else if (argument === 'false') { - return false; - } - - return undefined; -} - void _run();