Skip to content

Commit

Permalink
fix(presets): case of scope on invalid/semi-valid commits
Browse files Browse the repository at this point in the history
  • Loading branch information
dalisoft committed Apr 25, 2024
1 parent b15cbd8 commit 790d179
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
31 changes: 17 additions & 14 deletions presets/conventional-commits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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
Expand All @@ -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+="- "
Expand Down
29 changes: 16 additions & 13 deletions presets/workspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -43,20 +41,30 @@ 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
if [ "${scope-}" != "$PKG_NAME" ]; then
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
Expand All @@ -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
Expand Down

0 comments on commit 790d179

Please sign in to comment.