Skip to content

Commit 26f3868

Browse files
rishabhKalakotijamesgeorge007
authored andcommitted
feat: prompt user to create a personal access token beforehand (#48)
* feat: prompt user to create a personal access token for github cli * feat: prompt user to create a personal access token for github cli * chore: update lock file * chore: tweaks
1 parent 275392b commit 26f3868

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"execa": "^1.0.0",
5252
"inquirer": "^6.2.0",
5353
"node-banner": "^1.3.2",
54-
"python-shell": "^1.0.7"
54+
"python-shell": "^1.0.7",
55+
"open": "^7.0.0"
5556
},
5657
"devDependencies": {
5758
"@commitlint/cli": "^8.2.0",

src/commands/init.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { execSync } = require('child_process');
55
const fs = require('fs');
66
const inquirer = require('inquirer');
77
const showBanner = require('node-banner');
8+
const open = require('open');
89

910
// GitHub workflow helper methods.
1011
const {
@@ -45,6 +46,28 @@ const showInstructions = kickStart => {
4546
console.log(chalk.cyan.bold(` 2. teachcode fetchtask ${key}`));
4647
};
4748

49+
const promptAccessTokenCreation = async () => {
50+
const instructionsUrl =
51+
'https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line';
52+
console.log();
53+
console.log(
54+
chalk.greenBright(
55+
'You are required to have a personal access token for consuming the GitHub API.\nIf you do not have one, please follow these instructions.\n',
56+
),
57+
);
58+
const { openInBrowser } = await inquirer.prompt([
59+
{
60+
name: 'openInBrowser',
61+
type: 'confirm',
62+
message: 'Open browser to read instructions?',
63+
},
64+
]);
65+
if (openInBrowser) {
66+
// open link in the default browser
67+
await open(instructionsUrl);
68+
}
69+
};
70+
4871
/**
4972
* Initialize all the tasks
5073
*
@@ -122,6 +145,7 @@ const initTasks = async () => {
122145
let kickStart;
123146

124147
if (shouldCreateRepository) {
148+
await promptAccessTokenCreation();
125149
await createRepository();
126150
kickStart = true;
127151

0 commit comments

Comments
 (0)