From 57a19972bfaa7c8685cf15a79710b536569facc1 Mon Sep 17 00:00:00 2001 From: Geoffrey Testelin Date: Tue, 25 May 2021 20:13:44 +0200 Subject: [PATCH] refactor(logs): simplify the syntax to colour the logs --- .eslintrc.json | 2 +- dist/index.js | 233 ++++++++++++++++------------ src/classes/assignees.ts | 52 +++---- src/classes/issues-processor.ts | 142 +++++++++-------- src/classes/loggers/issue-logger.ts | 8 +- src/classes/loggers/logger.ts | 27 +--- src/classes/milestones.ts | 56 +++---- src/classes/statistics.ts | 13 +- src/services/logger.service.ts | 45 ++++++ 9 files changed, 318 insertions(+), 260 deletions(-) create mode 100644 src/services/logger.service.ts diff --git a/.eslintrc.json b/.eslintrc.json index d4ca3d2f7..7d0932de3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -28,7 +28,7 @@ "@typescript-eslint/no-array-constructor": "error", "@typescript-eslint/no-empty-interface": "error", "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-extraneous-class": "error", + "@typescript-eslint/no-extraneous-class": "off", "@typescript-eslint/no-for-in-array": "error", "@typescript-eslint/no-inferrable-types": "error", "@typescript-eslint/no-misused-new": "error", diff --git a/dist/index.js b/dist/index.js index 65885a3c7..670c30ce2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12,11 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Assignees = void 0; -const ansi_styles_1 = __importDefault(__nccwpck_require__(2068)); 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); +const logger_service_1 = __nccwpck_require__(1973); class Assignees { constructor(options, issue) { this._options = options; @@ -33,23 +33,23 @@ class Assignees { return false; } if (this._shouldExemptAllAssignees()) { - this._issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, 'Skipping this $$type because it has an exempt assignee'); + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has an exempt assignee'); return true; } const exemptAssignees = this._getExemptAssignees(); if (exemptAssignees.length === 0) { - this._issueLogger.info(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `No assignee option was specified to skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `No assignee option was specified to skip the stale process for this $$type`); this._logSkip(); return false; } - this._issueLogger.info(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `Found ${ansi_styles_1.default.cyan.open}${exemptAssignees.length}${ansi_styles_1.default.cyan.close} assignee${exemptAssignees.length > 1 ? 's' : ''} that can exempt stale on this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `Found ${logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, 'No assignee on this $$type can exempt the stale process'); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), 'No assignee on this $$type can exempt the stale process'); this._logSkip(); } else { - this._issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, 'Skipping this $$type because it has an exempt assignee'); + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has an exempt assignee'); } return hasExemptAssignee; } @@ -60,32 +60,32 @@ class Assignees { } _getExemptIssueAssignees() { if (this._options.exemptIssueAssignees === '') { - this._issueLogger.info(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is set. ${ansi_styles_1.default.cyan.open}${exemptAssignees.length}${ansi_styles_1.default.cyan.close} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is set. ${logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueAssignees)} is set. ${ansi_styles_1.default.cyan.open}${exemptAssignees.length}${ansi_styles_1.default.cyan.close} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueAssignees)} is set. ${logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is set. ${ansi_styles_1.default.cyan.open}${exemptAssignees.length}${ansi_styles_1.default.cyan.close} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is set. ${logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrAssignees)} is set. ${ansi_styles_1.default.cyan.open}${exemptAssignees.length}${ansi_styles_1.default.cyan.close} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrAssignees)} is set. ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); return exemptAssignees; } _hasAssignee(assignee) { @@ -93,7 +93,7 @@ class Assignees { return this._issue.assignees.some((issueAssignee) => { const isSameAssignee = cleanAssignee === Assignees._cleanAssignee(issueAssignee.login); if (isSameAssignee) { - this._issueLogger.info(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `@${issueAssignee.login} is assigned on this $$type and is an exempt assignee`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `@${issueAssignee.login} is assigned on this $$type and is an exempt assignee`); } return isSameAssignee; }); @@ -136,7 +136,7 @@ class Assignees { } } _logSkip() { - this._issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, 'Skip the assignees checks'); + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skip the assignees checks'); } } exports.Assignees = Assignees; @@ -223,14 +223,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.IssuesProcessor = void 0; const core = __importStar(__nccwpck_require__(2186)); const github_1 = __nccwpck_require__(5438); -const ansi_styles_1 = __importDefault(__nccwpck_require__(2068)); const option_1 = __nccwpck_require__(5931); const get_humanized_date_1 = __nccwpck_require__(965); const is_date_more_recent_than_1 = __nccwpck_require__(1473); @@ -246,6 +242,7 @@ 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. */ @@ -259,10 +256,10 @@ class IssuesProcessor { this.options = options; this.client = github_1.getOctokit(this.options.repoToken); this._operations = new stale_operations_1.StaleOperations(this.options); - this._logger.info(`${ansi_styles_1.default.yellow.open}Starting the stale action process...${ansi_styles_1.default.yellow.close}`); + this._logger.info(logger_service_1.LoggerService.yellow(`Starting the stale action process...`)); if (this.options.debugOnly) { - this._logger.warning(`${ansi_styles_1.default.yellowBright.open}Executing in debug mode!${ansi_styles_1.default.yellowBright.close}`); - this._logger.warning(`${ansi_styles_1.default.yellowBright.open}The debug output will be written but no issues/PRs will be processed.${ansi_styles_1.default.yellowBright.close}`); + this._logger.warning(logger_service_1.LoggerService.yellowBright(`Executing in debug mode!`)); + this._logger.warning(logger_service_1.LoggerService.yellowBright(`The debug output will be written but no issues/PRs will be processed.`)); } if (this.options.enableStatistics) { this._statistics = new statistics_1.Statistics(); @@ -277,7 +274,7 @@ class IssuesProcessor { const consumedOperationsCount = issue.operations.getConsumedOperationsCount(); if (consumedOperationsCount > 0) { const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`${ansi_styles_1.default.cyan.open}${consumedOperationsCount}${ansi_styles_1.default.cyan.close}`, `operation${consumedOperationsCount > 1 ? 's' : ''} consumed for this $$type`); + issueLogger.info(logger_service_1.LoggerService.cyan(consumedOperationsCount), `operation${consumedOperationsCount > 1 ? 's' : ''} consumed for this $$type`); } } static _getStaleMessageUsedOptionName(issue) { @@ -292,17 +289,17 @@ class IssuesProcessor { const issues = yield this.getIssues(page); const actor = yield this.getActor(); if (issues.length <= 0) { - this._logger.info(`${ansi_styles_1.default.green.open}No more issues found to process. Exiting...${ansi_styles_1.default.green.close}`); + this._logger.info(logger_service_1.LoggerService.green(`No more issues found to process. Exiting...`)); (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.setRemainingOperations(this._operations.getRemainingOperationsCount()).logStats(); return this._operations.getRemainingOperationsCount(); } else { - this._logger.info(`${ansi_styles_1.default.yellow.open}Processing the batch of issues ${ansi_styles_1.default.cyan.open}#${page}${ansi_styles_1.default.cyan.close} containing ${ansi_styles_1.default.cyan.open}${issues.length}${ansi_styles_1.default.cyan.close} issue${issues.length > 1 ? 's' : ''}...${ansi_styles_1.default.yellow.close}`); + this._logger.info(`${logger_service_1.LoggerService.yellow('Processing the batch of issues')} ${logger_service_1.LoggerService.cyan(`#${page}`)} ${logger_service_1.LoggerService.yellow('containing')} ${logger_service_1.LoggerService.cyan(issues.length)} ${logger_service_1.LoggerService.yellow(`issue${issues.length > 1 ? 's' : ''}...`)}`); } for (const issue of issues.values()) { const issueLogger = new issue_logger_1.IssueLogger(issue); (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementProcessedItemsCount(issue); - issueLogger.info(`Found this $$type last updated at: ${ansi_styles_1.default.cyan.open}${issue.updated_at}${ansi_styles_1.default.cyan.close}`); + issueLogger.info(`Found this $$type last updated at: ${logger_service_1.LoggerService.cyan(issue.updated_at)}`); // calculate string based messages for this issue const staleMessage = issue.isPullRequest ? this.options.stalePrMessage @@ -324,28 +321,28 @@ class IssuesProcessor { : this._getDaysBeforeIssueStale(); 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 (${ansi_styles_1.default.cyan.open}${onlyLabels.length}${ansi_styles_1.default.cyan.close})`); + 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)})`); const hasAllWhitelistedLabels = onlyLabels.every((label) => { return is_labeled_1.isLabeled(issue, label); }); if (!hasAllWhitelistedLabels) { - issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, `Skipping this $$type because it doesn't have all the required labels`); + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Skipping this $$type because it doesn't have all the required labels`); IssuesProcessor._endIssueProcessing(issue); continue; // Don't process issues without all of the required labels } else { - issueLogger.info(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `All the required labels are present on this $$type`); - issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, `Continuing the process for this $$type`); + issueLogger.info(logger_service_1.LoggerService.white('├──'), `All the required labels are present on this $$type`); + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); } } else { issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.OnlyLabels)} was not specified`); - issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, `Continuing the process for this $$type`); + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); } - issueLogger.info(`Days before $$type stale: ${ansi_styles_1.default.cyan.open}${daysBeforeStale}${ansi_styles_1.default.cyan.close}`); + issueLogger.info(`Days before $$type stale: ${logger_service_1.LoggerService.cyan(daysBeforeStale)}`); const shouldMarkAsStale = should_mark_when_stale_1.shouldMarkWhenStale(daysBeforeStale); if (!staleMessage && shouldMarkAsStale) { - issueLogger.info(`Skipping this $$type because it should be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${ansi_styles_1.default.cyan.open}${daysBeforeStale}${ansi_styles_1.default.cyan.close}) but the option ${issueLogger.createOptionLink(IssuesProcessor._getStaleMessageUsedOptionName(issue))} is not set`); + issueLogger.info(`Skipping this $$type because it should be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${logger_service_1.LoggerService.cyan(daysBeforeStale)}) but the option ${issueLogger.createOptionLink(IssuesProcessor._getStaleMessageUsedOptionName(issue))} is not set`); IssuesProcessor._endIssueProcessing(issue); continue; } @@ -364,14 +361,14 @@ class IssuesProcessor { if (this.options.startDate) { const startDate = new Date(this.options.startDate); const createdAt = new Date(issue.created_at); - issueLogger.info(`A start date was specified for the ${get_humanized_date_1.getHumanizedDate(startDate)} (${ansi_styles_1.default.cyan.open}${this.options.startDate}${ansi_styles_1.default.cyan.close})`); + issueLogger.info(`A start date was specified for the ${get_humanized_date_1.getHumanizedDate(startDate)} (${logger_service_1.LoggerService.cyan(this.options.startDate)})`); // Expecting that GitHub will always set a creation date on the issues and PRs // But you never know! if (!is_valid_date_1.isValidDate(createdAt)) { IssuesProcessor._endIssueProcessing(issue); core.setFailed(new Error(`Invalid issue field: "created_at". Expected a valid date`)); } - issueLogger.info(`$$type created the ${get_humanized_date_1.getHumanizedDate(createdAt)} (${ansi_styles_1.default.cyan.open}${issue.created_at}${ansi_styles_1.default.cyan.close})`); + issueLogger.info(`$$type created the ${get_humanized_date_1.getHumanizedDate(createdAt)} (${logger_service_1.LoggerService.cyan(issue.created_at)})`); if (!is_date_more_recent_than_1.isDateMoreRecentThan(createdAt, startDate)) { issueLogger.info(`Skipping this $$type because it was created before the specified start date`); IssuesProcessor._endIssueProcessing(issue); @@ -398,23 +395,23 @@ class IssuesProcessor { } const anyOfLabels = words_to_list_1.wordsToList(this._getAnyOfLabels(issue)); if (anyOfLabels.length > 0) { - issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.AnyOfLabels)} was specified to only process the issues and pull requests with one of those labels (${ansi_styles_1.default.cyan.open}${anyOfLabels.length}${ansi_styles_1.default.cyan.close})`); + issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.AnyOfLabels)} was specified to only process the issues and pull requests with one of those labels (${logger_service_1.LoggerService.cyan(anyOfLabels.length)})`); const hasOneOfWhitelistedLabels = anyOfLabels.some((label) => { return is_labeled_1.isLabeled(issue, label); }); if (!hasOneOfWhitelistedLabels) { - issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, `Skipping this $$type because it doesn't have one of the required labels`); + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Skipping this $$type because it doesn't have one of the required labels`); IssuesProcessor._endIssueProcessing(issue); continue; // Don't process issues without any of the required labels } else { - issueLogger.info(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `One of the required labels is present on this $$type`); - issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, `Continuing the process for this $$type`); + issueLogger.info(logger_service_1.LoggerService.white('├──'), `One of the required labels is present on this $$type`); + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); } } else { issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.AnyOfLabels)} was not specified`); - issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, `Continuing the process for this $$type`); + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); } const milestones = new milestones_1.Milestones(this.options, issue); if (milestones.shouldExemptMilestones()) { @@ -433,19 +430,19 @@ class IssuesProcessor { issueLogger.info(`This $$type is not stale`); const updatedAtDate = new Date(issue.updated_at); if (shouldBeStale) { - issueLogger.info(`This $$type should be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(updatedAtDate)} (${ansi_styles_1.default.cyan.open}${issue.updated_at}${ansi_styles_1.default.cyan.close})`); + issueLogger.info(`This $$type should be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(updatedAtDate)} (${logger_service_1.LoggerService.cyan(issue.updated_at)})`); if (shouldMarkAsStale) { - issueLogger.info(`This $$type should be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${ansi_styles_1.default.cyan.open}${daysBeforeStale}${ansi_styles_1.default.cyan.close})`); + issueLogger.info(`This $$type should be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${logger_service_1.LoggerService.cyan(daysBeforeStale)})`); yield this._markStale(issue, staleMessage, staleLabel, skipMessage); issue.isStale = true; // This issue is now considered stale issueLogger.info(`This $$type is now stale`); } else { - issueLogger.info(`This $$type should not be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${ansi_styles_1.default.cyan.open}${daysBeforeStale}${ansi_styles_1.default.cyan.close})`); + issueLogger.info(`This $$type should not be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${logger_service_1.LoggerService.cyan(daysBeforeStale)})`); } } else { - issueLogger.info(`This $$type should not be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(updatedAtDate)} (${ansi_styles_1.default.cyan.open}${issue.updated_at}${ansi_styles_1.default.cyan.close})`); + issueLogger.info(`This $$type should not be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(updatedAtDate)} (${logger_service_1.LoggerService.cyan(issue.updated_at)})`); } } // Process the issue if it was marked stale @@ -456,11 +453,11 @@ class IssuesProcessor { IssuesProcessor._endIssueProcessing(issue); } if (!this._operations.hasRemainingOperations()) { - this._logger.warning(`${ansi_styles_1.default.yellowBright.open}No more operations left! Exiting...${ansi_styles_1.default.yellowBright.close}`); - this._logger.warning(`${ansi_styles_1.default.yellowBright.open}If you think that not enough issues were processed you could try to increase the quantity related to the ${this._logger.createOptionLink(option_1.Option.OperationsPerRun)} option which is currently set to ${ansi_styles_1.default.cyan.open}${this.options.operationsPerRun}${ansi_styles_1.default.cyan.close}${ansi_styles_1.default.yellowBright.close}`); + this._logger.warning(logger_service_1.LoggerService.yellowBright(`No more operations left! Exiting...`)); + this._logger.warning(`${logger_service_1.LoggerService.yellowBright('If you think that not enough issues were processed you could try to increase the quantity related to the')} ${this._logger.createOptionLink(option_1.Option.OperationsPerRun)} ${logger_service_1.LoggerService.yellowBright('option which is currently set to')} ${logger_service_1.LoggerService.cyan(this.options.operationsPerRun)}`); return 0; } - this._logger.info(`${ansi_styles_1.default.green.open}Batch ${ansi_styles_1.default.cyan.open}#${page}${ansi_styles_1.default.cyan.close} processed.${ansi_styles_1.default.green.close}`); + this._logger.info(`${logger_service_1.LoggerService.green('Batch')} ${logger_service_1.LoggerService.cyan(`#${page}`)} ${logger_service_1.LoggerService.green('processed.')}`); // Do the next batch return this.processIssues(page + 1); }); @@ -556,15 +553,15 @@ class IssuesProcessor { return __awaiter(this, void 0, void 0, function* () { const issueLogger = new issue_logger_1.IssueLogger(issue); const markedStaleOn = (yield this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at; - issueLogger.info(`$$type marked stale on: ${ansi_styles_1.default.cyan.open}${markedStaleOn}${ansi_styles_1.default.cyan.close}`); + issueLogger.info(`$$type marked stale on: ${logger_service_1.LoggerService.cyan(markedStaleOn)}`); const issueHasComments = yield this._hasCommentsSince(issue, markedStaleOn, actor); - issueLogger.info(`$$type has been commented on: ${ansi_styles_1.default.cyan.open}${issueHasComments}${ansi_styles_1.default.cyan.close}`); + issueLogger.info(`$$type has been commented on: ${logger_service_1.LoggerService.cyan(issueHasComments)}`); const daysBeforeClose = issue.isPullRequest ? this._getDaysBeforePrClose() : this._getDaysBeforeIssueClose(); - issueLogger.info(`Days before $$type close: ${ansi_styles_1.default.cyan.open}${daysBeforeClose}${ansi_styles_1.default.cyan.close}`); + issueLogger.info(`Days before $$type close: ${logger_service_1.LoggerService.cyan(daysBeforeClose)}`); const issueHasUpdate = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose); - issueLogger.info(`$$type has been updated: ${ansi_styles_1.default.cyan.open}${issueHasUpdate}${ansi_styles_1.default.cyan.close}`); + issueLogger.info(`$$type has been updated: ${logger_service_1.LoggerService.cyan(issueHasUpdate)}`); // should we un-stale this issue? if (this._shouldRemoveStaleWhenUpdated(issue) && issueHasComments) { yield this._removeStaleLabel(issue, staleLabel); @@ -576,7 +573,7 @@ class IssuesProcessor { return; // nothing to do because we aren't closing stale issues } if (!issueHasComments && !issueHasUpdate) { - issueLogger.info(`Closing $$type because it was last updated on! ${ansi_styles_1.default.cyan.open}${issue.updated_at}${ansi_styles_1.default.cyan.close}`); + issueLogger.info(`Closing $$type because it was last updated on! ${logger_service_1.LoggerService.cyan(issue.updated_at)}`); yield this._closeIssue(issue, closeMessage, closeLabel); if (this.options.deleteBranch && issue.pull_request) { issueLogger.info(`Deleting the branch the option ${issueLogger.createOptionLink(option_1.Option.DeleteBranch)} was specified`); @@ -593,14 +590,14 @@ class IssuesProcessor { _hasCommentsSince(issue, sinceDate, actor) { return __awaiter(this, void 0, void 0, function* () { const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`Checking for comments on $$type since: ${ansi_styles_1.default.cyan.open}${sinceDate}${ansi_styles_1.default.cyan.close}`); + issueLogger.info(`Checking for comments on $$type since: ${logger_service_1.LoggerService.cyan(sinceDate)}`); if (!sinceDate) { return true; } // find any comments since the date const comments = yield this.listIssueComments(issue.number, sinceDate); const filteredComments = comments.filter(comment => comment.user.type === 'User' && comment.user.login !== actor); - issueLogger.info(`Comments not made by actor or another bot: ${ansi_styles_1.default.cyan.open}${filteredComments.length}${ansi_styles_1.default.cyan.close}`); + issueLogger.info(`Comments not made by actor or another bot: ${logger_service_1.LoggerService.cyan(filteredComments.length)}`); // if there are any user comments returned return filteredComments.length > 0; }); @@ -742,7 +739,7 @@ class IssuesProcessor { return; } const branch = pullRequest.head.ref; - issueLogger.info(`Deleting the branch "${ansi_styles_1.default.cyan.open}${branch}${ansi_styles_1.default.cyan.close}" from closed $$type`); + issueLogger.info(`Deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from closed $$type`); try { this._consumeIssueOperation(issue); (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedBranchesCount(); @@ -753,7 +750,7 @@ class IssuesProcessor { }); } catch (error) { - issueLogger.error(`Error when deleting the branch "${ansi_styles_1.default.cyan.open}${branch}${ansi_styles_1.default.cyan.close}" from $$type: ${error.message}`); + issueLogger.error(`Error when deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from $$type: ${error.message}`); } }); } @@ -762,7 +759,7 @@ class IssuesProcessor { var _a; return __awaiter(this, void 0, void 0, function* () { const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`Removing the label "${ansi_styles_1.default.cyan.open}${label}${ansi_styles_1.default.cyan.close}" from this $$type...`); + issueLogger.info(`Removing the label "${logger_service_1.LoggerService.cyan(label)}" from this $$type...`); this.removedLabelIssues.push(issue); if (this.options.debugOnly) { return; @@ -776,10 +773,10 @@ class IssuesProcessor { issue_number: issue.number, name: label }); - issueLogger.info(`The label "${ansi_styles_1.default.cyan.open}${label}${ansi_styles_1.default.cyan.close}" was removed`); + issueLogger.info(`The label "${logger_service_1.LoggerService.cyan(label)}" was removed`); } catch (error) { - issueLogger.error(`Error when removing the label: "${ansi_styles_1.default.cyan.open}${error.message}${ansi_styles_1.default.cyan.close}"`); + issueLogger.error(`Error when removing the label: "${logger_service_1.LoggerService.cyan(error.message)}"`); } }); } @@ -860,7 +857,7 @@ class IssuesProcessor { return Promise.resolve(); } if (is_labeled_1.isLabeled(issue, closeLabel)) { - issueLogger.info(`The $$type has a close label "${ansi_styles_1.default.cyan.open}${closeLabel}${ansi_styles_1.default.cyan.close}". Removing the close label...`); + issueLogger.info(`The $$type has a close label "${logger_service_1.LoggerService.cyan(closeLabel)}". Removing the close label...`); yield this._removeLabel(issue, closeLabel); (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedCloseItemsLabelsCount(issue); } @@ -892,17 +889,14 @@ exports.IssuesProcessor = IssuesProcessor; /***/ }), /***/ 2984: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.IssueLogger = void 0; -const ansi_styles_1 = __importDefault(__nccwpck_require__(2068)); const logger_1 = __nccwpck_require__(6212); +const logger_service_1 = __nccwpck_require__(1973); /** * @description * Each log will prefix the message with the issue number @@ -953,10 +947,10 @@ class IssueLogger extends logger_1.Logger { : this._getIssuePrefix(); } _getIssuePrefix() { - return `${ansi_styles_1.default.red.open}[#${this._getIssueNumber()}]${ansi_styles_1.default.red.close}`; + return logger_service_1.LoggerService.red(`[#${this._getIssueNumber()}]`); } _getPullRequestPrefix() { - return `${ansi_styles_1.default.blue.open}[#${this._getIssueNumber()}]${ansi_styles_1.default.blue.close}`; + return logger_service_1.LoggerService.blue(`[#${this._getIssueNumber()}]`); } } exports.IssueLogger = IssueLogger; @@ -994,23 +988,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Logger = void 0; const core = __importStar(__nccwpck_require__(2186)); -const ansi_styles_1 = __importDefault(__nccwpck_require__(2068)); const terminal_link_1 = __importDefault(__nccwpck_require__(1898)); +const logger_service_1 = __nccwpck_require__(1973); class Logger { warning(...message) { - core.warning(`${ansi_styles_1.default.whiteBright.open}${message.join(' ')}${ansi_styles_1.default.whiteBright.close}`); + core.warning(logger_service_1.LoggerService.whiteBright(message.join(' '))); } info(...message) { - core.info(`${ansi_styles_1.default.whiteBright.open}${message.join(' ')}${ansi_styles_1.default.whiteBright.close}`); + core.info(logger_service_1.LoggerService.whiteBright(message.join(' '))); } error(...message) { - core.error(`${ansi_styles_1.default.whiteBright.open}${message.join(' ')}${ansi_styles_1.default.whiteBright.close}`); + core.error(logger_service_1.LoggerService.whiteBright(message.join(' '))); } createLink(name, link) { return terminal_link_1.default(name, link); } createOptionLink(option) { - return `${ansi_styles_1.default.magenta.open}${this.createLink(option, `https://github.com/actions/stale#${option}`)}${ansi_styles_1.default.magenta.close}`; + return logger_service_1.LoggerService.magenta(this.createLink(option, `https://github.com/actions/stale#${option}`)); } } exports.Logger = Logger; @@ -1028,11 +1022,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Milestones = void 0; -const ansi_styles_1 = __importDefault(__nccwpck_require__(2068)); 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); +const logger_service_1 = __nccwpck_require__(1973); class Milestones { constructor(options, issue) { this._options = options; @@ -1049,23 +1043,23 @@ class Milestones { return false; } if (this._shouldExemptAllMilestones()) { - this._issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, 'Skipping this $$type because it has a milestone'); + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has a milestone'); return true; } const exemptMilestones = this._getExemptMilestones(); if (exemptMilestones.length === 0) { - this._issueLogger.info(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `No milestone option was specified to skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `No milestone option was specified to skip the stale process for this $$type`); this._logSkip(); return false; } - this._issueLogger.info(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `Found ${ansi_styles_1.default.cyan.open}${exemptMilestones.length}${ansi_styles_1.default.cyan.close} milestone${exemptMilestones.length > 1 ? 's' : ''} that can exempt stale on this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `Found ${logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, 'No milestone on this $$type can exempt the stale process'); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), 'No milestone on this $$type can exempt the stale process'); this._logSkip(); } else { - this._issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, 'Skipping this $$type because it has an exempt milestone'); + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has an exempt milestone'); } return hasExemptMilestone; } @@ -1076,32 +1070,32 @@ class Milestones { } _getExemptIssueMilestones() { if (this._options.exemptIssueMilestones === '') { - this._issueLogger.info(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is set. ${ansi_styles_1.default.cyan.open}${exemptMilestones.length}${ansi_styles_1.default.cyan.close} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is set. ${logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueMilestones)} is set. ${ansi_styles_1.default.cyan.open}${exemptMilestones.length}${ansi_styles_1.default.cyan.close} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueMilestones)} is set. ${logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is set. ${ansi_styles_1.default.cyan.open}${exemptMilestones.length}${ansi_styles_1.default.cyan.close} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is set. ${logger_service_1.LoggerService.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(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrMilestones)} is set. ${ansi_styles_1.default.cyan.open}${exemptMilestones.length}${ansi_styles_1.default.cyan.close} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrMilestones)} is set. ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); return exemptMilestones; } _hasMilestone(milestone) { @@ -1112,7 +1106,7 @@ class Milestones { const isSameMilestone = cleanMilestone === Milestones._cleanMilestone(this._issue.milestone.title); if (isSameMilestone) { - this._issueLogger.info(`${ansi_styles_1.default.white.open}├──${ansi_styles_1.default.white.close}`, `The milestone "${milestone}" is set on this $$type and is an exempt milestone`); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The milestone "${logger_service_1.LoggerService.cyan(milestone)}" is set on this $$type and is an exempt milestone`); } return isSameMilestone; } @@ -1157,7 +1151,7 @@ class Milestones { } } _logSkip() { - this._issueLogger.info(`${ansi_styles_1.default.white.open}└──${ansi_styles_1.default.white.close}`, 'Skip the milestones checks'); + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skip the milestones checks'); } } exports.Milestones = Milestones; @@ -1218,17 +1212,14 @@ exports.StaleOperations = StaleOperations; /***/ }), /***/ 3334: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Statistics = void 0; -const ansi_styles_1 = __importDefault(__nccwpck_require__(2068)); const logger_1 = __nccwpck_require__(6212); +const logger_service_1 = __nccwpck_require__(1973); class Statistics { constructor() { this._logger = new logger_1.Logger(); @@ -1328,7 +1319,7 @@ class Statistics { return this; } logStats() { - this._logger.info(`${ansi_styles_1.default.yellow.open}${ansi_styles_1.default.bold.open}Statistics:${ansi_styles_1.default.bold.close}${ansi_styles_1.default.yellow.close}`); + this._logger.info(logger_service_1.LoggerService.yellow(logger_service_1.LoggerService.bold(`Statistics:`))); this._logProcessedIssuesAndPullRequestsCount(); this._logStaleIssuesAndPullRequestsCount(); this._logUndoStaleIssuesAndPullRequestsCount(); @@ -1525,7 +1516,7 @@ class Statistics { } _logCount(name, count) { if (count > 0) { - this._logger.info(`${name}:`, `${ansi_styles_1.default.cyan.open}${count}${ansi_styles_1.default.cyan.close}`); + this._logger.info(`${name}:`, logger_service_1.LoggerService.cyan(count)); } } _logGroup(groupName, values) { @@ -1570,7 +1561,7 @@ class Statistics { const longestValue = this._getLongestGroupValue(onlyValuesSet); for (const [index, value] of onlyValuesSet.entries()) { const prefix = index === onlyValuesSet.length - 1 ? '└──' : '├──'; - this._logCount(`${ansi_styles_1.default.white.open}${prefix}${ansi_styles_1.default.white.close} ${value.name.padEnd(longestValue, ' ')}`, value.count); + this._logCount(`${logger_service_1.LoggerService.white(prefix)} ${value.name.padEnd(longestValue, ' ')}`, value.count); } } _getLongestGroupValue(values) { @@ -1958,6 +1949,54 @@ function _toOptionalBoolean(argumentName) { void _run(); +/***/ }), + +/***/ 1973: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.LoggerService = void 0; +const ansi_styles_1 = __importDefault(__nccwpck_require__(2068)); +class LoggerService { + static whiteBright(message) { + return `${ansi_styles_1.default.whiteBright.open}${message}${ansi_styles_1.default.whiteBright.close}`; + } + static yellowBright(message) { + return `${ansi_styles_1.default.yellowBright.open}${message}${ansi_styles_1.default.yellowBright.close}`; + } + static magenta(message) { + return `${ansi_styles_1.default.magenta.open}${message}${ansi_styles_1.default.magenta.close}`; + } + static cyan(message) { + return `${ansi_styles_1.default.cyan.open}${message}${ansi_styles_1.default.cyan.close}`; + } + static yellow(message) { + return `${ansi_styles_1.default.yellow.open}${message}${ansi_styles_1.default.yellow.close}`; + } + static white(message) { + return `${ansi_styles_1.default.white.open}${message}${ansi_styles_1.default.white.close}`; + } + static green(message) { + return `${ansi_styles_1.default.green.open}${message}${ansi_styles_1.default.green.close}`; + } + static red(message) { + return `${ansi_styles_1.default.red.open}${message}${ansi_styles_1.default.red.close}`; + } + static blue(message) { + return `${ansi_styles_1.default.blue.open}${message}${ansi_styles_1.default.blue.close}`; + } + static bold(message) { + return `${ansi_styles_1.default.bold.open}${message}${ansi_styles_1.default.bold.close}`; + } +} +exports.LoggerService = LoggerService; + + /***/ }), /***/ 7351: diff --git a/src/classes/assignees.ts b/src/classes/assignees.ts index 011a305ac..38185db0b 100644 --- a/src/classes/assignees.ts +++ b/src/classes/assignees.ts @@ -1,4 +1,3 @@ -import styles from 'ansi-styles'; import deburr from 'lodash.deburr'; import {Option} from '../enums/option'; import {wordsToList} from '../functions/words-to-list'; @@ -6,6 +5,7 @@ import {IAssignee} from '../interfaces/assignee'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {Issue} from './issue'; import {IssueLogger} from './loggers/issue-logger'; +import {LoggerService} from '../services/logger.service'; type CleanAssignee = string; @@ -34,7 +34,7 @@ export class Assignees { if (this._shouldExemptAllAssignees()) { this._issueLogger.info( - `${styles.white.open}└──${styles.white.close}`, + LoggerService.white('└──'), 'Skipping this $$type because it has an exempt assignee' ); @@ -45,7 +45,7 @@ export class Assignees { if (exemptAssignees.length === 0) { this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `No assignee option was specified to skip the stale process for this $$type` ); this._logSkip(); @@ -54,10 +54,8 @@ export class Assignees { } this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, - `Found ${styles.cyan.open}${exemptAssignees.length}${ - styles.cyan.close - } assignee${ + LoggerService.white('├──'), + `Found ${LoggerService.cyan(exemptAssignees.length)} assignee${ exemptAssignees.length > 1 ? 's' : '' } that can exempt stale on this $$type` ); @@ -69,13 +67,13 @@ export class Assignees { if (!hasExemptAssignee) { this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), 'No assignee on this $$type can exempt the stale process' ); this._logSkip(); } else { this._issueLogger.info( - `${styles.white.open}└──${styles.white.close}`, + LoggerService.white('└──'), 'Skipping this $$type because it has an exempt assignee' ); } @@ -92,7 +90,7 @@ export class Assignees { private _getExemptIssueAssignees(): string[] { if (this._options.exemptIssueAssignees === '') { this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink( Option.ExemptIssueAssignees )} is disabled. No specific assignee can skip the stale process for this $$type` @@ -100,7 +98,7 @@ export class Assignees { if (this._options.exemptAssignees === '') { this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink( Option.ExemptAssignees )} is disabled. No specific assignee can skip the stale process for this $$type` @@ -114,12 +112,10 @@ export class Assignees { ); this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink( Option.ExemptAssignees - )} is set. ${styles.cyan.open}${exemptAssignees.length}${ - styles.cyan.close - } assignee${ + )} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -132,12 +128,10 @@ export class Assignees { ); this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink( Option.ExemptIssueAssignees - )} is set. ${styles.cyan.open}${exemptAssignees.length}${ - styles.cyan.close - } assignee${ + )} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -148,7 +142,7 @@ export class Assignees { private _getExemptPullRequestAssignees(): string[] { if (this._options.exemptPrAssignees === '') { this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink( Option.ExemptPrAssignees )} is disabled. No specific assignee can skip the stale process for this $$type` @@ -156,7 +150,7 @@ export class Assignees { if (this._options.exemptAssignees === '') { this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink( Option.ExemptAssignees )} is disabled. No specific assignee can skip the stale process for this $$type` @@ -170,12 +164,10 @@ export class Assignees { ); this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink( Option.ExemptAssignees - )} is set. ${styles.cyan.open}${exemptAssignees.length}${ - styles.cyan.close - } assignee${ + )} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -188,12 +180,10 @@ export class Assignees { ); this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink( Option.ExemptPrAssignees - )} is set. ${styles.cyan.open}${exemptAssignees.length}${ - styles.cyan.close - } assignee${ + )} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -211,7 +201,7 @@ export class Assignees { if (isSameAssignee) { this._issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `@${issueAssignee.login} is assigned on this $$type and is an exempt assignee` ); } @@ -293,7 +283,7 @@ export class Assignees { private _logSkip(): void { this._issueLogger.info( - `${styles.white.open}└──${styles.white.close}`, + LoggerService.white('└──'), 'Skip the assignees checks' ); } diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index c8cf00b26..16829790c 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -2,7 +2,6 @@ import * as core from '@actions/core'; import {context, getOctokit} from '@actions/github'; import {GitHub} from '@actions/github/lib/utils'; import {GetResponseTypeFromEndpointMethod} from '@octokit/types'; -import styles from 'ansi-styles'; import {Option} from '../enums/option'; import {getHumanizedDate} from '../functions/dates/get-humanized-date'; import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than'; @@ -23,6 +22,7 @@ import {Logger} from './loggers/logger'; import {Milestones} from './milestones'; import {StaleOperations} from './stale-operations'; import {Statistics} from './statistics'; +import {LoggerService} from '../services/logger.service'; /*** * Handle processing of issues for staleness/closure. @@ -43,7 +43,7 @@ export class IssuesProcessor { const issueLogger: IssueLogger = new IssueLogger(issue); issueLogger.info( - `${styles.cyan.open}${consumedOperationsCount}${styles.cyan.close}`, + LoggerService.cyan(consumedOperationsCount), `operation${ consumedOperationsCount > 1 ? 's' : '' } consumed for this $$type` @@ -75,15 +75,17 @@ export class IssuesProcessor { this._operations = new StaleOperations(this.options); this._logger.info( - `${styles.yellow.open}Starting the stale action process...${styles.yellow.close}` + LoggerService.yellow(`Starting the stale action process...`) ); if (this.options.debugOnly) { this._logger.warning( - `${styles.yellowBright.open}Executing in debug mode!${styles.yellowBright.close}` + LoggerService.yellowBright(`Executing in debug mode!`) ); this._logger.warning( - `${styles.yellowBright.open}The debug output will be written but no issues/PRs will be processed.${styles.yellowBright.close}` + LoggerService.yellowBright( + `The debug output will be written but no issues/PRs will be processed.` + ) ); } @@ -99,7 +101,7 @@ export class IssuesProcessor { if (issues.length <= 0) { this._logger.info( - `${styles.green.open}No more issues found to process. Exiting...${styles.green.close}` + LoggerService.green(`No more issues found to process. Exiting...`) ); this._statistics ?.setRemainingOperations(this._operations.getRemainingOperationsCount()) @@ -108,13 +110,13 @@ export class IssuesProcessor { return this._operations.getRemainingOperationsCount(); } else { this._logger.info( - `${styles.yellow.open}Processing the batch of issues ${ - styles.cyan.open - }#${page}${styles.cyan.close} containing ${styles.cyan.open}${ - issues.length - }${styles.cyan.close} issue${issues.length > 1 ? 's' : ''}...${ - styles.yellow.close - }` + `${LoggerService.yellow( + 'Processing the batch of issues' + )} ${LoggerService.cyan(`#${page}`)} ${LoggerService.yellow( + 'containing' + )} ${LoggerService.cyan(issues.length)} ${LoggerService.yellow( + `issue${issues.length > 1 ? 's' : ''}...` + )}` ); } @@ -123,7 +125,9 @@ export class IssuesProcessor { this._statistics?.incrementProcessedItemsCount(issue); issueLogger.info( - `Found this $$type last updated at: ${styles.cyan.open}${issue.updated_at}${styles.cyan.close}` + `Found this $$type last updated at: ${LoggerService.cyan( + issue.updated_at + )}` ); // calculate string based messages for this issue @@ -151,9 +155,9 @@ export class IssuesProcessor { issueLogger.info( `The option ${issueLogger.createOptionLink( Option.OnlyLabels - )} was specified to only process issues and pull requests with all those labels (${ - styles.cyan.open - }${onlyLabels.length}${styles.cyan.close})` + )} was specified to only process issues and pull requests with all those labels (${LoggerService.cyan( + onlyLabels.length + )})` ); const hasAllWhitelistedLabels: boolean = onlyLabels.every( @@ -164,7 +168,7 @@ export class IssuesProcessor { if (!hasAllWhitelistedLabels) { issueLogger.info( - `${styles.white.open}└──${styles.white.close}`, + LoggerService.white('└──'), `Skipping this $$type because it doesn't have all the required labels` ); @@ -172,11 +176,11 @@ export class IssuesProcessor { continue; // Don't process issues without all of the required labels } else { issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `All the required labels are present on this $$type` ); issueLogger.info( - `${styles.white.open}└──${styles.white.close}`, + LoggerService.white('└──'), `Continuing the process for this $$type` ); } @@ -187,13 +191,13 @@ export class IssuesProcessor { )} was not specified` ); issueLogger.info( - `${styles.white.open}└──${styles.white.close}`, + LoggerService.white('└──'), `Continuing the process for this $$type` ); } issueLogger.info( - `Days before $$type stale: ${styles.cyan.open}${daysBeforeStale}${styles.cyan.close}` + `Days before $$type stale: ${LoggerService.cyan(daysBeforeStale)}` ); const shouldMarkAsStale: boolean = shouldMarkWhenStale(daysBeforeStale); @@ -202,9 +206,9 @@ export class IssuesProcessor { issueLogger.info( `Skipping this $$type because it should be marked as stale based on the option ${issueLogger.createOptionLink( this._getDaysBeforeStaleUsedOptionName(issue) - )} (${styles.cyan.open}${daysBeforeStale}${ - styles.cyan.close - }) but the option ${issueLogger.createOptionLink( + )} (${LoggerService.cyan( + daysBeforeStale + )}) but the option ${issueLogger.createOptionLink( IssuesProcessor._getStaleMessageUsedOptionName(issue) )} is not set` ); @@ -232,9 +236,9 @@ export class IssuesProcessor { const createdAt: Date = new Date(issue.created_at); issueLogger.info( - `A start date was specified for the ${getHumanizedDate(startDate)} (${ - styles.cyan.open - }${this.options.startDate}${styles.cyan.close})` + `A start date was specified for the ${getHumanizedDate( + startDate + )} (${LoggerService.cyan(this.options.startDate)})` ); // Expecting that GitHub will always set a creation date on the issues and PRs @@ -249,9 +253,9 @@ export class IssuesProcessor { } issueLogger.info( - `$$type created the ${getHumanizedDate(createdAt)} (${ - styles.cyan.open - }${issue.created_at}${styles.cyan.close})` + `$$type created the ${getHumanizedDate( + createdAt + )} (${LoggerService.cyan(issue.created_at)})` ); if (!isDateMoreRecentThan(createdAt, startDate)) { @@ -297,9 +301,9 @@ export class IssuesProcessor { issueLogger.info( `The option ${issueLogger.createOptionLink( Option.AnyOfLabels - )} was specified to only process the issues and pull requests with one of those labels (${ - styles.cyan.open - }${anyOfLabels.length}${styles.cyan.close})` + )} was specified to only process the issues and pull requests with one of those labels (${LoggerService.cyan( + anyOfLabels.length + )})` ); const hasOneOfWhitelistedLabels: boolean = anyOfLabels.some( @@ -310,18 +314,18 @@ export class IssuesProcessor { if (!hasOneOfWhitelistedLabels) { issueLogger.info( - `${styles.white.open}└──${styles.white.close}`, + LoggerService.white('└──'), `Skipping this $$type because it doesn't have one of the required labels` ); IssuesProcessor._endIssueProcessing(issue); continue; // Don't process issues without any of the required labels } else { issueLogger.info( - `${styles.white.open}├──${styles.white.close}`, + LoggerService.white('├──'), `One of the required labels is present on this $$type` ); issueLogger.info( - `${styles.white.open}└──${styles.white.close}`, + LoggerService.white('└──'), `Continuing the process for this $$type` ); } @@ -332,7 +336,7 @@ export class IssuesProcessor { )} was not specified` ); issueLogger.info( - `${styles.white.open}└──${styles.white.close}`, + LoggerService.white('└──'), `Continuing the process for this $$type` ); } @@ -366,14 +370,14 @@ export class IssuesProcessor { issueLogger.info( `This $$type should be stale based on the last update date the ${getHumanizedDate( updatedAtDate - )} (${styles.cyan.open}${issue.updated_at}${styles.cyan.close})` + )} (${LoggerService.cyan(issue.updated_at)})` ); if (shouldMarkAsStale) { issueLogger.info( `This $$type should be marked as stale based on the option ${issueLogger.createOptionLink( this._getDaysBeforeStaleUsedOptionName(issue) - )} (${styles.cyan.open}${daysBeforeStale}${styles.cyan.close})` + )} (${LoggerService.cyan(daysBeforeStale)})` ); await this._markStale(issue, staleMessage, staleLabel, skipMessage); issue.isStale = true; // This issue is now considered stale @@ -382,14 +386,14 @@ export class IssuesProcessor { issueLogger.info( `This $$type should not be marked as stale based on the option ${issueLogger.createOptionLink( this._getDaysBeforeStaleUsedOptionName(issue) - )} (${styles.cyan.open}${daysBeforeStale}${styles.cyan.close})` + )} (${LoggerService.cyan(daysBeforeStale)})` ); } } else { issueLogger.info( `This $$type should not be stale based on the last update date the ${getHumanizedDate( updatedAtDate - )} (${styles.cyan.open}${issue.updated_at}${styles.cyan.close})` + )} (${LoggerService.cyan(issue.updated_at)})` ); } } @@ -411,23 +415,25 @@ export class IssuesProcessor { if (!this._operations.hasRemainingOperations()) { this._logger.warning( - `${styles.yellowBright.open}No more operations left! Exiting...${styles.yellowBright.close}` + LoggerService.yellowBright(`No more operations left! Exiting...`) ); this._logger.warning( - `${ - styles.yellowBright.open - }If you think that not enough issues were processed you could try to increase the quantity related to the ${this._logger.createOptionLink( + `${LoggerService.yellowBright( + 'If you think that not enough issues were processed you could try to increase the quantity related to the' + )} ${this._logger.createOptionLink( Option.OperationsPerRun - )} option which is currently set to ${styles.cyan.open}${ - this.options.operationsPerRun - }${styles.cyan.close}${styles.yellowBright.close}` + )} ${LoggerService.yellowBright( + 'option which is currently set to' + )} ${LoggerService.cyan(this.options.operationsPerRun)}` ); return 0; } this._logger.info( - `${styles.green.open}Batch ${styles.cyan.open}#${page}${styles.cyan.close} processed.${styles.green.close}` + `${LoggerService.green('Batch')} ${LoggerService.cyan( + `#${page}` + )} ${LoggerService.green('processed.')}` ); // Do the next batch @@ -545,7 +551,7 @@ export class IssuesProcessor { const markedStaleOn: string = (await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at; issueLogger.info( - `$$type marked stale on: ${styles.cyan.open}${markedStaleOn}${styles.cyan.close}` + `$$type marked stale on: ${LoggerService.cyan(markedStaleOn)}` ); const issueHasComments: boolean = await this._hasCommentsSince( @@ -554,7 +560,7 @@ export class IssuesProcessor { actor ); issueLogger.info( - `$$type has been commented on: ${styles.cyan.open}${issueHasComments}${styles.cyan.close}` + `$$type has been commented on: ${LoggerService.cyan(issueHasComments)}` ); const daysBeforeClose: number = issue.isPullRequest @@ -562,7 +568,7 @@ export class IssuesProcessor { : this._getDaysBeforeIssueClose(); issueLogger.info( - `Days before $$type close: ${styles.cyan.open}${daysBeforeClose}${styles.cyan.close}` + `Days before $$type close: ${LoggerService.cyan(daysBeforeClose)}` ); const issueHasUpdate: boolean = IssuesProcessor._updatedSince( @@ -570,7 +576,7 @@ export class IssuesProcessor { daysBeforeClose ); issueLogger.info( - `$$type has been updated: ${styles.cyan.open}${issueHasUpdate}${styles.cyan.close}` + `$$type has been updated: ${LoggerService.cyan(issueHasUpdate)}` ); // should we un-stale this issue? @@ -589,7 +595,9 @@ export class IssuesProcessor { if (!issueHasComments && !issueHasUpdate) { issueLogger.info( - `Closing $$type because it was last updated on! ${styles.cyan.open}${issue.updated_at}${styles.cyan.close}` + `Closing $$type because it was last updated on! ${LoggerService.cyan( + issue.updated_at + )}` ); await this._closeIssue(issue, closeMessage, closeLabel); @@ -618,7 +626,7 @@ export class IssuesProcessor { const issueLogger: IssueLogger = new IssueLogger(issue); issueLogger.info( - `Checking for comments on $$type since: ${styles.cyan.open}${sinceDate}${styles.cyan.close}` + `Checking for comments on $$type since: ${LoggerService.cyan(sinceDate)}` ); if (!sinceDate) { @@ -633,7 +641,9 @@ export class IssuesProcessor { ); issueLogger.info( - `Comments not made by actor or another bot: ${styles.cyan.open}${filteredComments.length}${styles.cyan.close}` + `Comments not made by actor or another bot: ${LoggerService.cyan( + filteredComments.length + )}` ); // if there are any user comments returned @@ -795,7 +805,7 @@ export class IssuesProcessor { const branch = pullRequest.head.ref; issueLogger.info( - `Deleting the branch "${styles.cyan.open}${branch}${styles.cyan.close}" from closed $$type` + `Deleting the branch "${LoggerService.cyan(branch)}" from closed $$type` ); try { @@ -808,7 +818,9 @@ export class IssuesProcessor { }); } catch (error) { issueLogger.error( - `Error when deleting the branch "${styles.cyan.open}${branch}${styles.cyan.close}" from $$type: ${error.message}` + `Error when deleting the branch "${LoggerService.cyan( + branch + )}" from $$type: ${error.message}` ); } } @@ -818,7 +830,7 @@ export class IssuesProcessor { const issueLogger: IssueLogger = new IssueLogger(issue); issueLogger.info( - `Removing the label "${styles.cyan.open}${label}${styles.cyan.close}" from this $$type...` + `Removing the label "${LoggerService.cyan(label)}" from this $$type...` ); this.removedLabelIssues.push(issue); @@ -835,12 +847,10 @@ export class IssuesProcessor { issue_number: issue.number, name: label }); - issueLogger.info( - `The label "${styles.cyan.open}${label}${styles.cyan.close}" was removed` - ); + issueLogger.info(`The label "${LoggerService.cyan(label)}" was removed`); } catch (error) { issueLogger.error( - `Error when removing the label: "${styles.cyan.open}${error.message}${styles.cyan.close}"` + `Error when removing the label: "${LoggerService.cyan(error.message)}"` ); } } @@ -945,7 +955,9 @@ export class IssuesProcessor { if (isLabeled(issue, closeLabel)) { issueLogger.info( - `The $$type has a close label "${styles.cyan.open}${closeLabel}${styles.cyan.close}". Removing the close label...` + `The $$type has a close label "${LoggerService.cyan( + closeLabel + )}". Removing the close label...` ); await this._removeLabel(issue, closeLabel); diff --git a/src/classes/loggers/issue-logger.ts b/src/classes/loggers/issue-logger.ts index 56692cf6f..1dd6c793a 100644 --- a/src/classes/loggers/issue-logger.ts +++ b/src/classes/loggers/issue-logger.ts @@ -1,6 +1,6 @@ -import styles from 'ansi-styles'; import {Issue} from '../issue'; import {Logger} from './logger'; +import {LoggerService} from '../../services/logger.service'; /** * @description @@ -70,12 +70,10 @@ export class IssueLogger extends Logger { } private _getIssuePrefix(): string { - return `${styles.red.open}[#${this._getIssueNumber()}]${styles.red.close}`; + return LoggerService.red(`[#${this._getIssueNumber()}]`); } private _getPullRequestPrefix(): string { - return `${styles.blue.open}[#${this._getIssueNumber()}]${ - styles.blue.close - }`; + return LoggerService.blue(`[#${this._getIssueNumber()}]`); } } diff --git a/src/classes/loggers/logger.ts b/src/classes/loggers/logger.ts index 861ddf09f..4d10d76bb 100644 --- a/src/classes/loggers/logger.ts +++ b/src/classes/loggers/logger.ts @@ -1,31 +1,19 @@ import * as core from '@actions/core'; -import styles from 'ansi-styles'; import terminalLink from 'terminal-link'; import {Option} from '../../enums/option'; +import {LoggerService} from '../../services/logger.service'; export class Logger { warning(...message: string[]): void { - core.warning( - `${styles.whiteBright.open}${message.join(' ')}${ - styles.whiteBright.close - }` - ); + core.warning(LoggerService.whiteBright(message.join(' '))); } info(...message: string[]): void { - core.info( - `${styles.whiteBright.open}${message.join(' ')}${ - styles.whiteBright.close - }` - ); + core.info(LoggerService.whiteBright(message.join(' '))); } error(...message: string[]): void { - core.error( - `${styles.whiteBright.open}${message.join(' ')}${ - styles.whiteBright.close - }` - ); + core.error(LoggerService.whiteBright(message.join(' '))); } createLink(name: Readonly, link: Readonly): string { @@ -33,9 +21,8 @@ export class Logger { } createOptionLink(option: Readonly