@@ -21,7 +21,7 @@ function console_header::print_version() {
2121}
2222
2323function console_header::print_help() {
24- cat << EOF
24+ cat << EOF
2525create-pr [arguments] [options]
2626
2727Arguments:
@@ -59,8 +59,8 @@ set -o allexport
5959[[ -f " .env" ]] && source .env set
6060set +o allexport
6161
62- APP_CREATE_PR_ROOT_DIR=${APP_CREATE_PR_ROOT_DIR:- " $( git rev-parse --show-toplevel) " } \
63- || error_and_exit " This directory is not a git repository"
62+ APP_CREATE_PR_ROOT_DIR=${APP_CREATE_PR_ROOT_DIR:- " $( git rev-parse --show-toplevel) " } ||
63+ error_and_exit " This directory is not a git repository"
6464PR_LINK_PREFIX_TEXT=${PR_LINK_PREFIX_TEXT:- " " }
6565PR_TICKET_LINK_PREFIX=${PR_TICKET_LINK_PREFIX:- " " }
6666PR_TEMPLATE_PATH=${PR_TEMPLATE_PATH:- " .github/PULL_REQUEST_TEMPLATE.md" }
@@ -71,8 +71,8 @@ PR_ASSIGNEE=${PR_ASSIGNEE:-${ASSIGNEE:-"@me"}}
7171PR_REVIEWER=${PR_REVIEWER:- ${REVIEWER:- " " } }
7272PR_RUN_AFTER_CREATION=${PR_RUN_AFTER_CREATION:- " " }
7373TARGET_BRANCH=${TARGET_BRANCH:- " main" }
74- CURRENT_BRANCH=${CURRENT_BRANCH:- " $( git rev-parse --abbrev-ref HEAD 2> /dev/null) " } \
75- || error_and_exit " Failed to get the current branch name."
74+ CURRENT_BRANCH=${CURRENT_BRANCH:- " $( git rev-parse --abbrev-ref HEAD 2> /dev/null) " } ||
75+ error_and_exit " Failed to get the current branch name."
7676
7777REMOTE_URL=${REMOTE_URL:- " $( git config --get remote.origin.url) " }
7878if [[ " $REMOTE_URL " == * " github.com" * ]]; then
@@ -121,8 +121,8 @@ function main::create_pr() {
121121
122122 # Push the current branch
123123 if ! git push -u origin " $CURRENT_BRANCH " ; then
124- error_and_exit " Failed to push the current branch to the remote repository." \
125- " Please check your git remote settings."
124+ error_and_exit " Failed to push the current branch to the remote repository." \
125+ " Please check your git remote settings."
126126 fi
127127
128128 if [[ " $PR_USING_CLIENT " == " gitlab" ]]; then
@@ -137,13 +137,13 @@ function main::create_pr_gitlab() {
137137
138138 local glab_command=(
139139 glab mr create
140- --title " $PR_TITLE "
141- --target-branch " $TARGET_BRANCH "
142- --source-branch " $CURRENT_BRANCH "
143- --assignee " $PR_ASSIGNEE "
144- --reviewer " $PR_REVIEWER "
145- --label " $PR_LABEL "
146- --description " $PR_BODY "
140+ --title " $PR_TITLE "
141+ --target-branch " $TARGET_BRANCH "
142+ --source-branch " $CURRENT_BRANCH "
143+ --assignee " $PR_ASSIGNEE "
144+ --reviewer " $PR_REVIEWER "
145+ --label " $PR_LABEL "
146+ --description " $PR_BODY "
147147 )
148148
149149 if [[ ${# EXTRA_ARGS[@]} -gt 0 ]]; then
@@ -163,22 +163,22 @@ function main::create_pr_github() {
163163
164164 local gh_command=(
165165 gh pr create
166- --title " $PR_TITLE "
167- --base " $TARGET_BRANCH "
168- --head " $CURRENT_BRANCH "
169- --assignee " $PR_ASSIGNEE "
170- --reviewer " $PR_REVIEWER "
171- --label " $PR_LABEL "
172- --body " $PR_BODY "
166+ --title " $PR_TITLE "
167+ --base " $TARGET_BRANCH "
168+ --head " $CURRENT_BRANCH "
169+ --assignee " $PR_ASSIGNEE "
170+ --reviewer " $PR_REVIEWER "
171+ --label " $PR_LABEL "
172+ --body " $PR_BODY "
173173 )
174174
175175 if [[ ${# EXTRA_ARGS[@]} -gt 0 ]]; then
176176 gh_command+=(" ${EXTRA_ARGS[@]} " )
177177 fi
178178
179179 if ! " ${gh_command[@]} " ; then
180- error_and_exit " Failed to create the Pull Request." \
181- " Ensure you have the correct permissions and the repository is properly configured."
180+ error_and_exit " Failed to create the Pull Request." \
181+ " Ensure you have the correct permissions and the repository is properly configured."
182182 fi
183183
184184 main::run_after_creation_script
@@ -287,7 +287,7 @@ function pr_label() {
287287 IFS=' ;' # Split mapping entries by semicolon
288288 for entry in $mapping ; do
289289 # Split each entry into keys and value
290- IFS=' :' read -r keys value <<< " $entry"
290+ IFS=' :' read -r keys value <<< " $entry"
291291
292292 # Check if the prefix matches any of the keys
293293 IFS=' |' # Split keys by pipe symbol
@@ -388,7 +388,7 @@ function pr_title() {
388388 fi
389389
390390 local title
391- title=$( echo " $branch_name " | cut -d' -' -f3- | tr ' -' ' ' | tr ' _' ' ' )
391+ title=$( echo " $branch_name " | cut -d' -' -f3- | tr ' -' ' ' | tr ' _' ' ' )
392392 title=" $( echo " ${title: 0: 1} " | tr ' [:lower:]' ' [:upper:]' ) ${title: 1} "
393393
394394 # Normalize the template by removing spaces around placeholders
@@ -404,17 +404,17 @@ function pr_title() {
404404
405405 if [[ -n " $PR_TITLE_REMOVE_PREFIX " ]]; then
406406 # Split PR_TITLE_REMOVE_PREFIX into an array
407- IFS=' ,' read -ra prefixes <<< " $PR_TITLE_REMOVE_PREFIX"
407+ IFS=' ,' read -ra prefixes <<< " $PR_TITLE_REMOVE_PREFIX"
408408 # Loop through each prefix and remove it from the start if it matches
409409 for prefix in " ${prefixes[@]} " ; do
410410 # shellcheck disable=SC2001
411411 new_title=" $( echo " $new_title " | sed -e " s/^${prefix} //I" ) "
412412 done
413413
414414 # Trim leading whitespace and capitalize the first letter
415- new_title=$( echo " $new_title " \
416- | sed ' s/^ *//' \
417- | awk ' { print toupper(substr($0,1,1)) tolower(substr($0,2)) }' )
415+ new_title=$( echo " $new_title " |
416+ sed ' s/^ *//' |
417+ awk ' { print toupper(substr($0,1,1)) tolower(substr($0,2)) }' )
418418 fi
419419
420420 formatted=" ${formatted// \{\{ PR_TITLE\}\} / $new_title } "
@@ -450,8 +450,8 @@ GH_CLI_INSTALLATION_URL="https://cli.github.com/"
450450GLAB_CLI_INSTALLATION_URL=" https://gitlab.com/gitlab-org/cli/"
451451
452452function error_and_exit() {
453- echo " Error: $1 " >&2
454- exit 1
453+ echo " Error: $1 " >&2
454+ exit 1
455455}
456456
457457function validate::target_branch_exists() {
@@ -473,13 +473,13 @@ function validate::current_branch_is_not_target() {
473473}
474474
475475function validate::gh_cli_is_installed() {
476- if ! command -v gh & > /dev/null; then
476+ if ! command -v gh & > /dev/null; then
477477 error_and_exit " gh CLI is not installed. Please install it from $GH_CLI_INSTALLATION_URL and try again."
478478 fi
479479}
480480
481481function validate::glab_cli_is_installed() {
482- if ! command -v glab & > /dev/null; then
482+ if ! command -v glab & > /dev/null; then
483483 error_and_exit " glab CLI is not installed. Please install it from $GLAB_CLI_INSTALLATION_URL and try again."
484484 fi
485485}
@@ -493,38 +493,38 @@ declare -r CREATE_PR_VERSION="0.10.0"
493493CREATE_PR_ROOT_DIR=" $( dirname " ${BASH_SOURCE[0]} " ) "
494494export CREATE_PR_ROOT_DIR
495495
496-
497496DRY_RUN=${DRY_RUN:- false}
498497EXTRA_ARGS=()
499498
500499while [[ $# -gt 0 ]]; do
501500 argument=" $1 "
502501 case $argument in
503- --debug)
504- set -x
505- ;;
506- --dry-run)
507- DRY_RUN=true
508- ;;
509- -e|--env)
510- # shellcheck disable=SC1090
511- source " $2 "
512- shift
513- ;;
514- -t|--title)
515- helpers::generate_branch_name " $2 " " ${3:- } "
516- trap ' ' EXIT && exit 0
517- ;;
518- -h|--help)
519- console_header::print_help
520- trap ' ' EXIT && exit 0
521- ;;
522- -v|--version)
523- console_header::print_version
524- trap ' ' EXIT && exit 0
525- ;;
526- * )
527- EXTRA_ARGS+=(" $argument " )
502+ --debug)
503+ set -x
504+ ;;
505+ --dry-run)
506+ DRY_RUN=true
507+ ;;
508+ -e | --env)
509+ # shellcheck disable=SC1090
510+ source " $2 "
511+ shift
512+ ;;
513+ -t | --title)
514+ helpers::generate_branch_name " $2 " " ${3:- } "
515+ trap ' ' EXIT && exit 0
516+ ;;
517+ -h | --help)
518+ console_header::print_help
519+ trap ' ' EXIT && exit 0
520+ ;;
521+ -v | --version)
522+ console_header::print_version
523+ trap ' ' EXIT && exit 0
524+ ;;
525+ * )
526+ EXTRA_ARGS+=(" $argument " )
527+ ;;
528528 esac
529529 shift
530530done
0 commit comments