forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
47 lines (41 loc) · 1.05 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict'
const chalk = require('chalk')
const CHECK = chalk.green('✔')
const X = chalk.red('✖')
const WARN = chalk.yellow('⚠')
exports.CHECK = CHECK
exports.X = X
exports.WARN = WARN
exports.rightPad = function rightPad(str, max) {
const diff = max - str.length + 1
if (diff > 0) {
return `${str}${' '.repeat(diff)}`
}
return str
}
exports.leftPad = function leftPad(str, max) {
const diff = max - str.length + 1
if (diff > 0) {
return `${' '.repeat(diff)}${str}`
}
return str
}
exports.header = (sha, status) => {
switch (status) {
case 'skip':
case 'pass':
const suffix = status === 'skip'
? ' # SKIPPED'
: ''
return `${CHECK} ${chalk.underline(sha)}${suffix}`
case 'fail':
return `${X} ${chalk.underline(sha)}`
}
}
exports.describeRule = function describeRule(rule, max = 20) {
if (rule.meta && rule.meta.description) {
const desc = rule.meta.description
const title = exports.leftPad(rule.id, max)
console.log(' %s %s', chalk.red(title), chalk.dim(desc))
}
}