Skip to content

Commit

Permalink
Create pull request script
Browse files Browse the repository at this point in the history
  • Loading branch information
andys8 committed Mar 6, 2024
1 parent ab4f20c commit c6acf7f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions bin/create-pullrequest
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
set -e

# Check if the branch name is provided
if [ -z "$1" ]; then
echo "Usage: $0 <branch_name>"
exit 1
fi

# Abort if there are no git changes
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit"
exit 1
fi

# Extract ticket number and branch type from the provided branch name
BRANCH_NAME="$1"
TICKET_NUMBER=$(echo "$BRANCH_NAME" | grep -oPi 'vi-\d+' | tr '[:lower:]' '[:upper:]')

BRANCH_TYPE=$(echo "$BRANCH_NAME" | cut -d'/' -f1)
if [ "$BRANCH_TYPE" == "feature" ]; then
BRANCH_TYPE="feat"
elif [ "$BRANCH_TYPE" == "bugfix" ]; then
BRANCH_TYPE="fix"
fi

TITLE=$(echo "$BRANCH_NAME" | cut -d'-' -f3- | sed 's/-/ /g')

if [ -z "$TICKET_NUMBER" ]; then
COMMIT_MSG="$BRANCH_TYPE: $TITLE"
else
COMMIT_MSG="$BRANCH_TYPE: $TICKET_NUMBER $TITLE"
fi

git checkout -b "$BRANCH_NAME"
git add .
git commit -am "$COMMIT_MSG" || true
git push --set-upstream origin "$BRANCH_NAME"

hub pull-request

0 comments on commit c6acf7f

Please sign in to comment.