From aaa9c3092cb27512aa505b90340550ced81f94c6 Mon Sep 17 00:00:00 2001 From: Jakub Werner Date: Tue, 20 Sep 2022 09:04:11 +0200 Subject: [PATCH] Adding --all-match to include/exclude filters & some tests Signed-off-by: Jakub Werner --- README.md | 4 ++-- assets/check | 8 ++++---- test/check.sh | 15 +++++++++++++++ test/helpers.sh | 5 ++++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 07b36ab..229e252 100644 --- a/README.md +++ b/README.md @@ -115,11 +115,11 @@ Tracks the commits in a [git](http://git-scm.com/) repository. * `commit_filter`: *Optional.* Object containing commit message filters * `exclude`: *Optional.* Array containing strings that should cause a commit to be skipped - * `exclude_match_all`: *Optional.* Boolean wheater it should match all the exclude filters "AND", default: false + * `exclude_all_match`: *Optional.* Boolean wheater it should match all the exclude filters "AND", default: false * `include`: *Optional.* Array containing strings that *MUST* be included in commit messages for the commit to not be skipped - * `include_match_all`: *Optional.* Boolean wheater it should match all the include filters "AND", default: false + * `include_all_match`: *Optional.* Boolean wheater it should match all the include filters "AND", default: false **Note**: *You must escape any regex sensitive characters, since the string is used as a regex filter.* For example, using `[skip deploy]` or `[deploy skip]` to skip non-deployment related commits in a deployment pipeline: diff --git a/assets/check b/assets/check index 5e6e8ea..f37cd2d 100755 --- a/assets/check +++ b/assets/check @@ -28,9 +28,9 @@ git_config_payload=$(jq -r '.source.git_config // []' <<< "$payload") ref=$(jq -r '.version.ref // ""' <<< "$payload") skip_ci_disabled=$(jq -r '.source.disable_ci_skip // false' <<< "$payload") filter_whitelist=$(jq -r '.source.commit_filter.include // []' <<< "$payload") -filter_whitelist_match_all=$(jq -r '.source.commit_filter.include_match_all // false' <<< "$payload") +filter_whitelist_match_all=$(jq -r '.source.commit_filter.include_all_match // false' <<< "$payload") filter_blacklist=$(jq -r '.source.commit_filter.exclude // []' <<< "$payload") -filter_blacklist_match_all=$(jq -r '.source.commit_filter.exclude_match_all // false' <<< "$payload") +filter_blacklist_match_all=$(jq -r '.source.commit_filter.exclude_all_match // false' <<< "$payload") version_depth=$(jq -r '.source.version_depth // 1' <<< "$payload") reverse=false @@ -87,7 +87,7 @@ if [ `echo $filter_whitelist | jq -r '. | length'` -gt 0 ] then list_command+=" | git rev-list --stdin --date-order --first-parent --no-walk=unsorted " if [ "$filter_whitelist_match_all" = "true" ]; then - list_command+="--match-all" + list_command+="--all-match" fi whitelist_items=$(echo $filter_whitelist | jq -r -c '.[]') for wli in "$whitelist_items" @@ -100,7 +100,7 @@ if [ `echo $filter_blacklist | jq -r '. | length'` -gt 0 ] then list_command+=" | git rev-list --stdin --date-order --invert-grep --first-parent --no-walk=unsorted " if [ "$filter_blacklist_match_all" = "true" ]; then - list_command+="--match-all" + list_command+="--all-match" fi blacklist_items=$(echo $filter_blacklist | jq -r -c '.[]') for bli in "$blacklist_items" diff --git a/test/check.sh b/test/check.sh index 00e520f..a9b19bd 100755 --- a/test/check.sh +++ b/test/check.sh @@ -513,6 +513,21 @@ it_skips_non_included_commits() { " } +it_skips_all_non_included_commits() { + local repo=$(init_repo) + local ref1=$(make_commit $repo) + local ref2=$(make_commit_to_future $repo "not skipped commit") + local ref3=$(make_commit $repo "not skipped commit 2") + local ref4=$(make_commit $repo "should skip this commit") + local ref5=$(make_commit $repo) + + check_uri_with_filter $repo $ref1 "include" "[\"not\",\"skipped\", \"2\"]" "true"| jq -e " + . == [ + {ref: $(echo $ref3 | jq -R .)} + ] + " +} + it_skips_excluded_commits_conventional() { local repo=$(init_repo) local ref1=$(make_commit $repo) diff --git a/test/helpers.sh b/test/helpers.sh index 1ecb42c..7aa452f 100644 --- a/test/helpers.sh +++ b/test/helpers.sh @@ -636,6 +636,7 @@ check_uri_with_filter() { local ref=$2 local type=$3 local value=$4 + local all_match=${5:-"false"} jq -n "{ source: { @@ -643,7 +644,9 @@ check_uri_with_filter() { commit_filter: { $(echo $type | jq -R .): [ $(echo $value | jq -R .) - ] + ], + $(echo $type"_all_match" | jq -R .): $(echo $all_match | jq -R .) + } }, version: {