From 790d179b93dbf824d3f4bfcbc88d5b377d43549e Mon Sep 17 00:00:00 2001 From: Davlatjon Shavkatov Date: Thu, 25 Apr 2024 19:41:01 +0500 Subject: [PATCH] fix(presets): case of scope on invalid/semi-valid commits --- presets/conventional-commits.sh | 31 +++++++++++++++++-------------- presets/workspace.sh | 29 ++++++++++++++++------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/presets/conventional-commits.sh b/presets/conventional-commits.sh index 4dcd549..f28a77b 100755 --- a/presets/conventional-commits.sh +++ b/presets/conventional-commits.sh @@ -4,7 +4,7 @@ set -eu # RegExp as variable regexp_commit_primary="^([a-z]+)(\(([^\)]+)\))?:\ (.+)$" regexp_commit_major="^([a-z]+)(\(([^\)]+)\))?!?:\ (.+)$" -string_commit_major="^BREAKING CHANGE" +string_commit_major="^BREAKING CHANGE(: )?(.+)" # Release types # shellcheck disable=2034 @@ -13,8 +13,6 @@ RELEASE_SKIP_TYPES=("build" "chore" "docs" "test" "style" "ci" "skip ci") RELEASE_PATCH_TYPES=("fix" "close" "closes" "perf" "revert") # shellcheck disable=2034 RELEASE_MINOR_TYPES=("refactor" "feat") -# shellcheck disable=2034 -RELEASE_MAJOR_TYPES=("BREAKING CHANGE") INCLUDE_SCOPE=("refactor" "perf" "revert") @@ -43,15 +41,25 @@ parse_commit() { description="${BASH_REMATCH[4]}" type="BREAKING CHANGE" - elif [[ "$body" =~ $string_commit_major ]]; then - type="BREAKING CHANGE" - description="$subject" - else - return 0 + if ! $MAJOR_UPGRADED; then + MAJOR_UPGRADED=true + RELEASE_BODY+="\n## BREAKING CHANGES\n\n" + fi fi - if is_valid_commit_type "$type" "${RELEASE_SKIP_TYPES[@]}"; then + # Extract body + if [[ "$body" =~ $string_commit_major ]]; then + description="$subject" + + type="BREAKING CHANGE" + + if ! $MAJOR_UPGRADED; then + MAJOR_UPGRADED=true + RELEASE_BODY+="\n## BREAKING CHANGES\n\n" + fi + # Handle other type of commits + elif is_valid_commit_type "$type" "${RELEASE_SKIP_TYPES[@]}"; then return 0 elif is_valid_commit_type "$type" "${RELEASE_PATCH_TYPES[@]}"; then if ! $PATCH_UPGRADED; then @@ -63,11 +71,6 @@ parse_commit() { MINOR_UPGRADED=true RELEASE_BODY+="\n## Features\n\n" fi - elif is_valid_commit_type "$type" "${RELEASE_MAJOR_TYPES[@]}"; then - if ! $MAJOR_UPGRADED; then - MAJOR_UPGRADED=true - RELEASE_BODY+="\n## BREAKING CHANGES\n\n" - fi fi RELEASE_BODY+="- " diff --git a/presets/workspace.sh b/presets/workspace.sh index d6069b5..6327ea1 100644 --- a/presets/workspace.sh +++ b/presets/workspace.sh @@ -13,8 +13,6 @@ RELEASE_SKIP_TYPES=("build" "chore" "docs" "test" "style" "ci" "skip ci") RELEASE_PATCH_TYPES=("fix" "close" "closes" "perf" "revert") # shellcheck disable=2034 RELEASE_MINOR_TYPES=("refactor" "feat") -# shellcheck disable=2034 -RELEASE_MAJOR_TYPES=("BREAKING CHANGE") INCLUDE_SCOPE=("refactor" "perf" "revert") @@ -43,12 +41,11 @@ parse_commit() { description="${BASH_REMATCH[4]}" type="BREAKING CHANGE" - elif [[ "$body" =~ $string_commit_major ]]; then - type="BREAKING CHANGE" - description="$subject" - else - return 0 + if ! $MAJOR_UPGRADED; then + MAJOR_UPGRADED=true + RELEASE_BODY+="\n## BREAKING CHANGES\n\n" + fi fi # Early catching non-workspace commits @@ -56,7 +53,18 @@ parse_commit() { return 0 fi - if is_valid_commit_type "$type" "${RELEASE_SKIP_TYPES[@]}"; then + # Extract body + if [[ "$body" =~ $string_commit_major ]]; then + type="BREAKING CHANGE" + + description="$subject" + + if ! $MAJOR_UPGRADED; then + MAJOR_UPGRADED=true + RELEASE_BODY+="\n## BREAKING CHANGES\n\n" + fi + # Handle other type of commits + elif is_valid_commit_type "$type" "${RELEASE_SKIP_TYPES[@]}"; then return 0 elif is_valid_commit_type "$type" "${RELEASE_PATCH_TYPES[@]}"; then if ! $PATCH_UPGRADED; then @@ -68,11 +76,6 @@ parse_commit() { MINOR_UPGRADED=true RELEASE_BODY+="\n## Features\n\n" fi - elif is_valid_commit_type "$type" "${RELEASE_MAJOR_TYPES[@]}"; then - if ! $MAJOR_UPGRADED; then - MAJOR_UPGRADED=true - RELEASE_BODY+="\n## BREAKING CHANGES\n\n" - fi fi if is_valid_commit_type "$type" "${INCLUDE_SCOPE[@]}"; then