Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
refactor(issue.js): Apply new format issues functionality to `gh issu…
Browse files Browse the repository at this point in the history
…e --list`
  • Loading branch information
Ryan Garant committed Sep 22, 2018
1 parent 4d4e213 commit f7c0de3
Showing 1 changed file with 18 additions and 61 deletions.
79 changes: 18 additions & 61 deletions lib/cmds/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,71 +428,25 @@ Issue.prototype.list = function(user, repo, opt_callback) {
})

async.series(operations, function(err, results) {
var issues = []

if (err && !options.all) {
logger.error(logger.getErrorMessage(err))
}

results.forEach(function(result) {
const issues = results[0].map(result => {
if (result) {
issues = issues.concat(result)
return result
}
})

issues.sort(function(a, b) {
return a.number > b.number ? -1 : 1
})

if (issues && issues.length > 0) {
issues.forEach(function(issue) {
var labels = issue.labels || []

var headline =
logger.colors.green('#' + issue.number) +
' ' +
issue.title +
' ' +
logger.colors.magenta(
'@' + issue.user.login + ' (' + logger.getDuration(issue.created_at) + ')'
)
if (options.link) {
headline += ' ' + logger.colors.blue(issue.html_url)
}
logger.log(headline)

if (options.detailed) {
if (issue.body) {
logger.log(issue.body)
}

var labelsForDisplay = []
labels.forEach(function(label) {
labelsForDisplay.push(label.name)
})

if (labelsForDisplay.length > 0) {
var labelLabel = labelsForDisplay.length > 1 ? 'labels' : 'label'
logger.log(
logger.colors.yellow(labelLabel + ': ') + labelsForDisplay.join(', ')
)
}
const formattedIssues = formatIssues(issues, options.detailed)

if (issue.milestone) {
logger.log(
logger.colors.green('milestone: ') +
issue.milestone.title +
' - ' +
issue.milestone.number
)
}

logger.log(logger.colors.blue(issue.html_url))
}
})

opt_callback && opt_callback(err)
logger.log(formattedIssues)
} else {
logger.log('No issues.')
}

opt_callback && opt_callback(err)
})
}

Expand Down Expand Up @@ -591,17 +545,19 @@ Issue.prototype.search = function(user, repo, opt_callback, options) {
logger.error(logger.getErrorMessage(err))
}

let issues = results[0].items.map(result => {
const issues = results[0].items.map(result => {
if (result) {
return result
}
})

const formattedIssues = formatIssues(issues, options.detailed)
if (issues && issues.length > 0) {
var formattedIssues = formatIssues(issues, options.detailed)

logger.log(
formattedIssues ? formattedIssues : 'Could not find any issues matching your query.'
)
logger.log(formattedIssues)
} else {
logger.log('Could not find any issues matching your query.')
}

opt_callback && opt_callback(err, formattedIssues)
})
Expand All @@ -614,7 +570,7 @@ function formatIssues(issues, showDetailed) {

if (issues && issues.length > 0) {
const formattedIssuesArr = issues.map(issue => {
const issueNumber = logger.colors.green('#' + issue.number)
const issueNumber = logger.colors.green(`#${issue.number}`)
const issueUser = logger.colors.magenta(`@${issue.user.login}`)
const issueDate = `(${logger.getDuration(issue.created_at)})`

Expand All @@ -630,10 +586,11 @@ function formatIssues(issues, showDetailed) {

if (_.isArray(issue.labels) && issue.labels.length > 0) {
const labels = issue.labels.map(label => label.name)
const labelHeading = labels.length > 1 ? 'labels: ' : 'label: '

formattedIssue = `
${formattedIssue}
${logger.colors.green('label: ') + labels.join(', ')}
${logger.colors.yellow(labelHeading) + labels.join(', ')}
`
}

Expand Down

0 comments on commit f7c0de3

Please sign in to comment.