Created
April 6, 2023 18:47
-
-
Save jeffypooo/361e7349c8894b0cb41037c991687082 to your computer and use it in GitHub Desktop.
Revisions
-
jeffypooo created this gist
Apr 6, 2023 .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,40 @@ #!/bin/bash ############################################################################### # Script to create a new git branch for a JIRA ticket, using the ticket URL. # # # # Usage: gb-ticket.sh <ticket_url> <desc> # ############################################################################### # Require parameters and parse them if [ $# -ne 2 ]; then echo "Usage: gb-ticket.sh <ticket_url> <desc>" exit 1 fi url=$1 desc=$2 # Get username from git config username=$(git config --get user.name) # Parse project name and ticket number from URL regex='^.*\/([A-Z]{3})-([0-9]+)\?.*$' if [[ $url =~ $regex ]]; then project=${BASH_REMATCH[1]} ticket_number=${BASH_REMATCH[2]} else echo "Error: Invalid URL" exit 1 fi # Derive a new branch using the scheme: <username>/<project>-<ticket_number>/<desc> branch=$username/$project-$ticket_number/$desc # Checkout branch and push to remote git checkout -b $branch && git push -u origin $branch # Check for errors if [ $? -eq 0 ]; then echo "Created branch $branch" else echo "Error creating branch $branch" fi