Last active
January 19, 2017 07:28
-
-
Save goozbach/1b1aa6c780c71e9bc052e9f286a9c39b to your computer and use it in GitHub Desktop.
Revisions
-
goozbach revised this gist
Jan 19, 2017 . 1 changed file with 50 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,35 +1,66 @@ gitcreate() { # usage: gitcreate <reponame> [--push] # requires 'jq' to be installed # Seed of this idea came from http://www.karan.org/blog/2017/01/13/create-a-new-github-com-repo-from-the-cli/ REPONAME=${1} PUSH=${2} # This function only works in a git repo. if [[ ! -d .git ]] then echo "Error: This needs to be ran in the top-level directory of an already existing git repo." return 2 fi # We need to have a secret token to access github API. if [[ ! -r ~/.gitcreate_secret ]] then echo "Error: You must generate a personal access token and place it in the file '~/.gitcreate_secret'" echo echo " '~/.gitcreate_secret' format:" echo echo " GITHUB_AUTH=<username>:<personal_access_token>" echo echo "Generate a 'personal access token' here: https://github.com/settings/tokens" return 2 fi source ~/.gitcreate_secret # Actual API call TEMPJSON=$(mktemp .git/github-info-XXXX) curl -s -u ${GITHUB_AUTH} https://api.github.com/user/repos -d "{\"name\":\"${REPONAME}\"}" > ${TEMPJSON} # Check status of request and print error messages if grep -qs 'error' ${TEMPJSON} then REQMSG=$(jq -r '.message' ${TEMPJSON}) ERRSTR=$(jq -r '.errors[0].message' ${TEMPJSON}) echo echo "Error creating repo: ${REQMSG}" echo " Message is: ${ERRSTR}" echo rm -f ${TEMPJSON} return 2 else echo -e "\nRepo creation SUCCESS!" mv -f ${TEMPJSON} .git/github-info.json fi CLONEURL=$(jq -r '.clone_url' .git/github-info.json) # you can pass the trailing flag of '--push' to automatically push the repo. if [[ ${PUSH} == '--push' ]] then echo -e "\nAutomatically pushing..." git remote add origin ${CLONEURL} git push -u origin master else echo "Created REPO ${1}, to push manually:" echo echo " git remote add origin ${CLONEURL}" echo " git push -u origin master" fi HTMLURL=$(jq -r '.html_url' .git/github-info.json) echo -e "\nVisit your new repo here: ${HTMLURL}" -
goozbach revised this gist
Jan 19, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ gitcreate() { # Seed of this idea came from http://www.karan.org/blog/2017/01/13/create-a-new-github-com-repo-from-the-cli/ # `~/.gitcreate_secret` format: # # GITHUB_AUTH=<username>:<personal_access_token> -
goozbach revised this gist
Jan 19, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ gitcreate() { # GITHUB_AUTH=<username>:<personal_access_token> # # Generate a personal access token here: https://github.com/settings/tokens source ~/.gitcreate_secret || return if [[ ! -d .git ]] then echo "This needs to be ran in the top-level directory of an already existing git repo." -
goozbach created this gist
Jan 19, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ gitcreate() { # `~/.gitcreate_secret` format: # # GITHUB_AUTH=<username>:<personal_access_token> # # Generate a personal access token here: https://github.com/settings/tokens source ~/.gitcreate_secret if [[ ! -d .git ]] then echo "This needs to be ran in the top-level directory of an already existing git repo." return fi REPONAME=${1} PUSH=${2} curl -s -u ${GITHUB_AUTH} https://api.github.com/user/repos -d "{\"name\":\"${REPONAME}\"}" > .git/github-info.json CLONEURL=$(jq -r '.clone_url' .git/github-info.json) if [[ ${PUSH} == '--push' ]] then echo "Automatically pushing..." git remote add origin ${CLONEURL} git push -u origin master else # gotta keep this indentation cause HEREDOCs suck at indenting cat <<-EOF Created REPO ${1}, to push manually: git remote add origin ${CLONEURL} git push -u origin master EOF fi HTMLURL=$(jq -r '.html_url' .git/github-info.json) echo -e "\nVisit your new repo here: ${HTMLURL}" }