cameronstark
1/25/2018 - 1:10 AM

Make a new Bitbucket Repo From the Command Line

Make a new Bitbucket Repo From the Command Line

read -e -p "Project:" PNAME
read -e -p "Description:" DESCRIPTION
read -e -p "Username:" USER
read -e -p "Password:" PASS

COMPANY_LWR='<CMPNYNAME>'
DASH=${PNAME// /-}
LWR_DASH=(`echo "$DASH" | awk '{print tolower($0)}'`)
PROJECT_KEY='<PRJKEY>'

#Create Bitbucket Repo
curl -X POST -v -u $USER:$PASS https://api.bitbucket.org/2.0/repositories/$COMPANY_LWR/$LWR_DASH -H "Content-Type: application/json" -d "{\"name\": \"$PNAME\",\"project\": {\"key\": \"$PROJECT_KEY\"},\"is_private\": true, \"description\": \"$DESCRIPTION\"}"\

#$? for last execution
if [ 0 -eq $? ];
then

  #Create README
  echo "# $PNAME #\n\n### DESCRIPTION ###\n\n$DESCRIPTION\n\n### AUTHOR ###\n\n$USER" >> README.md

  #Push Git
  git init;
  git add --all;
  git commit -m "init";
  git remote add origin https://$USER@bitbucket.org/$COMPANY_LWR/$LWR_DASH.git
  git push -u origin master

  echo "New Repo Pushed Up"

else

  echo "Curl was unsuccessful"

fi;