Skip to content

Commit

Permalink
Adding --all-match to include/exclude filters & some tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Werner <[email protected]>
  • Loading branch information
Jakub Werner committed Sep 20, 2022
1 parent bb551c3 commit aaa9c30
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions assets/check
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions test/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -636,14 +636,17 @@ check_uri_with_filter() {
local ref=$2
local type=$3
local value=$4
local all_match=${5:-"false"}

jq -n "{
source: {
uri: $(echo $uri| jq -R .),
commit_filter: {
$(echo $type | jq -R .): [
$(echo $value | jq -R .)
]
],
$(echo $type"_all_match" | jq -R .): $(echo $all_match | jq -R .)
}
},
version: {
Expand Down

0 comments on commit aaa9c30

Please sign in to comment.