Re-merge single-line-log and render-test-runs
This commit is contained in:
Родитель
366172d473
Коммит
e280e9d18c
|
@ -1,4 +1,5 @@
|
||||||
const cli = require('heroku-cli-util')
|
const cli = require('heroku-cli-util')
|
||||||
|
const log = require('single-line-log').stdout
|
||||||
const io = require('socket.io-client')
|
const io = require('socket.io-client')
|
||||||
const api = require('./heroku-api')
|
const api = require('./heroku-api')
|
||||||
const TestRun = require('./test-run')
|
const TestRun = require('./test-run')
|
||||||
|
@ -6,6 +7,48 @@ const SingleLineLog = require('./single-line-log')
|
||||||
|
|
||||||
const SIMI = 'https://simi-production.herokuapp.com'
|
const SIMI = 'https://simi-production.herokuapp.com'
|
||||||
|
|
||||||
|
const { PENDING, CREATING, BUILDING, RUNNING, ERRORED, FAILED, SUCCEEDED } = TestRun.STATES
|
||||||
|
const STATUS_ICONS = {
|
||||||
|
[PENDING]: '⋯',
|
||||||
|
[CREATING]: '⋯',
|
||||||
|
[BUILDING]: '⋯',
|
||||||
|
[RUNNING]: '⋯',
|
||||||
|
[ERRORED]: '!',
|
||||||
|
[FAILED]: '𐄂',
|
||||||
|
[SUCCEEDED]: '✓'
|
||||||
|
}
|
||||||
|
|
||||||
|
const STATUS_COLORS = {
|
||||||
|
[PENDING]: 'yellow',
|
||||||
|
[CREATING]: 'yellow',
|
||||||
|
[BUILDING]: 'yellow',
|
||||||
|
[RUNNING]: 'yellow',
|
||||||
|
[ERRORED]: 'red',
|
||||||
|
[FAILED]: 'red',
|
||||||
|
[SUCCEEDED]: 'green'
|
||||||
|
}
|
||||||
|
|
||||||
|
function statusIcon ({ status }) {
|
||||||
|
return cli.color[STATUS_COLORS[status]](STATUS_ICONS[status])
|
||||||
|
}
|
||||||
|
|
||||||
|
function printLine (testRun) {
|
||||||
|
return `${statusIcon(testRun)} #${testRun.number} ${testRun.commit_branch}:${testRun.commit_sha.slice(0, 6)} ${testRun.status}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function limit (testRuns, count) {
|
||||||
|
return testRuns.slice(0, count)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sort (testRuns) {
|
||||||
|
return testRuns.sort((a, b) => a.number < b.number ? 1 : -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function redraw (testRuns, count = 15) {
|
||||||
|
const arranged = limit(sort(testRuns), count)
|
||||||
|
return log(arranged.map(printLine).join('\n'))
|
||||||
|
}
|
||||||
|
|
||||||
function handleTestRunEvent (newTestRun, testRuns) {
|
function handleTestRunEvent (newTestRun, testRuns) {
|
||||||
const previousTestRun = testRuns.find(({ id }) => id === newTestRun.id)
|
const previousTestRun = testRuns.find(({ id }) => id === newTestRun.id)
|
||||||
if (previousTestRun) {
|
if (previousTestRun) {
|
||||||
|
@ -18,10 +61,6 @@ function handleTestRunEvent (newTestRun, testRuns) {
|
||||||
return testRuns
|
return testRuns
|
||||||
}
|
}
|
||||||
|
|
||||||
function redraw (testRuns) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
function* render (pipeline, { heroku, watch }) {
|
function* render (pipeline, { heroku, watch }) {
|
||||||
cli.styledHeader(
|
cli.styledHeader(
|
||||||
`${watch ? 'Watching' : 'Showing'} latest test runs for the ${pipeline.name} pipeline`
|
`${watch ? 'Watching' : 'Showing'} latest test runs for the ${pipeline.name} pipeline`
|
||||||
|
@ -29,7 +68,7 @@ function* render (pipeline, { heroku, watch }) {
|
||||||
|
|
||||||
let testRuns = yield api.testRuns(heroku, pipeline.id)
|
let testRuns = yield api.testRuns(heroku, pipeline.id)
|
||||||
|
|
||||||
SingleLineLog.render(testRuns)
|
redraw(testRuns)
|
||||||
|
|
||||||
if (!watch) {
|
if (!watch) {
|
||||||
return
|
return
|
||||||
|
@ -47,14 +86,14 @@ function* render (pipeline, { heroku, watch }) {
|
||||||
socket.on('create', ({ resource, data }) => {
|
socket.on('create', ({ resource, data }) => {
|
||||||
if (resource === 'test-run') {
|
if (resource === 'test-run') {
|
||||||
testRuns = handleTestRunEvent(data, testRuns)
|
testRuns = handleTestRunEvent(data, testRuns)
|
||||||
SingleLineLog.render(testRuns)
|
redraw(testRuns)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on('update', ({ resource, data }) => {
|
socket.on('update', ({ resource, data }) => {
|
||||||
if (resource === 'test-run') {
|
if (resource === 'test-run') {
|
||||||
testRuns = handleTestRunEvent(data, testRuns)
|
testRuns = handleTestRunEvent(data, testRuns)
|
||||||
SingleLineLog.render(testRuns)
|
redraw(testRuns)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
const log = require('single-line-log').stdout
|
|
||||||
const TestRun = require('./test-run')
|
|
||||||
const cli = require('heroku-cli-util')
|
|
||||||
|
|
||||||
const { PENDING, CREATING, BUILDING, RUNNING, ERRORED, FAILED, SUCCEEDED } = TestRun.STATES
|
|
||||||
const STATUS_ICONS = {
|
|
||||||
[PENDING]: '⋯',
|
|
||||||
[CREATING]: '⋯',
|
|
||||||
[BUILDING]: '⋯',
|
|
||||||
[RUNNING]: '⋯',
|
|
||||||
[ERRORED]: '!',
|
|
||||||
[FAILED]: '𐄂',
|
|
||||||
[SUCCEEDED]: '✓'
|
|
||||||
}
|
|
||||||
|
|
||||||
const STATUS_COLORS = {
|
|
||||||
[PENDING]: 'yellow',
|
|
||||||
[CREATING]: 'yellow',
|
|
||||||
[BUILDING]: 'yellow',
|
|
||||||
[RUNNING]: 'yellow',
|
|
||||||
[ERRORED]: 'red',
|
|
||||||
[FAILED]: 'red',
|
|
||||||
[SUCCEEDED]: 'green'
|
|
||||||
}
|
|
||||||
|
|
||||||
function statusIcon ({ status }) {
|
|
||||||
return cli.color[STATUS_COLORS[status]](STATUS_ICONS[status])
|
|
||||||
}
|
|
||||||
|
|
||||||
function printLine (testRun) {
|
|
||||||
return `${statusIcon(testRun)} #${testRun.number} ${testRun.commit_branch}:${testRun.commit_sha.slice(0, 6)} ${testRun.status}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function limit (testRuns, count) {
|
|
||||||
return testRuns.slice(0, count)
|
|
||||||
}
|
|
||||||
|
|
||||||
function sort (testRuns) {
|
|
||||||
return testRuns.sort((a, b) => a.number < b.number ? 1 : -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
function render (testRuns, count = 15) {
|
|
||||||
const arranged = limit(sort(testRuns), count)
|
|
||||||
return log(arranged.map(printLine).join('\n'))
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
render
|
|
||||||
}
|
|
Загрузка…
Ссылка в новой задаче