From a8c5bb1c29eeb17857599f5b26c992110f0f405c Mon Sep 17 00:00:00 2001 From: TESTELIN Geoffrey Date: Fri, 8 Oct 2021 20:26:58 +0200 Subject: [PATCH] feat: remove the only-labels option BREAKING CHANGE: The option only-labels was removed --- README.md | 36 +- __tests__/only-labels.spec.ts | 1680 +++++++------------- action.yml | 8 +- dist/index.js | 23 +- src/classes/issue.spec.ts | 1 - src/classes/issues-processor.ts | 22 +- src/enums/option.ts | 1 - src/interfaces/issues-processor-options.ts | 1 - src/main.ts | 1 - 9 files changed, 568 insertions(+), 1205 deletions(-) diff --git a/README.md b/README.md index 9191b5da..bc519186 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,8 @@ Every argument is optional. | [close-pr-label](#close-pr-label) | Label to apply on closed PRs | | | [exempt-issue-labels](#exempt-issue-labels) | Labels on issues exempted from stale | | | [exempt-pr-labels](#exempt-pr-labels) | Labels on PRs exempted from stale | | -| [only-labels](#only-labels) | Only issues/PRs with ALL these labels are checked | | -| [only-issue-labels](#only-issue-labels) | Override [only-labels](#only-labels) for issues only | | -| [only-pr-labels](#only-pr-labels) | Override [only-labels](#only-labels) for PRs only | | +| [only-issue-labels](#only-issue-labels) | Only issues with ALL these labels are checked | | +| [only-pr-labels](#only-pr-labels) | Only PRs with ALL these labels are checked | | | [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` | @@ -115,7 +114,8 @@ You can fine tune which issues or pull requests should be marked as stale based - [exempt-issue-labels](#exempt-issue-labels) - [exempt-pr-labels](#exempt-pr-labels) -- [only-labels](#only-labels) +- [only-issue-labels](#only-issue-labels) +- [only-pr-labels](#only-pr-labels) - [any-of-issue-labels](#any-of-issue-labels) - [any-of-pr-labels](#any-of-pr-labels) - [start-date](#start-date) @@ -253,26 +253,25 @@ If unset (or an empty string), this option will not alter the stale workflow. Default value: unset -#### only-labels +#### only-issue-labels -An allow-list of label(s) to only process the issues or the pull requests that contain all these label(s). +An allow-list of label(s) to only process the issues that contain all these label(s). It can be a comma separated list of labels (e.g: `answered,needs-rebase`). If unset (or an empty string), this option will not alter the stale workflow. -If you wish to only check that the issues or the pull requests contain one of these label(s), use instead [any-of-issue-labels](#any-of-issue-labels) and [any-of-pr-labels](#any-of-pr-labels). - -Default value: unset - -#### only-issue-labels - -Override [only-labels](#only-labels) but only to process the issues that contain all these label(s). +If you wish to only check that the issues contain one of these label(s), use instead [any-of-issue-labels](#any-of-issue-labels). Default value: unset #### only-pr-labels -Override [only-labels](#only-labels) but only to process the pull requests that contain all these label(s). +An allow-list of label(s) to only process the pull requests that contain all these label(s). +It can be a comma separated list of labels (e.g: `answered,needs-rebase`). + +If unset (or an empty string), this option will not alter the stale workflow. + +If you wish to only check that the pull requests contain one of these label(s), use instead [any-of-pr-labels](#any-of-pr-labels). Default value: unset @@ -283,7 +282,7 @@ It can be a comma separated list of labels (e.g: `answered,needs-rebase`). If unset (or an empty string), this option will not alter the stale workflow. -If you wish to only check that the issues or the pull requests contain all these label(s), use instead [only-labels](#only-labels). +If you wish to only check that the issues or the pull requests contain all these label(s), use instead [only-issue-labels](#only-issue-labels). Default value: unset @@ -294,7 +293,7 @@ It can be a comma separated list of labels (e.g: `answered,needs-rebase`). If unset (or an empty string), this option will not alter the stale workflow. -If you wish to only check that the issues or the pull requests contain all these label(s), use instead [only-labels](#only-labels). +If you wish to only check that the issues or the pull requests contain all these label(s), use instead [only-pr-labels](#only-pr-labels). Default value: unset @@ -597,7 +596,8 @@ jobs: exempt-issue-labels: 'awaiting-approval,work-in-progress' stale-pr-label: 'no-pr-activity' exempt-pr-labels: 'awaiting-approval,work-in-progress' - only-labels: 'awaiting-feedback,awaiting-answers' + only-issue-labels: 'awaiting-feedback,awaiting-answers' + only-pr-labels: 'awaiting-feedback,awaiting-answers' ``` Configure the stale action to only stale issue/PR created after the 18th april 2020: @@ -668,7 +668,7 @@ jobs: with: any-of-issue-labels: 'needs-more-info,needs-demo' any-of-pr-labels: 'needs-more-info,needs-demo' - # You can opt for 'only-labels' instead if your use-case requires all labels + # You can opt for 'only-issue-labels' and 'only-pr-labels' instead if your use-case requires all labels # to be present in the issue/PR ``` diff --git a/__tests__/only-labels.spec.ts b/__tests__/only-labels.spec.ts index 690cb118..45fef6e7 100644 --- a/__tests__/only-labels.spec.ts +++ b/__tests__/only-labels.spec.ts @@ -1,1147 +1,533 @@ -import {Issue} from '../src/classes/issue'; -import {IIssue} from '../src/interfaces/issue'; -import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options'; -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; - -describe('only-labels options', (): void => { - beforeEach((): void => { - issuesProcessorBuilder = new IssuesProcessorBuilder(); - }); - - test('should stale when not set even if the issue has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyLabels() - .issuesOrPrs([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should stale when not set even if the issue has a label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyLabels() - .issuesOrPrs([{labels: [{name: 'label'}]}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should not stale when set and the issue has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyLabels('dummy-label') - .issuesOrPrs([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the issue has a different label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyLabels('dummy-label') - .issuesOrPrs([ - { - labels: [ - { - name: 'label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the issue has different labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyLabels('dummy-label') - .issuesOrPrs([ - { - labels: [ - { - name: 'label-1' - }, - { - name: 'label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the issue has the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyLabels('dummy-label') - .issuesOrPrs([ - { - labels: [ - { - name: 'dummy-label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should not stale when set and the issue has only one of the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyLabels('dummy-label-1,dummy-label-2') - .issuesOrPrs([ - { - labels: [ - { - name: 'dummy-label-1' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the issue has all the same labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyLabels('dummy-label-1,dummy-label-2') - .issuesOrPrs([ - { - labels: [ - { - name: 'dummy-label-1' - }, - { - name: 'dummy-label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); -}); - -describe('only-issue-labels option', (): void => { - beforeEach((): void => { - issuesProcessorBuilder = new IssuesProcessorBuilder(); - }); - - describe('when the only-labels options is not set', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.emptyOnlyLabels(); - }); - - test('should stale when not set even if the issue has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyIssueLabels() - .issues([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should stale when not set even if the issue has a label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyIssueLabels() - .issues([{labels: [{name: 'dummy-label'}]}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should not stale when set and the issue has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the issue has a different label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([ - { - labels: [ - { - name: 'label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the issue has different labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([ - { - labels: [ - { - name: 'label-1' - }, - { - name: 'label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the issue has the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([ - { - labels: [ - { - name: 'dummy-label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should not stale when set and the issue has only one of the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label-1,dummy-label-2') - .issues([ - { - labels: [ - { - name: 'dummy-label-1' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the issue has all the same labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label-1,dummy-label-2') - .issues([ - { - labels: [ - { - name: 'dummy-label-1' - }, - { - name: 'dummy-label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - }); - - describe('when the only-labels options is set (same as only-issue-labels)', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.onlyLabels('dummy-label'); - }); - - test('should not stale when not set even if the issue has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyIssueLabels() - .issues([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when not set even if the issue has a label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyIssueLabels() - .issues([{labels: [{name: 'label'}]}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the issue has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the issue has a different label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([ - { - labels: [ - { - name: 'label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the issue has different labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([ - { - labels: [ - { - name: 'label-1' - }, - { - name: 'label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the issue has the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([ - { - labels: [ - { - name: 'dummy-label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should not stale when set and the issue has only one of the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label-1,dummy-label-2') - .issues([ - { - labels: [ - { - name: 'dummy-label-1' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the issue has all the same labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label-1,dummy-label-2') - .issues([ - { - labels: [ - { - name: 'dummy-label-1' - }, - { - name: 'dummy-label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - }); - - describe('when the only-labels options is set (different than only-issue-labels)', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.onlyLabels('dummy-only-label'); - }); - - test('should not stale when not set even if the issue has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyIssueLabels() - .issues([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when not set even if the issue has a label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyIssueLabels() - .issues([{labels: [{name: 'label'}]}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the issue has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the issue has a different label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([ - { - labels: [ - { - name: 'label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the issue has different labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([ - { - labels: [ - { - name: 'label-1' - }, - { - name: 'label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the issue has the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label') - .issues([ - { - labels: [ - { - name: 'dummy-label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should not stale when set and the issue has only one of the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label-1,dummy-label-2') - .issues([ - { - labels: [ - { - name: 'dummy-label-1' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the issue has all the same labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyIssueLabels('dummy-label-1,dummy-label-2') - .issues([ - { - labels: [ - { - name: 'dummy-label-1' - }, - { - name: 'dummy-label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - }); -}); - -describe('only-pr-labels option', (): void => { - beforeEach((): void => { - issuesProcessorBuilder = new IssuesProcessorBuilder(); - }); - - describe('when the only-labels options is not set', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.emptyOnlyLabels(); - }); - - test('should stale when not set even if the pr has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyPrLabels() - .prs([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should stale when not set even if the pr has a label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyPrLabels() - .prs([{labels: [{name: 'dummy-label'}]}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should not stale when set and the pr has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the pr has a different label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([ - { - labels: [ - { - name: 'label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the pr has different labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([ - { - labels: [ - { - name: 'label-1' - }, - { - name: 'label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the pr has the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([ - { - labels: [ - { - name: 'dummy-label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should not stale when set and the pr has only one of the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label-1,dummy-label-2') - .prs([ - { - labels: [ - { - name: 'dummy-label-1' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the pr has all the same labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label-1,dummy-label-2') - .prs([ - { - labels: [ - { - name: 'dummy-label-1' - }, - { - name: 'dummy-label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - }); - - describe('when the only-labels options is set (same as only-pr-labels)', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.onlyLabels('dummy-label'); - }); - - test('should not stale when not set even if the pr has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyPrLabels() - .prs([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when not set even if the pr has a label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyPrLabels() - .prs([{labels: [{name: 'label'}]}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the pr has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the pr has a different label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([ - { - labels: [ - { - name: 'label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the pr has different labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([ - { - labels: [ - { - name: 'label-1' - }, - { - name: 'label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the pr has the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([ - { - labels: [ - { - name: 'dummy-label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should not stale when set and the pr has only one of the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label-1,dummy-label-2') - .prs([ - { - labels: [ - { - name: 'dummy-label-1' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the pr has all the same labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label-1,dummy-label-2') - .prs([ - { - labels: [ - { - name: 'dummy-label-1' - }, - { - name: 'dummy-label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - }); - - describe('when the only-labels options is set (different than only-pr-labels)', (): void => { - beforeEach((): void => { - issuesProcessorBuilder.onlyLabels('dummy-only-label'); - }); - - test('should not stale when not set even if the pr has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyPrLabels() - .prs([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when not set even if the pr has a label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .emptyOnlyPrLabels() - .prs([{labels: [{name: 'label'}]}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the pr has no label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([{labels: []}]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the pr has a different label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([ - { - labels: [ - { - name: 'label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should not stale when set and the pr has different labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([ - { - labels: [ - { - name: 'label-1' - }, - { - name: 'label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the pr has the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label') - .prs([ - { - labels: [ - { - name: 'dummy-label' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - - test('should not stale when set and the pr has only one of the same label', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label-1,dummy-label-2') - .prs([ - { - labels: [ - { - name: 'dummy-label-1' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(0); - }); - - test('should stale when set and the pr has all the same labels', async (): Promise => { - expect.assertions(1); - issuesProcessor = issuesProcessorBuilder - .onlyPrLabels('dummy-label-1,dummy-label-2') - .prs([ - { - labels: [ - { - name: 'dummy-label-1' - }, - { - name: 'dummy-label-2' - } - ] - } - ]) - .build(); - - await issuesProcessor.processIssues(); - - expect(issuesProcessor.staleIssues).toHaveLength(1); - }); - }); -}); - -class IssuesProcessorBuilder { - private _options: IIssuesProcessorOptions = { - ...DefaultProcessorOptions, - daysBeforeStale: 0 - }; - private _issues: Issue[] = []; - - onlyLabels(labels: string): IssuesProcessorBuilder { - this._options.onlyLabels = labels; - - return this; - } - - onlyIssueLabels(labels: string): IssuesProcessorBuilder { - this._options.onlyIssueLabels = labels; - - return this; - } - - onlyPrLabels(labels: string): IssuesProcessorBuilder { - this._options.onlyPrLabels = labels; - - return this; - } - - emptyOnlyLabels(): IssuesProcessorBuilder { - return this.onlyLabels(''); - } - - emptyOnlyIssueLabels(): IssuesProcessorBuilder { - return this.onlyIssueLabels(''); - } - - emptyOnlyPrLabels(): IssuesProcessorBuilder { - return this.onlyPrLabels(''); - } - - 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; - } - - prs(issues: Partial[]): IssuesProcessorBuilder { - this.issuesOrPrs( - issues.map((issue: Readonly>): Partial => { - return { - ...issue, - pull_request: {key: 'value'} - }; - }) - ); - - return this; - } - - build(): IssuesProcessorMock { - return new IssuesProcessorMock( - this._options, - async p => (p === 1 ? this._issues : []), - async () => [], - 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 {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; + +describe('only-labels options', (): void => { + beforeEach((): void => { + issuesProcessorBuilder = new IssuesProcessorBuilder(); + }); + + test('should stale when not set even if the issue has no label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .emptyOnlyIssueLabels() + .issuesOrPrs([{labels: []}]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); + + test('should stale when not set even if the issue has a label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .emptyOnlyIssueLabels() + .issuesOrPrs([{labels: [{name: 'label'}]}]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); + + test('should not stale when set and the issue has no label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label') + .issuesOrPrs([{labels: []}]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should not stale when set and the issue has a different label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label') + .issuesOrPrs([ + { + labels: [ + { + name: 'label' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should not stale when set and the issue has different labels', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label') + .issuesOrPrs([ + { + labels: [ + { + name: 'label-1' + }, + { + name: 'label-2' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should stale when set and the issue has the same label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label') + .issuesOrPrs([ + { + labels: [ + { + name: 'dummy-label' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); + + test('should not stale when set and the issue has only one of the same label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label-1,dummy-label-2') + .issuesOrPrs([ + { + labels: [ + { + name: 'dummy-label-1' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should stale when set and the issue has all the same labels', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label-1,dummy-label-2') + .issuesOrPrs([ + { + labels: [ + { + name: 'dummy-label-1' + }, + { + name: 'dummy-label-2' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); +}); + +describe('only-issue-labels option', (): void => { + beforeEach((): void => { + issuesProcessorBuilder = new IssuesProcessorBuilder(); + }); + + test('should stale when not set even if the issue has no label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .emptyOnlyIssueLabels() + .issues([{labels: []}]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); + + test('should stale when not set even if the issue has a label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .emptyOnlyIssueLabels() + .issues([{labels: [{name: 'dummy-label'}]}]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); + + test('should not stale when set and the issue has no label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label') + .issues([{labels: []}]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should not stale when set and the issue has a different label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label') + .issues([ + { + labels: [ + { + name: 'label' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should not stale when set and the issue has different labels', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label') + .issues([ + { + labels: [ + { + name: 'label-1' + }, + { + name: 'label-2' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should stale when set and the issue has the same label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label') + .issues([ + { + labels: [ + { + name: 'dummy-label' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); + + test('should not stale when set and the issue has only one of the same label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label-1,dummy-label-2') + .issues([ + { + labels: [ + { + name: 'dummy-label-1' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should stale when set and the issue has all the same labels', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyIssueLabels('dummy-label-1,dummy-label-2') + .issues([ + { + labels: [ + { + name: 'dummy-label-1' + }, + { + name: 'dummy-label-2' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); +}); + +describe('only-pr-labels option', (): void => { + beforeEach((): void => { + issuesProcessorBuilder = new IssuesProcessorBuilder(); + }); + + test('should stale when not set even if the pr has no label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .emptyOnlyPrLabels() + .prs([{labels: []}]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); + + test('should stale when not set even if the pr has a label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .emptyOnlyPrLabels() + .prs([{labels: [{name: 'dummy-label'}]}]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); + + test('should not stale when set and the pr has no label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyPrLabels('dummy-label') + .prs([{labels: []}]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should not stale when set and the pr has a different label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyPrLabels('dummy-label') + .prs([ + { + labels: [ + { + name: 'label' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should not stale when set and the pr has different labels', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyPrLabels('dummy-label') + .prs([ + { + labels: [ + { + name: 'label-1' + }, + { + name: 'label-2' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should stale when set and the pr has the same label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyPrLabels('dummy-label') + .prs([ + { + labels: [ + { + name: 'dummy-label' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); + + test('should not stale when set and the pr has only one of the same label', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyPrLabels('dummy-label-1,dummy-label-2') + .prs([ + { + labels: [ + { + name: 'dummy-label-1' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(0); + }); + + test('should stale when set and the pr has all the same labels', async (): Promise => { + expect.assertions(1); + issuesProcessor = issuesProcessorBuilder + .onlyPrLabels('dummy-label-1,dummy-label-2') + .prs([ + { + labels: [ + { + name: 'dummy-label-1' + }, + { + name: 'dummy-label-2' + } + ] + } + ]) + .build(); + + await issuesProcessor.processIssues(); + + expect(issuesProcessor.staleIssues).toHaveLength(1); + }); +}); + +class IssuesProcessorBuilder { + private _options: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 0 + }; + private _issues: Issue[] = []; + + onlyIssueLabels(labels: string): IssuesProcessorBuilder { + this._options.onlyIssueLabels = labels; + + return this; + } + + onlyPrLabels(labels: string): IssuesProcessorBuilder { + this._options.onlyPrLabels = labels; + + return this; + } + + emptyOnlyIssueLabels(): IssuesProcessorBuilder { + return this.onlyIssueLabels(''); + } + + emptyOnlyPrLabels(): IssuesProcessorBuilder { + return this.onlyPrLabels(''); + } + + 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; + } + + prs(issues: Partial[]): IssuesProcessorBuilder { + this.issuesOrPrs( + issues.map((issue: Readonly>): Partial => { + return { + ...issue, + pull_request: {key: 'value'} + }; + }) + ); + + return this; + } + + build(): IssuesProcessorMock { + return new IssuesProcessorMock( + this._options, + async p => (p === 1 ? this._issues : []), + async () => [], + async () => new Date().toDateString() + ); + } +} diff --git a/action.yml b/action.yml index 3b229059..36c2fcc6 100644 --- a/action.yml +++ b/action.yml @@ -76,16 +76,12 @@ inputs: description: 'Exempt all pull requests with milestones from being marked as stale. Default to false.' default: 'false' required: false - only-labels: - description: 'Only issues or pull requests with all of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels.' - default: '' - required: false any-of-issue-labels: - description: 'Only issues with at least one of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels.' + description: 'Only issues with all of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels.' default: '' required: false any-of-pr-labels: - description: 'Only pull requests with at least one of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels.' + description: 'Only pull requests with all of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels.' default: '' required: false only-issue-labels: diff --git a/dist/index.js b/dist/index.js index 7729abd8..ab00b6de 100644 --- a/dist/index.js +++ b/dist/index.js @@ -293,24 +293,24 @@ exports.IssuesProcessor = void 0; const core = __importStar(__nccwpck_require__(2186)); const github_1 = __nccwpck_require__(5438); const option_1 = __nccwpck_require__(5931); +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 clean_label_1 = __nccwpck_require__(7752); const should_mark_when_stale_1 = __nccwpck_require__(2461); const words_to_list_1 = __nccwpck_require__(1883); +const logger_service_1 = __nccwpck_require__(1973); const assignees_1 = __nccwpck_require__(7236); -const ignore_updates_1 = __nccwpck_require__(2935); const exempt_draft_pull_request_1 = __nccwpck_require__(854); +const ignore_updates_1 = __nccwpck_require__(2935); const issue_1 = __nccwpck_require__(4783); const issue_logger_1 = __nccwpck_require__(2984); const logger_1 = __nccwpck_require__(6212); const milestones_1 = __nccwpck_require__(4601); const stale_operations_1 = __nccwpck_require__(5080); const statistics_1 = __nccwpck_require__(3334); -const logger_service_1 = __nccwpck_require__(1973); /*** * Handle processing of issues for staleness/closure. */ @@ -423,7 +423,7 @@ class IssuesProcessor { } const onlyLabels = words_to_list_1.wordsToList(this._getOnlyLabels(issue)); if (onlyLabels.length > 0) { - issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.OnlyLabels)} was specified to only process issues and pull requests with all those labels (${logger_service_1.LoggerService.cyan(onlyLabels.length)})`); + issueLogger.info(`The option ${issueLogger.createOptionLink(issue.isPullRequest ? option_1.Option.OnlyPrLabels : option_1.Option.OnlyIssueLabels)} was specified to only process issues and pull requests with all those labels (${logger_service_1.LoggerService.cyan(onlyLabels.length)})`); const hasAllWhitelistedLabels = onlyLabels.every((label) => { return is_labeled_1.isLabeled(issue, label); }); @@ -438,7 +438,7 @@ class IssuesProcessor { } } else { - issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.OnlyLabels)} was not specified`); + issueLogger.info(`The option ${issueLogger.createOptionLink(issue.isPullRequest ? option_1.Option.OnlyPrLabels : option_1.Option.OnlyIssueLabels)} was not specified`); issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); } issueLogger.info(`Days before $$type stale: ${logger_service_1.LoggerService.cyan(daysBeforeStale)}`); @@ -912,16 +912,9 @@ class IssuesProcessor { } _getOnlyLabels(issue) { if (issue.isPullRequest) { - if (this.options.onlyPrLabels !== '') { - return this.options.onlyPrLabels; - } + return this.options.onlyPrLabels; } - else { - if (this.options.onlyIssueLabels !== '') { - return this.options.onlyIssueLabels; - } - } - return this.options.onlyLabels; + return this.options.onlyIssueLabels; } _getAnyOfLabels(issue) { if (issue.isPullRequest) { @@ -1764,7 +1757,6 @@ var Option; Option["StalePrLabel"] = "stale-pr-label"; Option["ClosePrLabel"] = "close-pr-label"; Option["ExemptPrLabels"] = "exempt-pr-labels"; - Option["OnlyLabels"] = "only-labels"; Option["OnlyIssueLabels"] = "only-issue-labels"; Option["OnlyPrLabels"] = "only-pr-labels"; Option["AnyOfIssueLabels"] = "any-of-issue-labels"; @@ -2067,7 +2059,6 @@ function _getAndValidateArgs() { stalePrLabel: core.getInput('stale-pr-label', { required: true }), closePrLabel: core.getInput('close-pr-label'), exemptPrLabels: core.getInput('exempt-pr-labels'), - onlyLabels: core.getInput('only-labels'), onlyIssueLabels: core.getInput('only-issue-labels'), onlyPrLabels: core.getInput('only-pr-labels'), anyOfIssueLabels: core.getInput('any-of-issue-labels'), diff --git a/src/classes/issue.spec.ts b/src/classes/issue.spec.ts index b89a3427..84e1f882 100644 --- a/src/classes/issue.spec.ts +++ b/src/classes/issue.spec.ts @@ -27,7 +27,6 @@ describe('Issue', (): void => { deleteBranch: false, exemptIssueLabels: '', exemptPrLabels: '', - onlyLabels: '', onlyIssueLabels: '', onlyPrLabels: '', anyOfIssueLabels: '', diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 5109f026..1a4f3e0f 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -3,29 +3,29 @@ import {context, getOctokit} from '@actions/github'; import {GitHub} from '@actions/github/lib/utils'; import {GetResponseTypeFromEndpointMethod} from '@octokit/types'; import {Option} from '../enums/option'; +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 {cleanLabel} from '../functions/clean-label'; import {shouldMarkWhenStale} from '../functions/should-mark-when-stale'; import {wordsToList} from '../functions/words-to-list'; import {IComment} from '../interfaces/comment'; +import {IIssue} from '../interfaces/issue'; import {IIssueEvent} from '../interfaces/issue-event'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {IPullRequest} from '../interfaces/pull-request'; +import {LoggerService} from '../services/logger.service'; import {Assignees} from './assignees'; -import {IgnoreUpdates} from './ignore-updates'; import {ExemptDraftPullRequest} from './exempt-draft-pull-request'; +import {IgnoreUpdates} from './ignore-updates'; import {Issue} from './issue'; import {IssueLogger} from './loggers/issue-logger'; import {Logger} from './loggers/logger'; import {Milestones} from './milestones'; import {StaleOperations} from './stale-operations'; import {Statistics} from './statistics'; -import {LoggerService} from '../services/logger.service'; -import {IIssue} from '../interfaces/issue'; /*** * Handle processing of issues for staleness/closure. @@ -227,7 +227,7 @@ export class IssuesProcessor { if (onlyLabels.length > 0) { issueLogger.info( `The option ${issueLogger.createOptionLink( - Option.OnlyLabels + issue.isPullRequest ? Option.OnlyPrLabels : Option.OnlyIssueLabels )} was specified to only process issues and pull requests with all those labels (${LoggerService.cyan( onlyLabels.length )})` @@ -260,7 +260,7 @@ export class IssuesProcessor { } else { issueLogger.info( `The option ${issueLogger.createOptionLink( - Option.OnlyLabels + issue.isPullRequest ? Option.OnlyPrLabels : Option.OnlyIssueLabels )} was not specified` ); issueLogger.info( @@ -983,16 +983,10 @@ export class IssuesProcessor { private _getOnlyLabels(issue: Issue): string { if (issue.isPullRequest) { - if (this.options.onlyPrLabels !== '') { - return this.options.onlyPrLabels; - } - } else { - if (this.options.onlyIssueLabels !== '') { - return this.options.onlyIssueLabels; - } + return this.options.onlyPrLabels; } - return this.options.onlyLabels; + return this.options.onlyIssueLabels; } private _getAnyOfLabels(issue: Issue): string { diff --git a/src/enums/option.ts b/src/enums/option.ts index ec28e937..96f5d4f7 100644 --- a/src/enums/option.ts +++ b/src/enums/option.ts @@ -16,7 +16,6 @@ export enum Option { StalePrLabel = 'stale-pr-label', ClosePrLabel = 'close-pr-label', ExemptPrLabels = 'exempt-pr-labels', - OnlyLabels = 'only-labels', OnlyIssueLabels = 'only-issue-labels', OnlyPrLabels = 'only-pr-labels', AnyOfIssueLabels = 'any-of-issue-labels', diff --git a/src/interfaces/issues-processor-options.ts b/src/interfaces/issues-processor-options.ts index fdc7138d..2db3abb7 100644 --- a/src/interfaces/issues-processor-options.ts +++ b/src/interfaces/issues-processor-options.ts @@ -18,7 +18,6 @@ export interface IIssuesProcessorOptions { stalePrLabel: string; closePrLabel: string; exemptPrLabels: string; - onlyLabels: string; onlyIssueLabels: string; onlyPrLabels: string; anyOfIssueLabels: string; diff --git a/src/main.ts b/src/main.ts index 1fb6bf39..c930af0b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -44,7 +44,6 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { stalePrLabel: core.getInput('stale-pr-label', {required: true}), closePrLabel: core.getInput('close-pr-label'), exemptPrLabels: core.getInput('exempt-pr-labels'), - onlyLabels: core.getInput('only-labels'), onlyIssueLabels: core.getInput('only-issue-labels'), onlyPrLabels: core.getInput('only-pr-labels'), anyOfIssueLabels: core.getInput('any-of-issue-labels'),