Skip to content

Commit

Permalink
refactor(logs): replace chalk by ansi-styles
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed May 24, 2021
1 parent 98ed4cb commit 9821c26
Show file tree
Hide file tree
Showing 16 changed files with 2,679 additions and 4,359 deletions.
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/stale_issue_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
runs-on: ...
steps:
- uses: actions/stale@...
with:
...
with: ...
```

## Further context
Expand Down
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<!-- List the change(s) you're making with this PR. -->

## Changes

- [x] ...

## Context
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Every argument is optional.
| `repo-token` | PAT (Personal Access Token) for authorizing the repository.<br>_Defaults to **${{ github.token }}**_. |
| `days-before-stale` | Idle number of days before marking an issue/PR as stale.<br>_Defaults to **60**_. |
| `days-before-issue-stale` | Idle number of days before marking an issue as stale.<br>_Override `days-before-stale`_. |
| `days-before-pr-stale` | Idle number of days before marking a PR as stale.<br>_Override `days-before-stale`_. |
| `days-before-close` | Idle number of days before closing a stale issue/PR.<br>_Defaults to **7**_. |
| `days-before-issue-close` | Idle number of days before closing a stale issue.<br>_Override `days-before-close`_. |
| `days-before-pr-close` | Idle number of days before closing a stale PR.<br>_Override `days-before-close`_. |
| `days-before-pr-stale` | Idle number of days before marking a PR as stale.<br>_Override `days-before-stale`_. |
| `days-before-close` | Idle number of days before closing a stale issue/PR.<br>_Defaults to **7**_. |
| `days-before-issue-close` | Idle number of days before closing a stale issue.<br>_Override `days-before-close`_. |
| `days-before-pr-close` | Idle number of days before closing a stale PR.<br>_Override `days-before-close`_. |
| `stale-issue-message` | Message to post on the stale issue. |
| `stale-pr-message` | Message to post on the stale PR. |
| `close-issue-message` | Message to post on the stale issue while closing it. |
Expand Down
6,603 changes: 2,446 additions & 4,157 deletions dist/index.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions jest/test.ts
Original file line number Diff line number Diff line change
@@ -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');
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
55 changes: 34 additions & 21 deletions src/classes/assignees.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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'
);

Expand All @@ -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();
Expand All @@ -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`
);
Expand All @@ -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'
);
}
Expand All @@ -90,15 +92,15 @@ 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`
);

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

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

0 comments on commit 9821c26

Please sign in to comment.