Skip to content

Commit

Permalink
feat(pull-request): Replace cli-table with cli-table2 & Improve table…
Browse files Browse the repository at this point in the history
… formatting

node-gh#589
  • Loading branch information
hamxabaig authored and Ryan Garant committed Feb 5, 2019
1 parent 3692145 commit b85662e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
12 changes: 9 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 24 additions & 21 deletions src/cmds/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// -- Requires -------------------------------------------------------------------------------------

import * as async from 'async'
import * as Table from 'cli-table'
import * as Table from 'cli-table2'
import { startsWith } from 'lodash'
import marked from 'marked'
import TerminalRenderer from 'marked-terminal'
import * as marked from 'marked'
import * as TerminalRenderer from 'marked-terminal'
import * as openUrl from 'opn'
import wrap from 'word-wrap'
import * as wrap from 'wordwrap'
import * as base from '../base'
import * as git from '../git'
import * as hooks from '../hooks'
Expand Down Expand Up @@ -471,39 +471,42 @@ PullRequest.prototype.printPullsInfoTable_ = function(pulls) {
}

function getColWidths() {
var cols = process.stdout.columns
var noCol = 0.07 * cols,
titleCol = 0.53 * cols,
authorCol = 0.16 * cols,
dateCol = 0.13 * cols,
statusCol = 0.07 * cols

return [noCol, titleCol, authorCol, dateCol, statusCol].map(function(col) {
const cols = process.stdout.columns
const noCol = 0.07 * cols
const titleCol = 0.53 * cols
const authorCol = 0.16 * cols
const dateCol = 0.13 * cols
const statusCol = 0.07 * cols

return [noCol, titleCol, authorCol, dateCol, statusCol].map(col => {
return Math.floor(col)
})
}

function getPRBody(pull, length) {
var title = wrap(pull.title, { indent: '', width: length })
var title = wrap(length)(pull.title)
var body = ''

if (showDetails) {
marked.setOptions({
renderer: new TerminalRenderer(),
renderer: new TerminalRenderer({
width: length,
reflowText: true,
}),
})
body += logger.colors.blue('Title:')
body += '\n\n'
body += title
body += '\n\n'
body += logger.colors.blue('Body:')
body += '\n\n'
body += marked(wrap(pull.body || 'N/A', { indent: '', width: length }))
body += marked(pull.body || 'N/A')
} else {
body += title
}

if (options.link || showDetails) {
body += '\n' + logger.colors.blue(pull.html_url)
body += `\n${logger.colors.blue(pull.html_url)}`
}

return body
Expand All @@ -515,9 +518,9 @@ PullRequest.prototype.printPullsInfoTable_ = function(pulls) {
colWidths: tableWidths,
})

pulls.forEach(function(pull) {
var status = ''
var columns = []
pulls.forEach(pull => {
let status = ''
const columns = []

switch (pull.combinedStatus) {
case 'success':
Expand All @@ -528,9 +531,9 @@ PullRequest.prototype.printPullsInfoTable_ = function(pulls) {
break
}

columns.push('#' + pull.number)
columns.push(`#${pull.number}`)
columns.push(getPRBody(pull, tableWidths[1] - 5))
columns.push(logger.colors.magenta('@' + pull.user.login))
columns.push(logger.colors.magenta(`@${pull.user.login}`))
columns.push(logger.getDuration(pull.created_at))
columns.push(status)

Expand Down

0 comments on commit b85662e

Please sign in to comment.