Skip to content

Commit

Permalink
fix(logs): coloured logs (#465)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
C0ZEN authored Jun 2, 2021
1 parent e884599 commit 5fbbfba
Show file tree
Hide file tree
Showing 15 changed files with 689 additions and 2,280 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2,489 changes: 410 additions & 2,079 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ module.exports = {
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true,
setupFilesAfterEnv: [`./jest/test.ts`]
verbose: true
};
11 changes: 0 additions & 11 deletions jest/test.ts

This file was deleted.

99 changes: 41 additions & 58 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
45 changes: 24 additions & 21 deletions src/classes/assignees.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import chalk from 'chalk';
import deburr from 'lodash.deburr';
import {Option} from '../enums/option';
import {wordsToList} from '../functions/words-to-list';
import {IAssignee} from '../interfaces/assignee';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
import {LoggerService} from '../services/logger.service';

type CleanAssignee = string;

Expand Down Expand Up @@ -34,7 +34,7 @@ export class Assignees {

if (this._shouldExemptAllAssignees()) {
this._issueLogger.info(
chalk.white('└──'),
LoggerService.white('└──'),
'Skipping this $$type because it has an exempt assignee'
);

Expand All @@ -45,7 +45,7 @@ export class Assignees {

if (exemptAssignees.length === 0) {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`No assignee option was specified to skip the stale process for this $$type`
);
this._logSkip();
Expand All @@ -54,8 +54,8 @@ export class Assignees {
}

this._issueLogger.info(
chalk.white('├──'),
`Found ${chalk.cyan(exemptAssignees.length)} assignee${
LoggerService.white('├──'),
`Found ${LoggerService.cyan(exemptAssignees.length)} assignee${
exemptAssignees.length > 1 ? 's' : ''
} that can exempt stale on this $$type`
);
Expand All @@ -67,13 +67,13 @@ export class Assignees {

if (!hasExemptAssignee) {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
'No assignee 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 assignee'
);
}
Expand All @@ -90,15 +90,15 @@ export class Assignees {
private _getExemptIssueAssignees(): string[] {
if (this._options.exemptIssueAssignees === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
);

if (this._options.exemptAssignees === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
Expand All @@ -112,10 +112,10 @@ export class Assignees {
);

this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is set. ${chalk.cyan(exemptAssignees.length)} assignee${
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
Expand All @@ -128,10 +128,10 @@ export class Assignees {
);

this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueAssignees
)} is set. ${chalk.cyan(exemptAssignees.length)} assignee${
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
Expand All @@ -142,15 +142,15 @@ export class Assignees {
private _getExemptPullRequestAssignees(): string[] {
if (this._options.exemptPrAssignees === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
);

if (this._options.exemptAssignees === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
Expand All @@ -164,10 +164,10 @@ export class Assignees {
);

this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is set. ${chalk.cyan(exemptAssignees.length)} assignee${
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
Expand All @@ -180,10 +180,10 @@ export class Assignees {
);

this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrAssignees
)} is set. ${chalk.cyan(exemptAssignees.length)} assignee${
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
Expand All @@ -201,7 +201,7 @@ export class Assignees {

if (isSameAssignee) {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`@${issueAssignee.login} is assigned on this $$type and is an exempt assignee`
);
}
Expand Down Expand Up @@ -282,6 +282,9 @@ export class Assignees {
}

private _logSkip(): void {
this._issueLogger.info(chalk.white('└──'), 'Skip the assignees checks');
this._issueLogger.info(
LoggerService.white('└──'),
'Skip the assignees checks'
);
}
}
Loading

0 comments on commit 5fbbfba

Please sign in to comment.