Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allows users to select which Good First Issue to pick. #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions bin/good-first-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cli
.option('-o, --open', 'Open in browser')
.option('-f, --first', 'Return first/top issue')
.option('-a, --auth <token>', '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
Expand All @@ -30,7 +31,7 @@ cli

if (!project) {
console.log('')
input = await prompt()
input = await prompt.projectsPrompt()
}

try {
Expand All @@ -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) {
Expand Down
19 changes: 18 additions & 1 deletion lib/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ''}`
Expand All @@ -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
}