Skip to content

Commit

Permalink
refactor(logs): simplify the syntax to colour the logs
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed May 25, 2021
1 parent 3488a07 commit 57a1997
Show file tree
Hide file tree
Showing 9 changed files with 318 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
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
233 changes: 136 additions & 97 deletions dist/index.js

Large diffs are not rendered by default.

52 changes: 21 additions & 31 deletions src/classes/assignees.ts
@@ -1,11 +1,11 @@
import styles from 'ansi-styles';
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(
`${styles.white.open}└──${styles.white.close}`,
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(
`${styles.white.open}├──${styles.white.close}`,
LoggerService.white('├──'),
`No assignee option was specified to skip the stale process for this $$type`
);
this._logSkip();
Expand All @@ -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`
);
Expand All @@ -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'
);
}
Expand All @@ -92,15 +90,15 @@ 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`
);

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`
Expand All @@ -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`
);
Expand All @@ -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`
);
Expand All @@ -148,15 +142,15 @@ 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`
);

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`
Expand All @@ -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`
);
Expand All @@ -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`
);
Expand All @@ -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`
);
}
Expand Down Expand Up @@ -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'
);
}
Expand Down

0 comments on commit 57a1997

Please sign in to comment.