fix(logs): coloured logs (#465)

* refactor(logs): replace chalk by ansi-styles

* test(logs): fix the failing tests due to ansi styles

I was not able to disable or mock ansi-styles so instead I found a way to make the tests pass
it's not perfect but it's still nice because the logs will keep their trustful colour when running through the tests

* refactor(logs): simplify the syntax to colour the logs

* chore(rebase): update files due to rebase

* refactor(logger): reduce code duplication
This commit is contained in:
Geoffrey Testelin
2021-06-02 23:04:34 +02:00
committed by GitHub
parent e884599072
commit 5fbbfba142
15 changed files with 671 additions and 2262 deletions

View File

@@ -1,10 +1,10 @@
import chalk from 'chalk';
import deburr from 'lodash.deburr';
import {Option} from '../enums/option';
import {wordsToList} from '../functions/words-to-list';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
import {LoggerService} from '../services/logger.service';
type CleanMilestone = string;
@@ -33,7 +33,7 @@ export class Milestones {
if (this._shouldExemptAllMilestones()) {
this._issueLogger.info(
chalk.white('└──'),
LoggerService.white('└──'),
'Skipping this $$type because it has a milestone'
);
@@ -44,7 +44,7 @@ export class Milestones {
if (exemptMilestones.length === 0) {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`No milestone option was specified to skip the stale process for this $$type`
);
this._logSkip();
@@ -53,8 +53,8 @@ export class Milestones {
}
this._issueLogger.info(
chalk.white('├──'),
`Found ${chalk.cyan(exemptMilestones.length)} milestone${
LoggerService.white('├──'),
`Found ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length > 1 ? 's' : ''
} that can exempt stale on this $$type`
);
@@ -66,13 +66,13 @@ export class Milestones {
if (!hasExemptMilestone) {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
'No milestone on this $$type can exempt the stale process'
);
this._logSkip();
} else {
this._issueLogger.info(
chalk.white('└──'),
LoggerService.white('└──'),
'Skipping this $$type because it has an exempt milestone'
);
}
@@ -89,7 +89,7 @@ export class Milestones {
private _getExemptIssueMilestones(): string[] {
if (this._options.exemptIssueMilestones === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
@@ -97,7 +97,7 @@ export class Milestones {
if (this._options.exemptMilestones === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
@@ -111,10 +111,10 @@ export class Milestones {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is set. ${chalk.cyan(exemptMilestones.length)} milestone${
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -127,10 +127,10 @@ export class Milestones {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueMilestones
)} is set. ${chalk.cyan(exemptMilestones.length)} milestone${
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -141,7 +141,7 @@ export class Milestones {
private _getExemptPullRequestMilestones(): string[] {
if (this._options.exemptPrMilestones === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
@@ -149,7 +149,7 @@ export class Milestones {
if (this._options.exemptMilestones === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
@@ -163,10 +163,10 @@ export class Milestones {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is set. ${chalk.cyan(exemptMilestones.length)} milestone${
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -179,10 +179,10 @@ export class Milestones {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrMilestones
)} is set. ${chalk.cyan(exemptMilestones.length)} milestone${
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -205,8 +205,10 @@ export class Milestones {
if (isSameMilestone) {
this._issueLogger.info(
chalk.white('├──'),
`The milestone "${milestone}" is set on this $$type and is an exempt milestone`
LoggerService.white('├──'),
`The milestone "${LoggerService.cyan(
milestone
)}" is set on this $$type and is an exempt milestone`
);
}
@@ -288,6 +290,9 @@ export class Milestones {
}
private _logSkip(): void {
this._issueLogger.info(chalk.white('└──'), 'Skip the milestones checks');
this._issueLogger.info(
LoggerService.white('└──'),
'Skip the milestones checks'
);
}
}