diff --git a/bin/good-first-issue.js b/bin/good-first-issue.js index 1e8c4c1..2819b53 100755 --- a/bin/good-first-issue.js +++ b/bin/good-first-issue.js @@ -17,6 +17,7 @@ cli .option('-o, --open', 'Open in browser') .option('-f, --first', 'Return first/top issue') .option('-a, --auth ', 'Authenticate with the GitHub API (increased rate limits)') + .option('-i, --issues', 'Select from a list of all relevant issues in a project.') .action(async (project, cmd) => { const options = { // options for libgfi projects: projects @@ -30,7 +31,7 @@ cli if (!project) { console.log('') - input = await prompt() + input = await prompt.projectsPrompt() } try { @@ -41,16 +42,24 @@ cli return console.log(chalk.yellow(`\nNo Good First Issues were found for the GitHub organization, repo, or project ${chalk.white(input)}.\n`)) } - const key = cmd.first ? 0 : Math.floor(Math.random() * Math.floor(issues.length - 1)) + let issue + + if (cmd.issues && issues.length > 1) { + console.log('') + issue = await prompt.issuesPrompt(issues) + } else { + const key = cmd.first ? 0 : Math.floor(Math.random() * Math.floor(issues.length - 1)) + issue = issues[key] + } // Call the log functionality, output the result to the console. - const output = await log(issues[key], (input in projects) ? projects[input].name : project) + const output = await log(issue, (input in projects) ? projects[input].name : project) // Log the issue! console.log(output.toString()) if (cmd.open) { - opn(issues[key].url) + opn(issue.url) process.exitCode = 0 } } catch (err) { diff --git a/lib/prompt.js b/lib/prompt.js index 731b2ff..003d43b 100644 --- a/lib/prompt.js +++ b/lib/prompt.js @@ -6,7 +6,7 @@ const dataSrc = path.resolve(__dirname, '..', 'data', 'projects.json') const projects = JSON.parse(fs.readFileSync(dataSrc)) -module.exports = async function () { +module.exports.projectsPrompt = async function () { let name const projectNames = Object.keys(projects).sort().map(key => { name = `${projects[key].name}${projects[key].description ? ' - ' + projects[key].description : ''}` @@ -22,3 +22,20 @@ module.exports = async function () { ]) return a.project } + +module.exports.issuesPrompt = async function (issues) { + let name + const issueNames = issues.map(issue => { + name = `${issue.title}` + return { value: issue, name } + }) + const a = await inquirer.prompt([ + { + type: 'list', + name: 'issue', + message: 'Choose an issue:', + choices: issueNames + } + ]) + return a.issue +}