From 84190155492eb4cb6df5fcfac48062c460b36de7 Mon Sep 17 00:00:00 2001 From: Geoffrey Testelin Date: Tue, 25 May 2021 00:03:46 +0200 Subject: [PATCH 1/5] refactor(logs): replace chalk by ansi-styles --- README.md | 8 +- jest/test.ts | 6 +- package-lock.json | 99 ++++++++----------- package.json | 2 +- src/classes/assignees.ts | 55 +++++++---- src/classes/issues-processor.ts | 142 ++++++++++++++-------------- src/classes/loggers/issue-logger.ts | 8 +- src/classes/loggers/logger.ts | 27 ++++-- src/classes/milestones.ts | 55 +++++++---- src/classes/statistics.ts | 16 +++- tsconfig.app.json | 2 +- tsconfig.json | 2 +- tsconfig.spec.json | 2 +- 13 files changed, 227 insertions(+), 197 deletions(-) diff --git a/README.md b/README.md index 5b7d3744f..69f0608c8 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ Every argument is optional. | [repo-token](#repo-token) | PAT for GitHub API authentication | `${{ github.token }}` | | [days-before-stale](#days-before-stale) | Idle number of days before marking issues/PRs stale | `60` | | [days-before-issue-stale](#days-before-issue-stale) | Override [days-before-stale](#days-before-stale) for issues only | | -| [days-before-pr-stale](#days-before-pr-stale) | Override [days-before-stale](#days-before-stale) for PRs only | | -| [days-before-close](#days-before-close) | Idle number of days before closing stale issues/PRs | `7` | -| [days-before-issue-close](#days-before-issue-close) | Override [days-before-close](#days-before-close) for issues only | | -| [days-before-pr-close](#days-before-pr-close) | Override [days-before-close](#days-before-close) for PRs only | | +| [days-before-pr-stale](#days-before-pr-stale) | Override [days-before-stale](#days-before-stale) for PRs only | | +| [days-before-close](#days-before-close) | Idle number of days before closing stale issues/PRs | `7` | +| [days-before-issue-close](#days-before-issue-close) | Override [days-before-close](#days-before-close) for issues only | | +| [days-before-pr-close](#days-before-pr-close) | Override [days-before-close](#days-before-close) for PRs only | | | [stale-issue-message](#stale-issue-message) | Comment on the staled issues | | | [stale-pr-message](#stale-pr-message) | Comment on the staled PRs | | | [close-issue-message](#close-issue-message) | Comment on the staled issues while closed | | diff --git a/jest/test.ts b/jest/test.ts index f8eaa1bdf..d6dd801e9 100644 --- a/jest/test.ts +++ b/jest/test.ts @@ -1,11 +1,9 @@ -import chalk from 'chalk'; - // Disabled the colors to: // - improve the performances -// - avoid to mock chalk +// - avoid to mock styles // - avoid to have failing tests when testing the logs due to the extra text the log message will contains // // Note: // If you need to debug the log colours you can remove this line temporarily // But some tests will fail -chalk.level = 0; +jest.mock('ansi-styles'); diff --git a/package-lock.json b/package-lock.json index 5cc0047ef..3145c941b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -217,6 +217,17 @@ "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", "supports-color": "^5.3.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + } } } } @@ -2081,13 +2092,10 @@ "dev": true }, "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "dev": true }, "anymatch": { "version": "2.0.0", @@ -2556,57 +2564,6 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", "dev": true }, - "chalk": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", - "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", - "dev": true, - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "dependencies": { - "ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "requires": { - "color-convert": "^2.0.1" - } - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true - }, - "supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "requires": { - "has-flag": "^4.0.0" - } - } - } - }, "char-regex": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz", @@ -3167,7 +3124,33 @@ "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", "supports-color": "^5.3.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + } + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true } } }, diff --git a/package.json b/package.json index a14e0a4bc..e0e932122 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@typescript-eslint/eslint-plugin": "^4.16.1", "@typescript-eslint/parser": "^4.22.1", "@vercel/ncc": "^0.27.0", - "chalk": "^4.1.0", + "ansi-styles": "5.2.0", "eslint": "^7.21.0", "eslint-plugin-github": "^4.1.2", "eslint-plugin-jest": "^24.3.6", diff --git a/src/classes/assignees.ts b/src/classes/assignees.ts index 9a0a2a259..011a305ac 100644 --- a/src/classes/assignees.ts +++ b/src/classes/assignees.ts @@ -1,4 +1,4 @@ -import chalk from 'chalk'; +import styles from 'ansi-styles'; import deburr from 'lodash.deburr'; import {Option} from '../enums/option'; import {wordsToList} from '../functions/words-to-list'; @@ -34,7 +34,7 @@ export class Assignees { if (this._shouldExemptAllAssignees()) { this._issueLogger.info( - chalk.white('└──'), + `${styles.white.open}└──${styles.white.close}`, 'Skipping this $$type because it has an exempt assignee' ); @@ -45,7 +45,7 @@ export class Assignees { if (exemptAssignees.length === 0) { this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `No assignee option was specified to skip the stale process for this $$type` ); this._logSkip(); @@ -54,8 +54,10 @@ export class Assignees { } this._issueLogger.info( - chalk.white('├──'), - `Found ${chalk.cyan(exemptAssignees.length)} assignee${ + `${styles.white.open}├──${styles.white.close}`, + `Found ${styles.cyan.open}${exemptAssignees.length}${ + styles.cyan.close + } assignee${ exemptAssignees.length > 1 ? 's' : '' } that can exempt stale on this $$type` ); @@ -67,13 +69,13 @@ export class Assignees { if (!hasExemptAssignee) { this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, 'No assignee on this $$type can exempt the stale process' ); this._logSkip(); } else { this._issueLogger.info( - chalk.white('└──'), + `${styles.white.open}└──${styles.white.close}`, 'Skipping this $$type because it has an exempt assignee' ); } @@ -90,7 +92,7 @@ export class Assignees { private _getExemptIssueAssignees(): string[] { if (this._options.exemptIssueAssignees === '') { this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `The option ${this._issueLogger.createOptionLink( Option.ExemptIssueAssignees )} is disabled. No specific assignee can skip the stale process for this $$type` @@ -98,7 +100,7 @@ export class Assignees { if (this._options.exemptAssignees === '') { this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `The option ${this._issueLogger.createOptionLink( Option.ExemptAssignees )} is disabled. No specific assignee can skip the stale process for this $$type` @@ -112,10 +114,12 @@ export class Assignees { ); this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `The option ${this._issueLogger.createOptionLink( Option.ExemptAssignees - )} is set. ${chalk.cyan(exemptAssignees.length)} assignee${ + )} is set. ${styles.cyan.open}${exemptAssignees.length}${ + styles.cyan.close + } assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -128,10 +132,12 @@ export class Assignees { ); this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `The option ${this._issueLogger.createOptionLink( Option.ExemptIssueAssignees - )} is set. ${chalk.cyan(exemptAssignees.length)} assignee${ + )} is set. ${styles.cyan.open}${exemptAssignees.length}${ + styles.cyan.close + } assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -142,7 +148,7 @@ export class Assignees { private _getExemptPullRequestAssignees(): string[] { if (this._options.exemptPrAssignees === '') { this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `The option ${this._issueLogger.createOptionLink( Option.ExemptPrAssignees )} is disabled. No specific assignee can skip the stale process for this $$type` @@ -150,7 +156,7 @@ export class Assignees { if (this._options.exemptAssignees === '') { this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `The option ${this._issueLogger.createOptionLink( Option.ExemptAssignees )} is disabled. No specific assignee can skip the stale process for this $$type` @@ -164,10 +170,12 @@ export class Assignees { ); this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `The option ${this._issueLogger.createOptionLink( Option.ExemptAssignees - )} is set. ${chalk.cyan(exemptAssignees.length)} assignee${ + )} is set. ${styles.cyan.open}${exemptAssignees.length}${ + styles.cyan.close + } assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -180,10 +188,12 @@ export class Assignees { ); this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `The option ${this._issueLogger.createOptionLink( Option.ExemptPrAssignees - )} is set. ${chalk.cyan(exemptAssignees.length)} assignee${ + )} is set. ${styles.cyan.open}${exemptAssignees.length}${ + styles.cyan.close + } assignee${ exemptAssignees.length === 1 ? '' : 's' } can skip the stale process for this $$type` ); @@ -201,7 +211,7 @@ export class Assignees { if (isSameAssignee) { this._issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `@${issueAssignee.login} is assigned on this $$type and is an exempt assignee` ); } @@ -282,6 +292,9 @@ export class Assignees { } private _logSkip(): void { - this._issueLogger.info(chalk.white('└──'), 'Skip the assignees checks'); + this._issueLogger.info( + `${styles.white.open}└──${styles.white.close}`, + 'Skip the assignees checks' + ); } } diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 6c951bab4..5a6982eef 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -2,7 +2,7 @@ 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 chalk from 'chalk'; +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'; @@ -43,7 +43,7 @@ export class IssuesProcessor { const issueLogger: IssueLogger = new IssueLogger(issue); issueLogger.info( - chalk.cyan(consumedOperationsCount), + `${styles.cyan.open}${consumedOperationsCount}${styles.cyan.close}`, `operation${ consumedOperationsCount > 1 ? 's' : '' } consumed for this $$type` @@ -74,14 +74,16 @@ export class IssuesProcessor { this.client = getOctokit(this.options.repoToken); this._operations = new StaleOperations(this.options); - this._logger.info(chalk.yellow('Starting the stale action process...')); + this._logger.info( + `${styles.yellow.open}Starting the stale action process...${styles.yellow.close}` + ); if (this.options.debugOnly) { - this._logger.warning(chalk.yellowBright('Executing in debug mode!')); this._logger.warning( - chalk.yellowBright( - 'The debug output will be written but no issues/PRs will be processed.' - ) + `${styles.yellowBright.open}Executing in debug mode!${styles.yellowBright.close}` + ); + this._logger.warning( + `${styles.yellowBright.open}The debug output will be written but no issues/PRs will be processed.${styles.yellowBright.close}` ); } @@ -97,7 +99,7 @@ export class IssuesProcessor { if (issues.length <= 0) { this._logger.info( - chalk.green('No more issues found to process. Exiting...') + `${styles.green.open}No more issues found to process. Exiting...${styles.green.close}` ); this._statistics ?.setRemainingOperations(this._operations.getRemainingOperationsCount()) @@ -106,13 +108,13 @@ export class IssuesProcessor { return this._operations.getRemainingOperationsCount(); } else { this._logger.info( - chalk.yellow( - `Processing the batch of issues ${chalk.cyan( - `#${page}` - )} containing ${chalk.cyan(issues.length)} issue${ - issues.length > 1 ? 's' : '' - }...` - ) + `${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 + }` ); } @@ -121,7 +123,7 @@ export class IssuesProcessor { this._statistics?.incrementProcessedItemsCount(issue); issueLogger.info( - `Found this $$type last updated at: ${chalk.cyan(issue.updated_at)}` + `Found this $$type last updated at: ${styles.cyan.open}${issue.updated_at}${styles.cyan.close}` ); // calculate string based messages for this issue @@ -149,9 +151,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 (${chalk.cyan( - onlyLabels.length - )})` + )} was specified to only process issues and pull requests with all those labels (${ + styles.cyan.open + }${onlyLabels.length}${styles.cyan.close})` ); const hasAllWhitelistedLabels: boolean = onlyLabels.every( @@ -162,7 +164,7 @@ export class IssuesProcessor { if (!hasAllWhitelistedLabels) { issueLogger.info( - chalk.white('└──'), + `${styles.white.open}└──${styles.white.close}`, `Skipping this $$type because it doesn't have all the required labels` ); @@ -170,11 +172,11 @@ export class IssuesProcessor { continue; // Don't process issues without all of the required labels } else { issueLogger.info( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `All the required labels are present on this $$type` ); issueLogger.info( - chalk.white('└──'), + `${styles.white.open}└──${styles.white.close}`, `Continuing the process for this $$type` ); } @@ -185,13 +187,13 @@ export class IssuesProcessor { )} was not specified` ); issueLogger.info( - chalk.white('└──'), + `${styles.white.open}└──${styles.white.close}`, `Continuing the process for this $$type` ); } issueLogger.info( - `Days before $$type stale: ${chalk.cyan(daysBeforeStale)}` + `Days before $$type stale: ${styles.cyan.open}${daysBeforeStale}${styles.cyan.close}` ); const shouldMarkAsStale: boolean = shouldMarkWhenStale(daysBeforeStale); @@ -216,9 +218,9 @@ export class IssuesProcessor { const createdAt: Date = new Date(issue.created_at); issueLogger.info( - `A start date was specified for the ${getHumanizedDate( - startDate - )} (${chalk.cyan(this.options.startDate)})` + `A start date was specified for the ${getHumanizedDate(startDate)} (${ + styles.cyan.open + }${this.options.startDate}${styles.cyan.close})` ); // Expecting that GitHub will always set a creation date on the issues and PRs @@ -233,9 +235,9 @@ export class IssuesProcessor { } issueLogger.info( - `$$type created the ${getHumanizedDate(createdAt)} (${chalk.cyan( - issue.created_at - )})` + `$$type created the ${getHumanizedDate(createdAt)} (${ + styles.cyan.open + }${issue.created_at}${styles.cyan.close})` ); if (!isDateMoreRecentThan(createdAt, startDate)) { @@ -281,9 +283,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 (${chalk.cyan( - anyOfLabels.length - )})` + )} was specified to only process the issues and pull requests with one of those labels (${ + styles.cyan.open + }${anyOfLabels.length}${styles.cyan.close})` ); const hasOneOfWhitelistedLabels: boolean = anyOfLabels.some( @@ -294,18 +296,18 @@ export class IssuesProcessor { if (!hasOneOfWhitelistedLabels) { issueLogger.info( - chalk.white('└──'), + `${styles.white.open}└──${styles.white.close}`, `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( - chalk.white('├──'), + `${styles.white.open}├──${styles.white.close}`, `One of the required labels is present on this $$type` ); issueLogger.info( - chalk.white('└──'), + `${styles.white.open}└──${styles.white.close}`, `Continuing the process for this $$type` ); } @@ -316,7 +318,7 @@ export class IssuesProcessor { )} was not specified` ); issueLogger.info( - chalk.white('└──'), + `${styles.white.open}└──${styles.white.close}`, `Continuing the process for this $$type` ); } @@ -350,14 +352,14 @@ export class IssuesProcessor { issueLogger.info( `This $$type should be stale based on the last update date the ${getHumanizedDate( updatedAtDate - )} (${chalk.cyan(issue.updated_at)})` + )} (${styles.cyan.open}${issue.updated_at}${styles.cyan.close})` ); if (shouldMarkAsStale) { issueLogger.info( `This $$type should be marked as stale based on the option ${issueLogger.createOptionLink( this._getDaysBeforeStaleUsedOptionName(issue) - )} (${chalk.cyan(daysBeforeStale)})` + )} (${styles.cyan.open}${daysBeforeStale}${styles.cyan.close})` ); await this._markStale(issue, staleMessage, staleLabel, skipMessage); issue.isStale = true; // This issue is now considered stale @@ -366,14 +368,14 @@ export class IssuesProcessor { issueLogger.info( `This $$type should not be marked as stale based on the option ${issueLogger.createOptionLink( this._getDaysBeforeStaleUsedOptionName(issue) - )} (${chalk.cyan(daysBeforeStale)})` + )} (${styles.cyan.open}${daysBeforeStale}${styles.cyan.close})` ); } } else { issueLogger.info( `This $$type should not be stale based on the last update date the ${getHumanizedDate( updatedAtDate - )} (${chalk.cyan(issue.updated_at)})` + )} (${styles.cyan.open}${issue.updated_at}${styles.cyan.close})` ); } } @@ -395,23 +397,23 @@ export class IssuesProcessor { if (!this._operations.hasRemainingOperations()) { this._logger.warning( - chalk.yellowBright('No more operations left! Exiting...') + `${styles.yellowBright.open}No more operations left! Exiting...${styles.yellowBright.close}` ); this._logger.warning( - chalk.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 ${chalk.cyan( - this.options.operationsPerRun - )}` - ) + `${ + 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( + Option.OperationsPerRun + )} option which is currently set to ${styles.cyan.open}${ + this.options.operationsPerRun + }${styles.cyan.close}${styles.yellowBright.close}` ); return 0; } this._logger.info( - chalk.green(`Batch ${chalk.cyan(`#${page}`)} processed.`) + `${styles.green.open}Batch ${styles.cyan.open}#${page}${styles.cyan.close} processed.${styles.green.close}` ); // Do the next batch @@ -528,7 +530,9 @@ export class IssuesProcessor { const issueLogger: IssueLogger = new IssueLogger(issue); const markedStaleOn: string = (await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at; - issueLogger.info(`$$type marked stale on: ${chalk.cyan(markedStaleOn)}`); + issueLogger.info( + `$$type marked stale on: ${styles.cyan.open}${markedStaleOn}${styles.cyan.close}` + ); const issueHasComments: boolean = await this._hasCommentsSince( issue, @@ -536,7 +540,7 @@ export class IssuesProcessor { actor ); issueLogger.info( - `$$type has been commented on: ${chalk.cyan(issueHasComments)}` + `$$type has been commented on: ${styles.cyan.open}${issueHasComments}${styles.cyan.close}` ); const daysBeforeClose: number = issue.isPullRequest @@ -544,14 +548,16 @@ export class IssuesProcessor { : this._getDaysBeforeIssueClose(); issueLogger.info( - `Days before $$type close: ${chalk.cyan(daysBeforeClose)}` + `Days before $$type close: ${styles.cyan.open}${daysBeforeClose}${styles.cyan.close}` ); const issueHasUpdate: boolean = IssuesProcessor._updatedSince( issue.updated_at, daysBeforeClose ); - issueLogger.info(`$$type has been updated: ${chalk.cyan(issueHasUpdate)}`); + issueLogger.info( + `$$type has been updated: ${styles.cyan.open}${issueHasUpdate}${styles.cyan.close}` + ); // should we un-stale this issue? if (this._shouldRemoveStaleWhenUpdated(issue) && issueHasComments) { @@ -569,9 +575,7 @@ export class IssuesProcessor { if (!issueHasComments && !issueHasUpdate) { issueLogger.info( - `Closing $$type because it was last updated on! ${chalk.cyan( - issue.updated_at - )}` + `Closing $$type because it was last updated on! ${styles.cyan.open}${issue.updated_at}${styles.cyan.close}` ); await this._closeIssue(issue, closeMessage, closeLabel); @@ -600,7 +604,7 @@ export class IssuesProcessor { const issueLogger: IssueLogger = new IssueLogger(issue); issueLogger.info( - `Checking for comments on $$type since: ${chalk.cyan(sinceDate)}` + `Checking for comments on $$type since: ${styles.cyan.open}${sinceDate}${styles.cyan.close}` ); if (!sinceDate) { @@ -615,9 +619,7 @@ export class IssuesProcessor { ); issueLogger.info( - `Comments not made by actor or another bot: ${chalk.cyan( - filteredComments.length - )}` + `Comments not made by actor or another bot: ${styles.cyan.open}${filteredComments.length}${styles.cyan.close}` ); // if there are any user comments returned @@ -779,7 +781,7 @@ export class IssuesProcessor { const branch = pullRequest.head.ref; issueLogger.info( - `Deleting the branch "${chalk.cyan(branch)}" from closed $$type` + `Deleting the branch "${styles.cyan.open}${branch}${styles.cyan.close}" from closed $$type` ); try { @@ -792,9 +794,7 @@ export class IssuesProcessor { }); } catch (error) { issueLogger.error( - `Error when deleting the branch "${chalk.cyan(branch)}" from $$type: ${ - error.message - }` + `Error when deleting the branch "${styles.cyan.open}${branch}${styles.cyan.close}" from $$type: ${error.message}` ); } } @@ -804,7 +804,7 @@ export class IssuesProcessor { const issueLogger: IssueLogger = new IssueLogger(issue); issueLogger.info( - `Removing the label "${chalk.cyan(label)}" from this $$type...` + `Removing the label "${styles.cyan.open}${label}${styles.cyan.close}" from this $$type...` ); this.removedLabelIssues.push(issue); @@ -821,10 +821,12 @@ export class IssuesProcessor { issue_number: issue.number, name: label }); - issueLogger.info(`The label "${chalk.cyan(label)}" was removed`); + issueLogger.info( + `The label "${styles.cyan.open}${label}${styles.cyan.close}" was removed` + ); } catch (error) { issueLogger.error( - `Error when removing the label: "${chalk.cyan(error.message)}"` + `Error when removing the label: "${styles.cyan.open}${error.message}${styles.cyan.close}"` ); } } @@ -929,9 +931,7 @@ export class IssuesProcessor { if (isLabeled(issue, closeLabel)) { issueLogger.info( - `The $$type has a close label "${chalk.cyan( - closeLabel - )}". Removing the close label...` + `The $$type has a close label "${styles.cyan.open}${closeLabel}${styles.cyan.close}". 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 5db113018..56692cf6f 100644 --- a/src/classes/loggers/issue-logger.ts +++ b/src/classes/loggers/issue-logger.ts @@ -1,4 +1,4 @@ -import chalk from 'chalk'; +import styles from 'ansi-styles'; import {Issue} from '../issue'; import {Logger} from './logger'; @@ -70,10 +70,12 @@ export class IssueLogger extends Logger { } private _getIssuePrefix(): string { - return chalk.red(`[#${this._getIssueNumber()}]`); + return `${styles.red.open}[#${this._getIssueNumber()}]${styles.red.close}`; } private _getPullRequestPrefix(): string { - return chalk.blue(`[#${this._getIssueNumber()}]`); + return `${styles.blue.open}[#${this._getIssueNumber()}]${ + styles.blue.close + }`; } } diff --git a/src/classes/loggers/logger.ts b/src/classes/loggers/logger.ts index 65bb83afd..861ddf09f 100644 --- a/src/classes/loggers/logger.ts +++ b/src/classes/loggers/logger.ts @@ -1,19 +1,31 @@ import * as core from '@actions/core'; -import chalk from 'chalk'; +import styles from 'ansi-styles'; import terminalLink from 'terminal-link'; import {Option} from '../../enums/option'; export class Logger { warning(...message: string[]): void { - core.warning(chalk.whiteBright(...message)); + core.warning( + `${styles.whiteBright.open}${message.join(' ')}${ + styles.whiteBright.close + }` + ); } info(...message: string[]): void { - core.info(chalk.whiteBright(...message)); + core.info( + `${styles.whiteBright.open}${message.join(' ')}${ + styles.whiteBright.close + }` + ); } error(...message: string[]): void { - core.error(chalk.whiteBright(...message)); + core.error( + `${styles.whiteBright.open}${message.join(' ')}${ + styles.whiteBright.close + }` + ); } createLink(name: Readonly, link: Readonly): string { @@ -21,8 +33,9 @@ export class Logger { } createOptionLink(option: Readonly