Skip to content
Open
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
61 changes: 37 additions & 24 deletions bin/good-first-issue.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env node

const cli = require('commander')
const chalk = require('chalk')
const opn = require('open')
const gfi = require('libgfi')
const cli = require('commander');
const chalk = require('chalk');
const opn = require('open');
const gfi = require('libgfi');

const packageJSON = require('../package.json')
const log = require('../lib/log')
const prompt = require('../lib/prompt')
const projects = require('../data/projects.json')
const packageJSON = require('../package.json');
const log = require('../lib/log');
const prompt = require('../lib/prompt');
const projects = require('../data/projects.json');

cli
.version(packageJSON.version, '-v, --version')
Expand All @@ -20,42 +20,55 @@ cli
.action(async (project, cmd) => {
const options = { // options for libgfi
projects: projects
}
};

if (cmd.auth) {
options.auth = cmd.auth
options.auth = cmd.auth;
}

let input = project
let input = project;

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

try {
const issues = await gfi(input, options)
const issues = await gfi(input, options);

if (issues.length === 0) {
process.exitCode = 0
return console.log(chalk.yellow(`\nNo Good First Issues were found for the GitHub organization, repo, or project ${chalk.white(input)}.\n`))
process.exitCode = 0;
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))
const key = cmd.first ? 0 : Math.floor(Math.random() * Math.floor(issues.length - 1));

// 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(issues[key], (input in projects) ? projects[input].name : project);

// Log the issue!
console.log(output.toString())
console.log(output.toString());

if (cmd.open) {
opn(issues[key].url)
process.exitCode = 0
opn(issues[key].url);
process.exitCode = 0;
}
} catch (err) {
console.error(err)
process.exitCode = 1
if (err.status === 403 && err.message.includes("API rate limit exceeded")) {
console.error(
chalk.yellow("\n鈿狅笍 GitHub API rate limit exceeded.") +
"\nTip: Authenticate with a personal access token to get a higher limit." +
"\nSee: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting\n"
);
process.exitCode = 1;
} else {
console.error(chalk.red("Unexpected error:"), err.message);
process.exitCode = 1;
}
}
})
.parse(process.argv)
.parse(process.argv);