3c5367d272011e7bca9fa4e8f9a5f9635f938d11

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

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

Diff

This diff is truncated to protect this page.

  1diff --git a/tools/changelog.sh b/tools/changelog.sh
  2index 49532a4a451c7d7af4b10cf39487e4c1d55ad578..6489a3cb215d6641da45f09417df24eb63232294 100755
  3--- a/tools/changelog.sh
  4+++ b/tools/changelog.sh
  5@@ -23,8 +23,7 @@ TYPES=(
  6   test      "Testing"
  7 )
  8 
  9-#* Types that will be displayed in their own section,
 10-#* in the order specified here.
 11+#* Types that will be displayed in their own section, in the order specified here.
 12 local -a MAIN_TYPES
 13 MAIN_TYPES=(feat fix perf docs)
 14 
 15@@ -34,7 +33,8 @@ OTHER_TYPES=(refactor style other)
 16 
 17 #* Commit types that don't appear in $MAIN_TYPES nor $OTHER_TYPES
 18 #* will not be displayed and will simply be ignored.
 19-
 20+local -a IGNORED_TYPES
 21+IGNORED_TYPES=(${${${(@k)TYPES}:|MAIN_TYPES}:|OTHER_TYPES})
 22 
 23 ############################
 24 # COMMIT PARSING UTILITIES #
 25@@ -139,7 +139,7 @@ function parse-commit {
 26   #  [BREAKING CHANGE: warning]
 27 
 28   # commits holds the commit type
 29-  commits[$hash]="$(commit:type "$subject")"
 30+  types[$hash]="$(commit:type "$subject")"
 31   # scopes holds the commit scope
 32   scopes[$hash]="$(commit:scope "$subject")"
 33   # subjects holds the commit subject
 34@@ -164,26 +164,32 @@ function parse-commit {
 35 function display-release {
 36 
 37   # This function uses the following globals: output, version,
 38-  # commits (A), subjects (A), scopes (A), breaking (A) and reverts (A).
 39+  # types (A), subjects (A), scopes (A), breaking (A) and reverts (A).
 40   #
 41   # - output is the output format to use when formatting (raw|text|md)
 42   # - version is the version in which the commits are made
 43-  # - commits, subjects, scopes, breaking, and reverts are associative arrays
 44+  # - types, subjects, scopes, breaking, and reverts are associative arrays
 45   #   with commit hashes as keys
 46 
 47   # Remove commits that were reverted
 48   local hash rhash
 49   for hash rhash in ${(kv)reverts}; do
 50-    if (( ${+commits[$rhash]} )); then
 51+    if (( ${+types[$rhash]} )); then
 52       # Remove revert commit
 53-      unset "commits[$hash]" "subjects[$hash]" "scopes[$hash]" "breaking[$hash]"
 54+      unset "types[$hash]" "subjects[$hash]" "scopes[$hash]" "breaking[$hash]"
 55       # Remove reverted commit
 56-      unset "commits[$rhash]" "subjects[$rhash]" "scopes[$rhash]" "breaking[$rhash]"
 57+      unset "types[$rhash]" "subjects[$rhash]" "scopes[$rhash]" "breaking[$rhash]"
 58     fi
 59   done
 60 
 61+  # Remove commits from ignored types unless it has breaking change information
 62+  for hash in ${(k)types[(R)${(j:|:)IGNORED_TYPES}]}; do
 63+    (( ! ${+breaking[$hash]} )) || continue
 64+    unset "types[$hash]" "subjects[$hash]" "scopes[$hash]"
 65+  done
 66+
 67   # If no commits left skip displaying the release
 68-  if (( $#commits == 0 )); then
 69+  if (( $#types == 0 )); then
 70     return
 71   fi
 72 
 73@@ -313,7 +319,7 @@ function display-release {
 74     local hash type="$1"
 75 
 76     local -a hashes
 77-    hashes=(${(k)commits[(R)$type]})
 78+    hashes=(${(k)types[(R)$type]})
 79 
 80     # If no commits found of type $type, go to next type
 81     (( $#hashes != 0 )) || return 0
 82@@ -330,7 +336,7 @@ function display-release {
 83 
 84     # Commits made under types considered other changes
 85     local -A changes
 86-    changes=(${(kv)commits[(R)${(j:|:)OTHER_TYPES}]})
 87+    changes=(${(kv)types[(R)${(j:|:)OTHER_TYPES}]})
 88 
 89     # If no commits found under "other" types, don't display anything
 90     (( $#changes != 0 )) || return 0
 91@@ -388,7 +394,7 @@ function main {
 92   fi
 93 
 94   # Commit classification arrays
 95-  local -A commits subjects scopes breaking reverts
 96+  local -A types subjects scopes breaking reverts
 97   local truncate=0 read_commits=0
 98   local version tag
 99   local hash refs subject body
100@@ -441,7 +447,7 @@ function main {
101       # Output previous release
102       display-release
103       # Reinitialize commit storage
104-      commits=()