diff --git a/bin/good-first-issue.js b/bin/good-first-issue.js index ed7243d..ac03cee 100755 --- a/bin/good-first-issue.js +++ b/bin/good-first-issue.js @@ -51,13 +51,13 @@ cli process.exit(0) } - // Call the log functionality, output the result to the console. - let output = await log(issues, projects[input].name) + let key = cmd.first ? 0 : Math.floor(Math.random() * Math.floor(issues.length - 1)) - let key = cmd.first ? 0 : Math.floor(Math.random() * Math.floor(output.length - 1)) + // Call the log functionality, output the result to the console. + let output = await log(issues[key], projects[input].name) // Log the issue! - console.log(output[key].toString()) + console.log(output.toString()) if (cmd.open) { opn(issues[key].url) diff --git a/lib/log.js b/lib/log.js index c981250..c6f9072 100644 --- a/lib/log.js +++ b/lib/log.js @@ -6,27 +6,23 @@ var boxenOptions = { borderColor: 'green', borderStyle: 'round' } -async function log (issues, project) { - var set = [] - for (var issue in issues) { - var data = { - leftpad: ' ', - doublepad: ' ', - header: 'Good First Issue in ' + chalk.yellow(project) + ': ', - title: chalk.green(issues[issue].title), - issue: chalk.cyan('#' + issues[issue].pr), - state: chalk.green(issues[issue].state), - unassigned: chalk.green('unassigned!'), // All assigned issues are being filtered out at the search level, so all issues will always be unassigned - link: chalk.cyan(issues[issue].url), - repo: chalk.green(issues[issue].url.toString().slice(19, issues[issue].url.toString().indexOf('/issue'))), - labels: issues[issue].labels - } +async function log (issue, project) { + const data = { + leftpad: ' ', + doublepad: ' ', + header: 'Good First Issue in ' + chalk.yellow(project) + ': ', + title: chalk.green(issue.title), + issue: chalk.cyan('#' + issue.pr), + state: chalk.green(issue.state), + unassigned: chalk.green('unassigned!'), // All assigned issues are being filtered out at the search level, so all issues will always be unassigned + link: chalk.cyan(issue.url), + repo: chalk.green(issue.url.toString().slice(19, issue.url.toString().indexOf('/issue'))), + labels: issue.labels + } - var output = '\n' + boxen(data.header + '\n\n' + ' - Title: ' + data.title + '\n' + ' - Repository: ' + data.repo + '\n' + ' - Issue: ' + data.issue + '\n' + ' - Status: ' + data.state + '\n' + ' - Assigned to: ' + data.unassigned + '\n\n' + 'Start now: ' + data.link, boxenOptions) + '\n' + const output = '\n' + boxen(data.header + '\n\n' + ' - Title: ' + data.title + '\n' + ' - Repository: ' + data.repo + '\n' + ' - Issue: ' + data.issue + '\n' + ' - Status: ' + data.state + '\n' + ' - Assigned to: ' + data.unassigned + '\n\n' + 'Start now: ' + data.link, boxenOptions) + '\n' - set.push(output) - } - return set + return output } module.exports = log