Skip to content

Commit

Permalink
Merge pull request #47 from Chemaclass/feat/add-debug-option
Browse files Browse the repository at this point in the history
Add debug option
  • Loading branch information
Chemaclass authored Sep 15, 2024
2 parents 9e9ec88 + 3d1408d commit e3a82d4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Fix additional single quotes on PR_TITLE_TEMPLATE
- Improve feedback when given wrong PR template
- Add GitLab support
- Add `--debug` option (alias: `--dry-run`)
- Display the data used before creating the PR

## 0.5 - 2024-09-09

Expand Down
25 changes: 14 additions & 11 deletions create-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare -r CREATE_PR_VERSION="0.5.0"
CREATE_PR_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"
export CREATE_PR_ROOT_DIR

source "$CREATE_PR_ROOT_DIR/src/dev/debug.sh"
source "$CREATE_PR_ROOT_DIR/src/debug.sh"
source "$CREATE_PR_ROOT_DIR/src/helpers.sh"
source "$CREATE_PR_ROOT_DIR/src/validation.sh"
source "$CREATE_PR_ROOT_DIR/src/pr_ticket.sh"
Expand All @@ -18,11 +18,13 @@ source "$CREATE_PR_ROOT_DIR/src/env_configuration.sh"
source "$CREATE_PR_ROOT_DIR/src/console_header.sh"
source "$CREATE_PR_ROOT_DIR/src/main.sh"

DEBUG=${DEBUG:-false}

while [[ $# -gt 0 ]]; do
argument="$1"
case $argument in
--debug)
set -x
--debug|--dry-run)
DEBUG=true
;;
-e|--env)
# shellcheck disable=SC1090
Expand All @@ -49,20 +51,21 @@ PR_LABEL=${PR_LABEL:-${LABEL:-$(pr_label "$BRANCH_NAME" "${PR_LABEL_MAPPING:-}")
PR_TITLE=$(pr_title "$BRANCH_NAME")
PR_BODY=$(pr_body "$BRANCH_NAME" "$PR_TEMPLATE")

export PR_LABEL
export PR_TITLE
export PR_BODY

if [[ -n "${DEBUG:-}" && "$DEBUG" == true ]]; then
if [[ "$DEBUG" == true ]]; then
dump "REMOTE_URL: $REMOTE_URL"
dump "PR_USING_CLIENT: $PR_USING_CLIENT"
dump "BRANCH_NAME: $BRANCH_NAME"
dump "PR_USING_CLIENT: $PR_USING_CLIENT"
dump "PR_TEMPLATE: $PR_TEMPLATE"
dump "PR_LABEL: $PR_LABEL"
dump "PR_TITLE: $PR_TITLE"
dump "PR_BODY: $PR_BODY"
else
main::create_pr
exit 0
fi

export PR_LABEL
export PR_TITLE
export PR_BODY

main::create_pr

echo "Script finished successfully."
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 beta
curl -s https://bashunit.typeddevs.com/install.sh | bash -s lib 0.16.0
File renamed without changes.
12 changes: 3 additions & 9 deletions tests/e2e/create-pr_test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

function set_up() {
export REMOTE_URL="[email protected]:Chemaclass/create-pr.sh.git"
export APP_CREATE_PR_ROOT_DIR=.
export REMOTE_URL="[email protected]:Chemaclass/create-pr.sh.git"
export BASE_BRANCH="main"
export BRANCH_NAME="feat/ticket-123-my_branch-name"
export PR_TEMPLATE_PATH=".github/PULL_REQUEST_TEMPLATE.md"
Expand All @@ -14,22 +14,16 @@ function set_up() {
SCRIPT="$CREATE_PR_ROOT_DIR/create-pr.sh"
}

function tear_down_after_script() {
export DEBUG=false
}

function test_success() {
spy git
spy gh
export DEBUG=false

assert_match_snapshot "$($SCRIPT)"
}

function test_debug_success() {
function test_script_with_debug() {
spy git
spy gh
export DEBUG=true

assert_match_snapshot "$($SCRIPT)"
assert_match_snapshot "$($SCRIPT --debug)"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[DUMP] ./create-pr.sh:57: REMOTE_URL: [email protected]:Chemaclass/create-pr.sh.git
[DUMP] ./create-pr.sh:58: PR_USING_CLIENT: github
[DUMP] ./create-pr.sh:59: BRANCH_NAME: feat/ticket-123-my_branch-name
[DUMP] ./create-pr.sh:60: PR_TEMPLATE: ./.github/PULL_REQUEST_TEMPLATE.md
[DUMP] ./create-pr.sh:61: PR_LABEL: enhancement
[DUMP] ./create-pr.sh:62: PR_TITLE: TICKET-123 My branch name
[DUMP] ./create-pr.sh:63: PR_BODY: ### 🔗 Ticket
[DUMP] ./create-pr.sh:55: REMOTE_URL: [email protected]:Chemaclass/create-pr.sh.git
[DUMP] ./create-pr.sh:56: BRANCH_NAME: feat/ticket-123-my_branch-name
[DUMP] ./create-pr.sh:57: PR_USING_CLIENT: github
[DUMP] ./create-pr.sh:58: PR_TEMPLATE: ./.github/PULL_REQUEST_TEMPLATE.md
[DUMP] ./create-pr.sh:59: PR_LABEL: enhancement
[DUMP] ./create-pr.sh:60: PR_TITLE: TICKET-123 My branch name
[DUMP] ./create-pr.sh:61: PR_BODY: ### 🔗 Ticket

Closes: https://github.com/Chemaclass/create-pr.sh/issues/TICKET-123

Expand All @@ -27,4 +27,3 @@ Details in the ticket.
#### BEFORE

#### AFTER
Script finished successfully.

0 comments on commit e3a82d4

Please sign in to comment.