Skip to content

Commit 8e0bada

Browse files
fix: use http client to create github repo
closes #45
1 parent 775dd5f commit 8e0bada

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/utils/github.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,22 @@ const cloneRepository = async () => {
7272
*/
7373

7474
const createRepository = async () => {
75-
const API_URL = 'https://api.github.com/user/repos';
76-
const options = `--silent --output /dev/null -u ${GHUserName} ${API_URL} -d '{"name":"teachcode-solutions"}'`;
75+
const { userToken } = await inquirer.prompt({
76+
name: 'userToken',
77+
message: 'GitHub user token:-',
78+
type: 'password',
79+
validate,
80+
});
81+
const API_URL = `https://api.github.com/user/repos?access_token=${userToken}`;
7782

7883
// Create a new repository.
79-
await execa.shell(`curl ${options}`, { stdio: 'inherit' });
84+
try {
85+
await axios.post(API_URL, { name: 'teachcode-solutions' });
86+
} catch (err) {
87+
console.log(chalk.red.bold('Error: Invalid credentials'));
88+
console.log(err);
89+
await createRepository();
90+
}
8091

8192
// Ensure repository creation.
8293
if (await checkIfRepositoryExists()) {
@@ -85,7 +96,6 @@ const createRepository = async () => {
8596
await createRepository();
8697
}
8798
};
88-
8999
/**
90100
* Configure local repository
91101
*

0 commit comments

Comments
 (0)