Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: use http client to create github repo
closes #45
  • Loading branch information
jamesgeorge007 committed Nov 7, 2019
1 parent 775dd5f commit 8e0bada
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/utils/github.js
Expand Up @@ -72,11 +72,22 @@ const cloneRepository = async () => {
*/

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

// Create a new repository.
await execa.shell(`curl ${options}`, { stdio: 'inherit' });
try {
await axios.post(API_URL, { name: 'teachcode-solutions' });
} catch (err) {
console.log(chalk.red.bold('Error: Invalid credentials'));
console.log(err);
await createRepository();
}

// Ensure repository creation.
if (await checkIfRepositoryExists()) {
Expand All @@ -85,7 +96,6 @@ const createRepository = async () => {
await createRepository();
}
};

/**
* Configure local repository
*
Expand Down

0 comments on commit 8e0bada

Please sign in to comment.