From 043fbbdea3e060a5aa2949408ad8e4b52988f420 Mon Sep 17 00:00:00 2001 From: Geoffrey Testelin Date: Wed, 28 Apr 2021 22:39:28 +0200 Subject: [PATCH] feat(logs): enhance the logs for assignees and milestones (#382) * docs(only-labels): enhance the docs and fix duplicate (#341) * docs(only-labels): remove duplicated option and improve descriptions a bad rebase happend * docs(readme): use a multi-line array and remove the optional column the option column was not helpful since each value is optional the multi-line array will allow to have a better UI in small devices and basically in GitHub too due to the max-width * style(readme): break line for the statistics * docs(readme): add a better description for the ascending option * docs(action): add missing punctuation * build(deps-dev): bump @typescript-eslint/eslint-plugin (#342) Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 4.15.2 to 4.16.1. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.16.1/packages/eslint-plugin) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump @octokit/rest from 18.3.0 to 18.3.2 (#350) Bumps [@octokit/rest](https://github.com/octokit/rest.js) from 18.3.0 to 18.3.2. - [Release notes](https://github.com/octokit/rest.js/releases) - [Commits](https://github.com/octokit/rest.js/compare/v18.3.0...v18.3.2) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * test: add more coverage for the stale label behaviour (#352) (#15) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * test: add more coverage for the stale label behaviour (#352) (#17) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * test: add more coverage for the stale label behaviour (#352) (#18) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(logs): enhance the logs for assignees and milestones closes #381 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dist/index.js | 88 +++++----- src/classes/assignees.spec.ts | 301 ++++++++++++++++++++++++++++++--- src/classes/assignees.ts | 84 ++++++--- src/classes/milestones.spec.ts | 284 ++++++++++++++++++++++++++++--- src/classes/milestones.ts | 86 +++++++--- 5 files changed, 707 insertions(+), 136 deletions(-) diff --git a/dist/index.js b/dist/index.js index 965191e9..11c43e49 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12,7 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Assignees = void 0; +const chalk_1 = __importDefault(__nccwpck_require__(8818)); const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601)); +const option_1 = __nccwpck_require__(5931); const words_to_list_1 = __nccwpck_require__(1883); const issue_logger_1 = __nccwpck_require__(2984); class Assignees { @@ -31,23 +33,23 @@ class Assignees { return false; } if (this._shouldExemptAllAssignees()) { - this._issueLogger.info('Skipping $$type because it has an exempt assignee'); + this._issueLogger.info(chalk_1.default.white('└──'), 'Skipping $$type because it has an exempt assignee'); return true; } const exemptAssignees = this._getExemptAssignees(); if (exemptAssignees.length === 0) { - this._issueLogger.info(`No assignee option was specified to skip the stale process for this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `No assignee option was specified to skip the stale process for this $$type`); this._logSkip(); return false; } - this._issueLogger.info(`Found ${exemptAssignees.length} assignee${exemptAssignees.length > 1 ? 's' : ''} that can exempt stale on this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `Found ${chalk_1.default.cyan(exemptAssignees.length)} assignee${exemptAssignees.length > 1 ? 's' : ''} that can exempt stale on this $$type`); const hasExemptAssignee = exemptAssignees.some((exemptAssignee) => this._hasAssignee(exemptAssignee)); if (!hasExemptAssignee) { - this._issueLogger.info('No assignee on this $$type can exempt the stale process'); + this._issueLogger.info(chalk_1.default.white('├──'), 'No assignee on this $$type can exempt the stale process'); this._logSkip(); } else { - this._issueLogger.info('Skipping this $$type because it has an exempt assignee'); + this._issueLogger.info(chalk_1.default.white('└──'), 'Skipping this $$type because it has an exempt assignee'); } return hasExemptAssignee; } @@ -58,32 +60,32 @@ class Assignees { } _getExemptIssueAssignees() { if (this._options.exemptIssueAssignees === '') { - this._issueLogger.info('The option "exemptIssueAssignees" is disabled. No specific assignee can skip the stale process for this $$type'); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); if (this._options.exemptAssignees === '') { - this._issueLogger.info('The option "exemptAssignees" is disabled. No specific assignee can skip the stale process for this $$type'); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); return []; } const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptAssignees); - this._issueLogger.info(`The option "exemptAssignees" is set. ${exemptAssignees.length} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is set. ${chalk_1.default.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); return exemptAssignees; } const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptIssueAssignees); - this._issueLogger.info(`The option "exemptIssueAssignees" is set. ${exemptAssignees.length} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueAssignees)} is set. ${chalk_1.default.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); return exemptAssignees; } _getExemptPullRequestAssignees() { if (this._options.exemptPrAssignees === '') { - this._issueLogger.info('The option "exemptPrAssignees" is disabled. No specific assignee can skip the stale process for this $$type'); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); if (this._options.exemptAssignees === '') { - this._issueLogger.info('The option "exemptAssignees" is disabled. No specific assignee can skip the stale process for this $$type'); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); return []; } const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptAssignees); - this._issueLogger.info(`The option "exemptAssignees" is set. ${exemptAssignees.length} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is set. ${chalk_1.default.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); return exemptAssignees; } const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptPrAssignees); - this._issueLogger.info(`The option "exemptPrAssignees" is set. ${exemptAssignees.length} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrAssignees)} is set. ${chalk_1.default.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); return exemptAssignees; } _hasAssignee(assignee) { @@ -91,7 +93,7 @@ class Assignees { return this._issue.assignees.some((issueAssignee) => { const isSameAssignee = cleanAssignee === Assignees._cleanAssignee(issueAssignee.login); if (isSameAssignee) { - this._issueLogger.info(`@${issueAssignee.login} is assigned on this $$type and is an exempt assignee`); + this._issueLogger.info(chalk_1.default.white('├──'), `@${issueAssignee.login} is assigned on this $$type and is an exempt assignee`); } return isSameAssignee; }); @@ -103,11 +105,11 @@ class Assignees { } _shouldExemptAllIssueAssignees() { if (this._options.exemptAllIssueAssignees === true) { - this._issueLogger.info('The option "exemptAllIssueAssignees" is enabled. Any assignee on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueAssignees)} is enabled. Any assignee on this $$type will skip the stale process`); return true; } else if (this._options.exemptAllIssueAssignees === false) { - this._issueLogger.info('The option "exemptAllIssueAssignees" is disabled. Only some specific assignees on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueAssignees)} is disabled. Only some specific assignees on this $$type will skip the stale process`); return false; } this._logExemptAllAssigneesOption(); @@ -115,11 +117,11 @@ class Assignees { } _shouldExemptAllPullRequestAssignees() { if (this._options.exemptAllPrAssignees === true) { - this._issueLogger.info('The option "exemptAllPrAssignees" is enabled. Any assignee on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrAssignees)} is enabled. Any assignee on this $$type will skip the stale process`); return true; } else if (this._options.exemptAllPrAssignees === false) { - this._issueLogger.info('The option "exemptAllPrAssignees" is disabled. Only some specific assignees on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrAssignees)} is disabled. Only some specific assignees on this $$type will skip the stale process`); return false; } this._logExemptAllAssigneesOption(); @@ -127,14 +129,14 @@ class Assignees { } _logExemptAllAssigneesOption() { if (this._options.exemptAllAssignees) { - this._issueLogger.info('The option "exemptAllAssignees" is enabled. Any assignee on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllAssignees)} is enabled. Any assignee on this $$type will skip the stale process`); } else { - this._issueLogger.info('The option "exemptAllAssignees" is disabled. Only some specific assignees on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllAssignees)} is disabled. Only some specific assignees on this $$type will skip the stale process`); } } _logSkip() { - this._issueLogger.info('Skip the assignees checks'); + this._issueLogger.info(chalk_1.default.white('└──'), 'Skip the assignees checks'); } } exports.Assignees = Assignees; @@ -955,7 +957,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Milestones = void 0; +const chalk_1 = __importDefault(__nccwpck_require__(8818)); const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601)); +const option_1 = __nccwpck_require__(5931); const words_to_list_1 = __nccwpck_require__(1883); const issue_logger_1 = __nccwpck_require__(2984); class Milestones { @@ -974,23 +978,23 @@ class Milestones { return false; } if (this._shouldExemptAllMilestones()) { - this._issueLogger.info('Skipping $$type because it has an exempt milestone'); + this._issueLogger.info(chalk_1.default.white('└──'), 'Skipping $$type because it has a milestone'); return true; } const exemptMilestones = this._getExemptMilestones(); if (exemptMilestones.length === 0) { - this._issueLogger.info(`No milestone option was specified to skip the stale process for this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `No milestone option was specified to skip the stale process for this $$type`); this._logSkip(); return false; } - this._issueLogger.info(`Found ${exemptMilestones.length} milestone${exemptMilestones.length > 1 ? 's' : ''} that can exempt stale on this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `Found ${chalk_1.default.cyan(exemptMilestones.length)} milestone${exemptMilestones.length > 1 ? 's' : ''} that can exempt stale on this $$type`); const hasExemptMilestone = exemptMilestones.some((exemptMilestone) => this._hasMilestone(exemptMilestone)); if (!hasExemptMilestone) { - this._issueLogger.info('No milestone on this $$type can exempt the stale process'); + this._issueLogger.info(chalk_1.default.white('├──'), 'No milestone on this $$type can exempt the stale process'); this._logSkip(); } else { - this._issueLogger.info('Skipping this $$type because it has an exempt milestone'); + this._issueLogger.info(chalk_1.default.white('└──'), 'Skipping this $$type because it has an exempt milestone'); } return hasExemptMilestone; } @@ -1001,32 +1005,32 @@ class Milestones { } _getExemptIssueMilestones() { if (this._options.exemptIssueMilestones === '') { - this._issueLogger.info('The option "exemptIssueMilestones" is disabled. No specific milestone can skip the stale process for this $$type'); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); if (this._options.exemptMilestones === '') { - this._issueLogger.info('The option "exemptMilestones" is disabled. No specific milestone can skip the stale process for this $$type'); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); return []; } const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptMilestones); - this._issueLogger.info(`The option "exemptMilestones" is set. ${exemptMilestones.length} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is set. ${chalk_1.default.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); return exemptMilestones; } const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptIssueMilestones); - this._issueLogger.info(`The option "exemptIssueMilestones" is set. ${exemptMilestones.length} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueMilestones)} is set. ${chalk_1.default.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); return exemptMilestones; } _getExemptPullRequestMilestones() { if (this._options.exemptPrMilestones === '') { - this._issueLogger.info('The option "exemptPrMilestones" is disabled. No specific milestone can skip the stale process for this $$type'); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); if (this._options.exemptMilestones === '') { - this._issueLogger.info('The option "exemptMilestones" is disabled. No specific milestone can skip the stale process for this $$type'); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); return []; } const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptMilestones); - this._issueLogger.info(`The option "exemptMilestones" is set. ${exemptMilestones.length} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is set. ${chalk_1.default.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); return exemptMilestones; } const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptPrMilestones); - this._issueLogger.info(`The option "exemptPrMilestones" is set. ${exemptMilestones.length} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(chalk_1.default.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrMilestones)} is set. ${chalk_1.default.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); return exemptMilestones; } _hasMilestone(milestone) { @@ -1037,7 +1041,7 @@ class Milestones { const isSameMilestone = cleanMilestone === Milestones._cleanMilestone(this._issue.milestone.title); if (isSameMilestone) { - this._issueLogger.info(`The milestone "${milestone}" is set on this $$type and is an exempt milestone`); + this._issueLogger.info(chalk_1.default.white('├──'), `The milestone "${milestone}" is set on this $$type and is an exempt milestone`); } return isSameMilestone; } @@ -1051,11 +1055,11 @@ class Milestones { } _shouldExemptAllIssueMilestones() { if (this._options.exemptAllIssueMilestones === true) { - this._issueLogger.info('The option "exemptAllIssueMilestones" is enabled. Any milestone on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueMilestones)} is enabled. Any milestone on this $$type will skip the stale process`); return true; } else if (this._options.exemptAllIssueMilestones === false) { - this._issueLogger.info('The option "exemptAllIssueMilestones" is disabled. Only some specific milestones on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueMilestones)} is disabled. Only some specific milestones on this $$type will skip the stale process`); return false; } this._logExemptAllMilestonesOption(); @@ -1063,11 +1067,11 @@ class Milestones { } _shouldExemptAllPullRequestMilestones() { if (this._options.exemptAllPrMilestones === true) { - this._issueLogger.info('The option "exemptAllPrMilestones" is enabled. Any milestone on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrMilestones)} is enabled. Any milestone on this $$type will skip the stale process`); return true; } else if (this._options.exemptAllPrMilestones === false) { - this._issueLogger.info('The option "exemptAllPrMilestones" is disabled. Only some specific milestones on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrMilestones)} is disabled. Only some specific milestones on this $$type will skip the stale process`); return false; } this._logExemptAllMilestonesOption(); @@ -1075,14 +1079,14 @@ class Milestones { } _logExemptAllMilestonesOption() { if (this._options.exemptAllMilestones) { - this._issueLogger.info('The option "exemptAllMilestones" is enabled. Any milestone on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllMilestones)} is enabled. Any milestone on this $$type will skip the stale process`); } else { - this._issueLogger.info('The option "exemptAllMilestones" is disabled. Only some specific milestones on this $$type will skip the stale process'); + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllMilestones)} is disabled. Only some specific milestones on this $$type will skip the stale process`); } } _logSkip() { - this._issueLogger.info('Skip the milestones checks'); + this._issueLogger.info(chalk_1.default.white('└──'), 'Skip the milestones checks'); } } exports.Milestones = Milestones; diff --git a/src/classes/assignees.spec.ts b/src/classes/assignees.spec.ts index 26b689d1..d40bacc1 100644 --- a/src/classes/assignees.spec.ts +++ b/src/classes/assignees.spec.ts @@ -2,8 +2,8 @@ import {DefaultProcessorOptions} from '../../__tests__/constants/default-process import {generateIIssue} from '../../__tests__/functions/generate-iissue'; import {IIssue} from '../interfaces/issue'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; -import {Issue} from './issue'; import {Assignees} from './assignees'; +import {Issue} from './issue'; describe('Assignees', (): void => { let assignees: Assignees; @@ -12,7 +12,10 @@ describe('Assignees', (): void => { let issueInterface: IIssue; beforeEach((): void => { - optionsInterface = {...DefaultProcessorOptions}; + optionsInterface = { + ...DefaultProcessorOptions, + exemptAllAssignees: false + }; issueInterface = generateIIssue(); }); @@ -303,21 +306,51 @@ describe('Assignees', (): void => { }); }); }); - }); - describe('when the given issue is a pull request', (): void => { - beforeEach((): void => { - issueInterface.pull_request = {}; - }); - - describe('when the given options are not configured to exempt an assignee', (): void => { + describe('when the given options are configured to exempt all assignees', (): void => { beforeEach((): void => { - optionsInterface.exemptAssignees = ''; + optionsInterface.exemptAllAssignees = true; }); - describe('when the given options are not configured to exempt a pull request with an assignee', (): void => { + describe('when the given issue does not have an assignee', (): void => { beforeEach((): void => { - optionsInterface.exemptPrAssignees = ''; + issueInterface.assignees = []; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given issue does have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = [ + { + login: 'dummy-exempt-assignee' + } + ]; + }); + + it('should return true', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(true); + }); + }); + + describe('when the given options are not configured to exempt all issue assignees', (): void => { + beforeEach((): void => { + optionsInterface.exemptAllIssueAssignees = false; }); describe('when the given issue does not have an assignee', (): void => { @@ -337,6 +370,102 @@ describe('Assignees', (): void => { }); describe('when the given issue does have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = [ + { + login: 'dummy-exempt-assignee' + } + ]; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(false); + }); + }); + }); + + describe('when the given options are configured to exempt all issue assignees', (): void => { + beforeEach((): void => { + optionsInterface.exemptAllIssueAssignees = true; + }); + + describe('when the given issue does not have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = []; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given issue does have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = [ + { + login: 'dummy-exempt-issue-assignee' + } + ]; + }); + + it('should return true', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(true); + }); + }); + }); + }); + }); + + describe('when the given issue is a pull request', (): void => { + beforeEach((): void => { + issueInterface.pull_request = {}; + }); + + describe('when the given options are not configured to exempt an assignee', (): void => { + beforeEach((): void => { + optionsInterface.exemptAssignees = ''; + }); + + describe('when the given options are not configured to exempt a pull request with an assignee', (): void => { + beforeEach((): void => { + optionsInterface.exemptPrAssignees = ''; + }); + + describe('when the given pull request does not have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = []; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given pull request does have an assignee', (): void => { beforeEach((): void => { issueInterface.assignees = [ { @@ -362,7 +491,7 @@ describe('Assignees', (): void => { optionsInterface.exemptPrAssignees = 'dummy-exempt-pr-assignee'; }); - describe('when the given issue does not have an assignee', (): void => { + describe('when the given pull request does not have an assignee', (): void => { beforeEach((): void => { issueInterface.assignees = []; }); @@ -378,7 +507,7 @@ describe('Assignees', (): void => { }); }); - describe('when the given issue does have an assignee different than the exempt pull request assignee', (): void => { + describe('when the given pull request does have an assignee different than the exempt pull request assignee', (): void => { beforeEach((): void => { issueInterface.assignees = [ { @@ -398,7 +527,7 @@ describe('Assignees', (): void => { }); }); - describe('when the given issue does have an assignee equaling the exempt pull request assignee', (): void => { + describe('when the given pull request does have an assignee equaling the exempt pull request assignee', (): void => { beforeEach((): void => { issueInterface.assignees = [ { @@ -430,7 +559,7 @@ describe('Assignees', (): void => { optionsInterface.exemptPrAssignees = ''; }); - describe('when the given issue does not have an assignee', (): void => { + describe('when the given pull request does not have an assignee', (): void => { beforeEach((): void => { issueInterface.assignees = []; }); @@ -446,7 +575,7 @@ describe('Assignees', (): void => { }); }); - describe('when the given issue does have an assignee different than the exempt assignee', (): void => { + describe('when the given pull request does have an assignee different than the exempt assignee', (): void => { beforeEach((): void => { issueInterface.assignees = [ { @@ -466,7 +595,7 @@ describe('Assignees', (): void => { }); }); - describe('when the given issue does have an assignee equaling the exempt assignee', (): void => { + describe('when the given pull request does have an assignee equaling the exempt assignee', (): void => { beforeEach((): void => { issueInterface.assignees = [ { @@ -492,7 +621,7 @@ describe('Assignees', (): void => { optionsInterface.exemptPrAssignees = 'dummy-exempt-pr-assignee'; }); - describe('when the given issue does not have an assignee', (): void => { + describe('when the given pull request does not have an assignee', (): void => { beforeEach((): void => { issueInterface.assignees = []; }); @@ -508,7 +637,7 @@ describe('Assignees', (): void => { }); }); - describe('when the given issue does have an assignee different than the exempt pull request assignee', (): void => { + describe('when the given pull request does have an assignee different than the exempt pull request assignee', (): void => { beforeEach((): void => { issueInterface.assignees = [ { @@ -528,7 +657,7 @@ describe('Assignees', (): void => { }); }); - describe('when the given issue does have an assignee equaling the exempt pull request assignee', (): void => { + describe('when the given pull request does have an assignee equaling the exempt pull request assignee', (): void => { beforeEach((): void => { issueInterface.assignees = [ { @@ -548,7 +677,7 @@ describe('Assignees', (): void => { }); }); - describe('when the given issue does have an assignee different than the exempt assignee', (): void => { + describe('when the given pull request does have an assignee different than the exempt assignee', (): void => { beforeEach((): void => { issueInterface.assignees = [ { @@ -568,7 +697,7 @@ describe('Assignees', (): void => { }); }); - describe('when the given issue does have an assignee equaling the exempt assignee', (): void => { + describe('when the given pull request does have an assignee equaling the exempt assignee', (): void => { beforeEach((): void => { issueInterface.assignees = [ { @@ -589,6 +718,132 @@ describe('Assignees', (): void => { }); }); }); + + describe('when the given options are configured to exempt all assignees', (): void => { + beforeEach((): void => { + optionsInterface.exemptAllAssignees = true; + }); + + describe('when the given pull request does not have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = []; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given pull request does have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = [ + { + login: 'dummy-exempt-assignee' + } + ]; + }); + + it('should return true', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(true); + }); + }); + + describe('when the given options are not configured to exempt all pull request assignees', (): void => { + beforeEach((): void => { + optionsInterface.exemptAllPrAssignees = false; + }); + + describe('when the given pull request does not have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = []; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given pull request does have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = [ + { + login: 'dummy-exempt-assignee' + } + ]; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(false); + }); + }); + }); + + describe('when the given options are configured to exempt all pull request assignees', (): void => { + beforeEach((): void => { + optionsInterface.exemptAllPrAssignees = true; + }); + + describe('when the given pull request does not have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = []; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given pull request does have an assignee', (): void => { + beforeEach((): void => { + issueInterface.assignees = [ + { + login: 'dummy-exempt-issue-assignee' + } + ]; + }); + + it('should return true', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + assignees = new Assignees(optionsInterface, issue); + + const result = assignees.shouldExemptAssignees(); + + expect(result).toStrictEqual(true); + }); + }); + }); + }); }); }); }); diff --git a/src/classes/assignees.ts b/src/classes/assignees.ts index 5c0c8b2d..ce9cb11b 100644 --- a/src/classes/assignees.ts +++ b/src/classes/assignees.ts @@ -1,4 +1,6 @@ +import chalk from 'chalk'; import deburr from 'lodash.deburr'; +import {Option} from '../enums/option'; import {wordsToList} from '../functions/words-to-list'; import {IAssignee} from '../interfaces/assignee'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; @@ -32,6 +34,7 @@ export class Assignees { if (this._shouldExemptAllAssignees()) { this._issueLogger.info( + chalk.white('└──'), 'Skipping $$type because it has an exempt assignee' ); @@ -42,6 +45,7 @@ export class Assignees { if (exemptAssignees.length === 0) { this._issueLogger.info( + chalk.white('├──'), `No assignee option was specified to skip the stale process for this $$type` ); this._logSkip(); @@ -50,7 +54,8 @@ export class Assignees { } this._issueLogger.info( - `Found ${exemptAssignees.length} assignee${ + chalk.white('├──'), + `Found ${chalk.cyan(exemptAssignees.length)} assignee${ exemptAssignees.length > 1 ? 's' : '' } that can exempt stale on this $$type` ); @@ -62,11 +67,13 @@ export class Assignees { if (!hasExemptAssignee) { this._issueLogger.info( + chalk.white('├──'), 'No assignee on this $$type can exempt the stale process' ); this._logSkip(); } else { this._issueLogger.info( + chalk.white('└──'), 'Skipping this $$type because it has an exempt assignee' ); } @@ -83,12 +90,18 @@ export class Assignees { private _getExemptIssueAssignees(): string[] { if (this._options.exemptIssueAssignees === '') { this._issueLogger.info( - 'The option "exemptIssueAssignees" is disabled. No specific assignee can skip the stale process for this $$type' + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptIssueAssignees + )} is disabled. No specific assignee can skip the stale process for this $$type` ); if (this._options.exemptAssignees === '') { this._issueLogger.info( - 'The option "exemptAssignees" is disabled. No specific assignee can skip the stale process for this $$type' + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAssignees + )} is disabled. No specific assignee can skip the stale process for this $$type` ); return []; @@ -99,9 +112,10 @@ export class Assignees { ); this._issueLogger.info( - `The option "exemptAssignees" is set. ${ - exemptAssignees.length - } assignee${ + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAssignees + )} is set. ${chalk.cyan(exemptAssignees.length)} assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -114,9 +128,10 @@ export class Assignees { ); this._issueLogger.info( - `The option "exemptIssueAssignees" is set. ${ - exemptAssignees.length - } assignee${ + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptIssueAssignees + )} is set. ${chalk.cyan(exemptAssignees.length)} assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -127,12 +142,18 @@ export class Assignees { private _getExemptPullRequestAssignees(): string[] { if (this._options.exemptPrAssignees === '') { this._issueLogger.info( - 'The option "exemptPrAssignees" is disabled. No specific assignee can skip the stale process for this $$type' + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptPrAssignees + )} is disabled. No specific assignee can skip the stale process for this $$type` ); if (this._options.exemptAssignees === '') { this._issueLogger.info( - 'The option "exemptAssignees" is disabled. No specific assignee can skip the stale process for this $$type' + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAssignees + )} is disabled. No specific assignee can skip the stale process for this $$type` ); return []; @@ -143,9 +164,10 @@ export class Assignees { ); this._issueLogger.info( - `The option "exemptAssignees" is set. ${ - exemptAssignees.length - } assignee${ + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAssignees + )} is set. ${chalk.cyan(exemptAssignees.length)} assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -158,9 +180,10 @@ export class Assignees { ); this._issueLogger.info( - `The option "exemptPrAssignees" is set. ${ - exemptAssignees.length - } assignee${ + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptPrAssignees + )} is set. ${chalk.cyan(exemptAssignees.length)} assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -178,6 +201,7 @@ export class Assignees { if (isSameAssignee) { this._issueLogger.info( + chalk.white('├──'), `@${issueAssignee.login} is assigned on this $$type and is an exempt assignee` ); } @@ -196,13 +220,17 @@ export class Assignees { private _shouldExemptAllIssueAssignees(): boolean { if (this._options.exemptAllIssueAssignees === true) { this._issueLogger.info( - 'The option "exemptAllIssueAssignees" is enabled. Any assignee on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllIssueAssignees + )} is enabled. Any assignee on this $$type will skip the stale process` ); return true; } else if (this._options.exemptAllIssueAssignees === false) { this._issueLogger.info( - 'The option "exemptAllIssueAssignees" is disabled. Only some specific assignees on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllIssueAssignees + )} is disabled. Only some specific assignees on this $$type will skip the stale process` ); return false; @@ -216,13 +244,17 @@ export class Assignees { private _shouldExemptAllPullRequestAssignees(): boolean { if (this._options.exemptAllPrAssignees === true) { this._issueLogger.info( - 'The option "exemptAllPrAssignees" is enabled. Any assignee on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllPrAssignees + )} is enabled. Any assignee on this $$type will skip the stale process` ); return true; } else if (this._options.exemptAllPrAssignees === false) { this._issueLogger.info( - 'The option "exemptAllPrAssignees" is disabled. Only some specific assignees on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllPrAssignees + )} is disabled. Only some specific assignees on this $$type will skip the stale process` ); return false; @@ -236,16 +268,20 @@ export class Assignees { private _logExemptAllAssigneesOption(): void { if (this._options.exemptAllAssignees) { this._issueLogger.info( - 'The option "exemptAllAssignees" is enabled. Any assignee on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllAssignees + )} is enabled. Any assignee on this $$type will skip the stale process` ); } else { this._issueLogger.info( - 'The option "exemptAllAssignees" is disabled. Only some specific assignees on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllAssignees + )} is disabled. Only some specific assignees on this $$type will skip the stale process` ); } } private _logSkip(): void { - this._issueLogger.info('Skip the assignees checks'); + this._issueLogger.info(chalk.white('└──'), 'Skip the assignees checks'); } } diff --git a/src/classes/milestones.spec.ts b/src/classes/milestones.spec.ts index 91b2744d..bb87e8ff 100644 --- a/src/classes/milestones.spec.ts +++ b/src/classes/milestones.spec.ts @@ -12,7 +12,7 @@ describe('Milestones', (): void => { let issueInterface: IIssue; beforeEach((): void => { - optionsInterface = {...DefaultProcessorOptions}; + optionsInterface = {...DefaultProcessorOptions, exemptAllMilestones: false}; issueInterface = generateIIssue(); }); @@ -285,21 +285,49 @@ describe('Milestones', (): void => { }); }); }); - }); - describe('when the given issue is a pull request', (): void => { - beforeEach((): void => { - issueInterface.pull_request = {}; - }); - - describe('when the given options are not configured to exempt a milestone', (): void => { + describe('when the given options are configured to exempt all milestones', (): void => { beforeEach((): void => { - optionsInterface.exemptMilestones = ''; + optionsInterface.exemptAllMilestones = true; }); - describe('when the given options are not configured to exempt a pull request milestone', (): void => { + describe('when the given issue does not have a milestone', (): void => { beforeEach((): void => { - optionsInterface.exemptPrMilestones = ''; + issueInterface.milestone = undefined; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given issue does have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = { + title: 'dummy-exempt-issue-milestone' + }; + }); + + it('should return true', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(true); + }); + }); + + describe('when the given options are not configured to exempt all issue milestones', (): void => { + beforeEach((): void => { + optionsInterface.exemptAllIssueMilestones = false; }); describe('when the given issue does not have a milestone', (): void => { @@ -319,6 +347,98 @@ describe('Milestones', (): void => { }); describe('when the given issue does have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = { + title: 'dummy-exempt-milestone' + }; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(false); + }); + }); + }); + + describe('when the given options are configured to exempt all issue milestones', (): void => { + beforeEach((): void => { + optionsInterface.exemptAllIssueMilestones = true; + }); + + describe('when the given issue does not have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = undefined; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given issue does have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = { + title: 'dummy-exempt-issue-milestone' + }; + }); + + it('should return true', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(true); + }); + }); + }); + }); + }); + + describe('when the given issue is a pull request', (): void => { + beforeEach((): void => { + issueInterface.pull_request = {}; + }); + + describe('when the given options are not configured to exempt a milestone', (): void => { + beforeEach((): void => { + optionsInterface.exemptMilestones = ''; + }); + + describe('when the given options are not configured to exempt a pull request milestone', (): void => { + beforeEach((): void => { + optionsInterface.exemptPrMilestones = ''; + }); + + describe('when the given pull request does not have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = undefined; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given pull request does have a milestone', (): void => { beforeEach((): void => { issueInterface.milestone = { title: 'dummy-title' @@ -342,7 +462,7 @@ describe('Milestones', (): void => { optionsInterface.exemptPrMilestones = 'dummy-exempt-pr-milestone'; }); - describe('when the given issue does not have a milestone', (): void => { + describe('when the given pull request does not have a milestone', (): void => { beforeEach((): void => { issueInterface.milestone = undefined; }); @@ -358,7 +478,7 @@ describe('Milestones', (): void => { }); }); - describe('when the given issue does have a milestone different than the exempt pull request milestone', (): void => { + describe('when the given pull request does have a milestone different than the exempt pull request milestone', (): void => { beforeEach((): void => { issueInterface.milestone = { title: 'dummy-title' @@ -376,7 +496,7 @@ describe('Milestones', (): void => { }); }); - describe('when the given issue does have a milestone equaling the exempt pull request milestone', (): void => { + describe('when the given pull request does have a milestone equaling the exempt pull request milestone', (): void => { beforeEach((): void => { issueInterface.milestone = { title: 'dummy-exempt-pr-milestone' @@ -406,7 +526,7 @@ describe('Milestones', (): void => { optionsInterface.exemptPrMilestones = ''; }); - describe('when the given issue does not have a milestone', (): void => { + describe('when the given pull request does not have a milestone', (): void => { beforeEach((): void => { issueInterface.milestone = undefined; }); @@ -422,7 +542,7 @@ describe('Milestones', (): void => { }); }); - describe('when the given issue does have a milestone different than the exempt milestone', (): void => { + describe('when the given pull request does have a milestone different than the exempt milestone', (): void => { beforeEach((): void => { issueInterface.milestone = { title: 'dummy-title' @@ -440,7 +560,7 @@ describe('Milestones', (): void => { }); }); - describe('when the given issue does have a milestone equaling the exempt milestone', (): void => { + describe('when the given pull request does have a milestone equaling the exempt milestone', (): void => { beforeEach((): void => { issueInterface.milestone = { title: 'dummy-exempt-milestone' @@ -464,7 +584,7 @@ describe('Milestones', (): void => { optionsInterface.exemptPrMilestones = 'dummy-exempt-pr-milestone'; }); - describe('when the given issue does not have a milestone', (): void => { + describe('when the given pull request does not have a milestone', (): void => { beforeEach((): void => { issueInterface.milestone = undefined; }); @@ -480,7 +600,7 @@ describe('Milestones', (): void => { }); }); - describe('when the given issue does have a milestone different than the exempt pull request milestone', (): void => { + describe('when the given pull request does have a milestone different than the exempt pull request milestone', (): void => { beforeEach((): void => { issueInterface.milestone = { title: 'dummy-title' @@ -498,7 +618,7 @@ describe('Milestones', (): void => { }); }); - describe('when the given issue does have a milestone equaling the exempt pull request milestone', (): void => { + describe('when the given pull request does have a milestone equaling the exempt pull request milestone', (): void => { beforeEach((): void => { issueInterface.milestone = { title: 'dummy-exempt-pr-milestone' @@ -516,7 +636,7 @@ describe('Milestones', (): void => { }); }); - describe('when the given issue does have a milestone different than the exempt milestone', (): void => { + describe('when the given pull request does have a milestone different than the exempt milestone', (): void => { beforeEach((): void => { issueInterface.milestone = { title: 'dummy-title' @@ -534,7 +654,7 @@ describe('Milestones', (): void => { }); }); - describe('when the given issue does have a milestone equaling the exempt milestone', (): void => { + describe('when the given pull request does have a milestone equaling the exempt milestone', (): void => { beforeEach((): void => { issueInterface.milestone = { title: 'dummy-exempt-milestone' @@ -553,6 +673,126 @@ describe('Milestones', (): void => { }); }); }); + + describe('when the given options are configured to exempt all milestones', (): void => { + beforeEach((): void => { + optionsInterface.exemptAllMilestones = true; + }); + + describe('when the given pull request does not have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = undefined; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given pull request does have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = { + title: 'dummy-exempt-pr-milestone' + }; + }); + + it('should return true', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(true); + }); + }); + + describe('when the given options are not configured to exempt all pull request milestones', (): void => { + beforeEach((): void => { + optionsInterface.exemptAllPrMilestones = false; + }); + + describe('when the given pull request does not have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = undefined; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given pull request does have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = { + title: 'dummy-exempt-milestone' + }; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(false); + }); + }); + }); + + describe('when the given options are configured to exempt all pull request milestones', (): void => { + beforeEach((): void => { + optionsInterface.exemptAllPrMilestones = true; + }); + + describe('when the given pull request does not have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = undefined; + }); + + it('should return false', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(false); + }); + }); + + describe('when the given pull request does have a milestone', (): void => { + beforeEach((): void => { + issueInterface.milestone = { + title: 'dummy-exempt-pr-milestone' + }; + }); + + it('should return true', (): void => { + expect.assertions(1); + issue = new Issue(optionsInterface, issueInterface); + milestones = new Milestones(optionsInterface, issue); + + const result = milestones.shouldExemptMilestones(); + + expect(result).toStrictEqual(true); + }); + }); + }); + }); }); }); }); diff --git a/src/classes/milestones.ts b/src/classes/milestones.ts index bcb4f3ab..7f71b41a 100644 --- a/src/classes/milestones.ts +++ b/src/classes/milestones.ts @@ -1,4 +1,6 @@ +import chalk from 'chalk'; import deburr from 'lodash.deburr'; +import {Option} from '../enums/option'; import {wordsToList} from '../functions/words-to-list'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {Issue} from './issue'; @@ -31,7 +33,8 @@ export class Milestones { if (this._shouldExemptAllMilestones()) { this._issueLogger.info( - 'Skipping $$type because it has an exempt milestone' + chalk.white('└──'), + 'Skipping $$type because it has a milestone' ); return true; @@ -41,6 +44,7 @@ export class Milestones { if (exemptMilestones.length === 0) { this._issueLogger.info( + chalk.white('├──'), `No milestone option was specified to skip the stale process for this $$type` ); this._logSkip(); @@ -49,7 +53,8 @@ export class Milestones { } this._issueLogger.info( - `Found ${exemptMilestones.length} milestone${ + chalk.white('├──'), + `Found ${chalk.cyan(exemptMilestones.length)} milestone${ exemptMilestones.length > 1 ? 's' : '' } that can exempt stale on this $$type` ); @@ -61,11 +66,13 @@ export class Milestones { if (!hasExemptMilestone) { this._issueLogger.info( + chalk.white('├──'), 'No milestone on this $$type can exempt the stale process' ); this._logSkip(); } else { this._issueLogger.info( + chalk.white('└──'), 'Skipping this $$type because it has an exempt milestone' ); } @@ -82,12 +89,18 @@ export class Milestones { private _getExemptIssueMilestones(): string[] { if (this._options.exemptIssueMilestones === '') { this._issueLogger.info( - 'The option "exemptIssueMilestones" is disabled. No specific milestone can skip the stale process for this $$type' + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptIssueMilestones + )} is disabled. No specific milestone can skip the stale process for this $$type` ); if (this._options.exemptMilestones === '') { this._issueLogger.info( - 'The option "exemptMilestones" is disabled. No specific milestone can skip the stale process for this $$type' + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptMilestones + )} is disabled. No specific milestone can skip the stale process for this $$type` ); return []; @@ -98,9 +111,10 @@ export class Milestones { ); this._issueLogger.info( - `The option "exemptMilestones" is set. ${ - exemptMilestones.length - } milestone${ + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptMilestones + )} is set. ${chalk.cyan(exemptMilestones.length)} milestone${ exemptMilestones.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -113,9 +127,10 @@ export class Milestones { ); this._issueLogger.info( - `The option "exemptIssueMilestones" is set. ${ - exemptMilestones.length - } milestone${ + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptIssueMilestones + )} is set. ${chalk.cyan(exemptMilestones.length)} milestone${ exemptMilestones.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -126,12 +141,18 @@ export class Milestones { private _getExemptPullRequestMilestones(): string[] { if (this._options.exemptPrMilestones === '') { this._issueLogger.info( - 'The option "exemptPrMilestones" is disabled. No specific milestone can skip the stale process for this $$type' + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptPrMilestones + )} is disabled. No specific milestone can skip the stale process for this $$type` ); if (this._options.exemptMilestones === '') { this._issueLogger.info( - 'The option "exemptMilestones" is disabled. No specific milestone can skip the stale process for this $$type' + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptMilestones + )} is disabled. No specific milestone can skip the stale process for this $$type` ); return []; @@ -142,9 +163,10 @@ export class Milestones { ); this._issueLogger.info( - `The option "exemptMilestones" is set. ${ - exemptMilestones.length - } milestone${ + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptMilestones + )} is set. ${chalk.cyan(exemptMilestones.length)} milestone${ exemptMilestones.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -157,9 +179,10 @@ export class Milestones { ); this._issueLogger.info( - `The option "exemptPrMilestones" is set. ${ - exemptMilestones.length - } milestone${ + chalk.white('├──'), + `The option ${this._issueLogger.createOptionLink( + Option.ExemptPrMilestones + )} is set. ${chalk.cyan(exemptMilestones.length)} milestone${ exemptMilestones.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -182,6 +205,7 @@ export class Milestones { if (isSameMilestone) { this._issueLogger.info( + chalk.white('├──'), `The milestone "${milestone}" is set on this $$type and is an exempt milestone` ); } @@ -202,13 +226,17 @@ export class Milestones { private _shouldExemptAllIssueMilestones(): boolean { if (this._options.exemptAllIssueMilestones === true) { this._issueLogger.info( - 'The option "exemptAllIssueMilestones" is enabled. Any milestone on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllIssueMilestones + )} is enabled. Any milestone on this $$type will skip the stale process` ); return true; } else if (this._options.exemptAllIssueMilestones === false) { this._issueLogger.info( - 'The option "exemptAllIssueMilestones" is disabled. Only some specific milestones on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllIssueMilestones + )} is disabled. Only some specific milestones on this $$type will skip the stale process` ); return false; @@ -222,13 +250,17 @@ export class Milestones { private _shouldExemptAllPullRequestMilestones(): boolean { if (this._options.exemptAllPrMilestones === true) { this._issueLogger.info( - 'The option "exemptAllPrMilestones" is enabled. Any milestone on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllPrMilestones + )} is enabled. Any milestone on this $$type will skip the stale process` ); return true; } else if (this._options.exemptAllPrMilestones === false) { this._issueLogger.info( - 'The option "exemptAllPrMilestones" is disabled. Only some specific milestones on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllPrMilestones + )} is disabled. Only some specific milestones on this $$type will skip the stale process` ); return false; @@ -242,16 +274,20 @@ export class Milestones { private _logExemptAllMilestonesOption(): void { if (this._options.exemptAllMilestones) { this._issueLogger.info( - 'The option "exemptAllMilestones" is enabled. Any milestone on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllMilestones + )} is enabled. Any milestone on this $$type will skip the stale process` ); } else { this._issueLogger.info( - 'The option "exemptAllMilestones" is disabled. Only some specific milestones on this $$type will skip the stale process' + `The option ${this._issueLogger.createOptionLink( + Option.ExemptAllMilestones + )} is disabled. Only some specific milestones on this $$type will skip the stale process` ); } } private _logSkip(): void { - this._issueLogger.info('Skip the milestones checks'); + this._issueLogger.info(chalk.white('└──'), 'Skip the milestones checks'); } }