-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.js
55 lines (52 loc) · 1.49 KB
/
helper.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
48
49
50
51
52
53
54
55
const times = require('time-ago')
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
})
/**
*
* @param {String} text any text to display before getting user input
* @returns {Promise} result of user input
*/
module.exports.getInputAsync = function getInput(text) {
return new Promise((resolve, reject) => {
readline.question(`${text}`, value => {
resolve(value)
})
})
}
/**
* We have bellow statuses in lastBuild in branch object
*
* status
* notStarted, inProgress, completed
*
* result
* undefined, failed, succeeded, canceled
*
* @param {Object} lastBuild branch last build object
* @returns {String} result of status character
*/
module.exports.getStatusChar = function getStatusChar(lastBuild) {
if (lastBuild) {
const { status, result } = lastBuild
if (status === 'notStarted') return '🕔 '
if (status === 'inProgress') return '⏳ '
if (status === 'completed' && result === 'succeeded') return '✅ '
if (status === 'completed' && result === 'failed') return '❌ '
if (status === 'completed' && result === 'canceled') return '⛔️ '
}
return ''
}
/**
*
* @param {Object} lastBuild
* @returns {String} result of times ago
*/
module.exports.timeAgo = function timeAgo(lastBuild) {
if (lastBuild && lastBuild.finishTime) {
const oldTime = new Date(lastBuild.finishTime)
return times.ago(oldTime)
}
return '-'
}