fix(changelog): don't show changelog with only ignored type commits

This commit is contained in:
Marc Cornellà 2022-01-28 13:22:31 +01:00
parent b5edb51ee4
commit 3c5367d272
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -23,8 +23,7 @@ TYPES=(
test "Testing" test "Testing"
) )
#* Types that will be displayed in their own section, #* Types that will be displayed in their own section, in the order specified here.
#* in the order specified here.
local -a MAIN_TYPES local -a MAIN_TYPES
MAIN_TYPES=(feat fix perf docs) MAIN_TYPES=(feat fix perf docs)
@ -34,7 +33,8 @@ OTHER_TYPES=(refactor style other)
#* Commit types that don't appear in $MAIN_TYPES nor $OTHER_TYPES #* Commit types that don't appear in $MAIN_TYPES nor $OTHER_TYPES
#* will not be displayed and will simply be ignored. #* will not be displayed and will simply be ignored.
local -a IGNORED_TYPES
IGNORED_TYPES=(${${${(@k)TYPES}:|MAIN_TYPES}:|OTHER_TYPES})
############################ ############################
# COMMIT PARSING UTILITIES # # COMMIT PARSING UTILITIES #
@ -139,7 +139,7 @@ function parse-commit {
# [BREAKING CHANGE: warning] # [BREAKING CHANGE: warning]
# commits holds the commit type # commits holds the commit type
commits[$hash]="$(commit:type "$subject")" types[$hash]="$(commit:type "$subject")"
# scopes holds the commit scope # scopes holds the commit scope
scopes[$hash]="$(commit:scope "$subject")" scopes[$hash]="$(commit:scope "$subject")"
# subjects holds the commit subject # subjects holds the commit subject
@ -164,26 +164,32 @@ function parse-commit {
function display-release { function display-release {
# This function uses the following globals: output, version, # This function uses the following globals: output, version,
# commits (A), subjects (A), scopes (A), breaking (A) and reverts (A). # types (A), subjects (A), scopes (A), breaking (A) and reverts (A).
# #
# - output is the output format to use when formatting (raw|text|md) # - output is the output format to use when formatting (raw|text|md)
# - version is the version in which the commits are made # - version is the version in which the commits are made
# - commits, subjects, scopes, breaking, and reverts are associative arrays # - types, subjects, scopes, breaking, and reverts are associative arrays
# with commit hashes as keys # with commit hashes as keys
# Remove commits that were reverted # Remove commits that were reverted
local hash rhash local hash rhash
for hash rhash in ${(kv)reverts}; do for hash rhash in ${(kv)reverts}; do
if (( ${+commits[$rhash]} )); then if (( ${+types[$rhash]} )); then
# Remove revert commit # Remove revert commit
unset "commits[$hash]" "subjects[$hash]" "scopes[$hash]" "breaking[$hash]" unset "types[$hash]" "subjects[$hash]" "scopes[$hash]" "breaking[$hash]"
# Remove reverted commit # Remove reverted commit
unset "commits[$rhash]" "subjects[$rhash]" "scopes[$rhash]" "breaking[$rhash]" unset "types[$rhash]" "subjects[$rhash]" "scopes[$rhash]" "breaking[$rhash]"
fi fi
done done
# Remove commits from ignored types unless it has breaking change information
for hash in ${(k)types[(R)${(j:|:)IGNORED_TYPES}]}; do
(( ! ${+breaking[$hash]} )) || continue
unset "types[$hash]" "subjects[$hash]" "scopes[$hash]"
done
# If no commits left skip displaying the release # If no commits left skip displaying the release
if (( $#commits == 0 )); then if (( $#types == 0 )); then
return return
fi fi
@ -313,7 +319,7 @@ function display-release {
local hash type="$1" local hash type="$1"
local -a hashes local -a hashes
hashes=(${(k)commits[(R)$type]}) hashes=(${(k)types[(R)$type]})
# If no commits found of type $type, go to next type # If no commits found of type $type, go to next type
(( $#hashes != 0 )) || return 0 (( $#hashes != 0 )) || return 0
@ -330,7 +336,7 @@ function display-release {
# Commits made under types considered other changes # Commits made under types considered other changes
local -A changes local -A changes
changes=(${(kv)commits[(R)${(j:|:)OTHER_TYPES}]}) changes=(${(kv)types[(R)${(j:|:)OTHER_TYPES}]})
# If no commits found under "other" types, don't display anything # If no commits found under "other" types, don't display anything
(( $#changes != 0 )) || return 0 (( $#changes != 0 )) || return 0
@ -388,7 +394,7 @@ function main {
fi fi
# Commit classification arrays # Commit classification arrays
local -A commits subjects scopes breaking reverts local -A types subjects scopes breaking reverts
local truncate=0 read_commits=0 local truncate=0 read_commits=0
local version tag local version tag
local hash refs subject body local hash refs subject body
@ -441,7 +447,7 @@ function main {
# Output previous release # Output previous release
display-release display-release
# Reinitialize commit storage # Reinitialize commit storage
commits=() types=()
subjects=() subjects=()
scopes=() scopes=()
breaking=() breaking=()