diff --git a/lib/cmds/issue.js b/lib/cmds/issue.js index c7364a1e..8df5c033 100644 --- a/lib/cmds/issue.js +++ b/lib/cmds/issue.js @@ -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) }) } @@ -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) }) @@ -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)})` @@ -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(', ')} ` }