From c6acf7f9450a718fd9df6e200c6fc936df1199ec Mon Sep 17 00:00:00 2001 From: andys8 Date: Wed, 6 Mar 2024 21:02:19 +0100 Subject: [PATCH] Create pull request script --- bin/create-pullrequest | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 bin/create-pullrequest diff --git a/bin/create-pullrequest b/bin/create-pullrequest new file mode 100755 index 0000000..397a78e --- /dev/null +++ b/bin/create-pullrequest @@ -0,0 +1,40 @@ +#!/bin/bash +set -e + +# Check if the branch name is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + 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