diff --git a/.editorconfig b/.editorconfig index ff891d8..da2e984 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,6 +20,14 @@ indent_style = tab [{lib/*,README.md}] indent_size = unset +[{tests/acceptance/**.sh,src/console_header.sh}] +indent_size = unset + +[tests/**/*.snapshot] +indent_size = unset +max_line_length = unset +trim_trailing_whitespace = false + [bin/*] charset = unset end_of_line = unset diff --git a/.env.example b/.env.example index 31885ad..e5cc0f8 100644 --- a/.env.example +++ b/.env.example @@ -3,10 +3,8 @@ PR_TEMPLATE_PATH=".github/PULL_REQUEST_TEMPLATE.md" PR_TITLE_TEMPLATE="{{TICKET_KEY}}-{{TICKET_NUMBER}} {{PR_TITLE}}" PR_TICKET_LINK_PREFIX="https://github.com/Chemaclass/create-pr.sh/issues/" PR_LINK_PREFIX_TEXT="Closes: " -PR_LABEL_MAPPING="docs:documentation;\ - feat|feature:enhancement;\ - fix|bug|bugfix|hotfix:bug;\ - default:enhancement" +PR_LABEL_MAPPING="docs:documentation; fix|bug|bugfix|hotfix:bug; default:enhancement" # bashunit BASHUNIT_DEFAULT_PATH="tests" +BASHUNIT_TESTS_ENV=.env.tests diff --git a/Makefile b/Makefile index 95e30aa..d056565 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ SRC_SCRIPTS_DIR=src PRE_COMMIT_SCRIPTS_FILE=./bin/pre-commit test: $(TEST_SCRIPTS_DIR) - @lib/bashunit tests -e .env.tests + @lib/bashunit pre_commit/install: @echo "Installing pre-commit hook" diff --git a/install-dependencies.sh b/install-dependencies.sh index 322f91f..1ad3245 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -1,4 +1,4 @@ #!/bin/bash ## bashunit -curl -s https://bashunit.typeddevs.com/install.sh | bash -s lib 0.15.0 +curl -s https://bashunit.typeddevs.com/install.sh | bash -s lib beta diff --git a/src/env_configuration.sh b/src/env_configuration.sh index 29b33bf..c1d9d58 100644 --- a/src/env_configuration.sh +++ b/src/env_configuration.sh @@ -5,8 +5,8 @@ set -o allexport [[ -f ".env" ]] && source .env set set +o allexport -APP_CREATE_PR_ROOT_DIR=$(git rev-parse --show-toplevel) || error_and_exit "This directory is not a git repository" - +APP_CREATE_PR_ROOT_DIR=${APP_CREATE_PR_ROOT_DIR:-$(git rev-parse --show-toplevel)} \ + || error_and_exit "This directory is not a git repository" PR_LINK_PREFIX_TEXT=${PR_LINK_PREFIX_TEXT:-""} PR_TICKET_LINK_PREFIX=${PR_TICKET_LINK_PREFIX:-""} PR_TEMPLATE_PATH=${PR_TEMPLATE_PATH:-".github/PULL_REQUEST_TEMPLATE.md"} @@ -15,7 +15,8 @@ PR_TEMPLATE="$APP_CREATE_PR_ROOT_DIR/$PR_TEMPLATE_PATH" PR_TITLE_TEMPLATE=${PR_TITLE_TEMPLATE:-"{{TICKET_KEY}}-{{TICKET_NUMBER}} {{PR_TITLE}}"} PR_ASSIGNEE=${PR_ASSIGNEE:-${ASSIGNEE:-"@me"}} BASE_BRANCH=${BASE_BRANCH:-"main"} -BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) || error_and_exit "Failed to get the current branch name." +BRANCH_NAME=${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD 2>/dev/null)} \ + || error_and_exit "Failed to get the current branch name." export PR_TITLE_TEMPLATE export PR_TEMPLATE diff --git a/src/pr_body.sh b/src/pr_body.sh index 38b76d4..fb08be1 100644 --- a/src/pr_body.sh +++ b/src/pr_body.sh @@ -9,14 +9,11 @@ _CURRENT_DIR="$(dirname "${BASH_SOURCE[0]}")" function pr_body() { local branch_name=$1 local pr_template=$2 - local result local ticket_key ticket_key=$(pr_ticket::key "$branch_name") - local ticket_number ticket_number=$(pr_ticket::number "$branch_name") - local with_link=false if [[ -n "${PR_TICKET_LINK_PREFIX}" && -n "${ticket_number}" ]]; then with_link=true @@ -32,6 +29,8 @@ function pr_body() { fi ticket_link="${PR_LINK_PREFIX_TEXT}${ticket_link}" fi + + local result result=$(perl -pe 's//{{ $1 }}/g' "$pr_template") result=$(echo "$result" | sed "s|{{[[:space:]]*TICKET_LINK[[:space:]]*}}|$ticket_link|g") diff --git a/tests/e2e/create-pr_test.sh b/tests/e2e/create-pr_test.sh index 1f2cc20..ec2d224 100644 --- a/tests/e2e/create-pr_test.sh +++ b/tests/e2e/create-pr_test.sh @@ -1,6 +1,8 @@ #!/bin/bash function set_up() { + export BASE_BRANCH="main" + export BRANCH_NAME="feat/ticket-123-my_branch-name" export PR_TEMPLATE_PATH=".github/PULL_REQUEST_TEMPLATE.md" export PR_TICKET_LINK_PREFIX="https://github.com/Chemaclass/create-pr.sh/issues/" export PR_LINK_PREFIX_TEXT="Closes: " @@ -13,6 +15,15 @@ function set_up() { function test_success() { spy git spy gh + export DEBUG=false + + assert_match_snapshot "$($SCRIPT)" +} + +function test_debug_success() { + spy git + spy gh + export DEBUG=true assert_match_snapshot "$($SCRIPT)" } diff --git a/tests/e2e/snapshots/create_pr_test_sh.test_debug_success.snapshot b/tests/e2e/snapshots/create_pr_test_sh.test_debug_success.snapshot new file mode 100644 index 0000000..928f9d5 --- /dev/null +++ b/tests/e2e/snapshots/create_pr_test_sh.test_debug_success.snapshot @@ -0,0 +1,4 @@ +[DUMP] ./create-pr.sh:57: PR_LABEL: enhancement +[DUMP] ./create-pr.sh:58: PR_TITLE: TICKET-123 My branch name +[DUMP] ./create-pr.sh:59: PR_BODY: +Pull request created successfully.