Skip to content

Commit

Permalink
test: prepare debug_success
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Sep 15, 2024
1 parent ad3549c commit 2bab96a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions src/env_configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/pr_body.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +29,8 @@ function pr_body() {
fi
ticket_link="${PR_LINK_PREFIX_TEXT}${ticket_link}"
fi

local result
result=$(perl -pe 's/<!--\s*{{\s*(.*?)\s*}}\s*-->/{{ $1 }}/g' "$pr_template")
result=$(echo "$result" | sed "s|{{[[:space:]]*TICKET_LINK[[:space:]]*}}|$ticket_link|g")

Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/create-pr_test.sh
Original file line number Diff line number Diff line change
@@ -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: "
Expand All @@ -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)"
}
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 2bab96a

Please sign in to comment.