Skip to content

Commit 3c7aec6

Browse files
authored
Merge pull request #432 from concourse/issue/389
Add [include/exclude]_all_match
2 parents 58fbf4e + 3e5769c commit 3c7aec6

5 files changed

Lines changed: 39 additions & 11 deletions

File tree

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ RUN git config --global user.name "git"
3232
RUN git config --global pull.rebase "false"
3333
RUN git config --global protocol.file.allow "always"
3434

35-
ADD assets/ /opt/resource/
36-
RUN chmod +x /opt/resource/*
37-
3835
ENV CXXFLAGS -DOPENSSL_API_COMPAT=0x30000000L
3936
ADD scripts/install_git_crypt.sh install_git_crypt.sh
4037
RUN ./install_git_crypt.sh && rm ./install_git_crypt.sh
@@ -186,6 +183,9 @@ WORKDIR /usr/lib
186183
RUN rm -rf \
187184
perl
188185

186+
ADD assets/ /opt/resource/
187+
RUN chmod +x /opt/resource/*
188+
189189
FROM resource AS tests
190190
ADD test/ /tests
191191
RUN /tests/all.sh

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ Tracks the commits in a [git](http://git-scm.com/) repository.
140140
* `commit_filter`: *Optional.* Object containing commit message filters
141141
* `exclude`: *Optional.* Array containing strings that should
142142
cause a commit to be skipped
143+
* `exclude_all_match`: *Optional.* Boolean wheater it should match all the exclude filters "AND", default: false
143144
* `include`: *Optional.* Array containing strings that
144145
*MUST* be included in commit messages for the commit to not be
145146
skipped
147+
* `include_all_match`: *Optional.* Boolean wheater it should match all the include filters "AND", default: false
146148

147149
**Note**: *You must escape any regex sensitive characters, since the string is used as a regex filter.*
148150
For example, using `[skip deploy]` or `[deploy skip]` to skip non-deployment related commits in a deployment pipeline:

assets/check

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ git_config_payload=$(jq -r '.source.git_config // []' <<< "$payload")
2828
ref=$(jq -r '.version.ref // ""' <<< "$payload")
2929
skip_ci_disabled=$(jq -r '.source.disable_ci_skip // false' <<< "$payload")
3030
filter_include=$(jq '.source.commit_filter.include // []' <<< "$payload")
31+
filter_include_all_match=$(jq -r '.source.commit_filter.include_all_match // false' <<< "$payload")
3132
filter_exclude=$(jq '.source.commit_filter.exclude // []' <<< "$payload")
33+
filter_exclude_all_match=$(jq -r '.source.commit_filter.exclude_all_match // false' <<< "$payload")
3234
version_depth=$(jq -r '.source.version_depth // 1' <<< "$payload")
3335
reverse=false
3436

@@ -120,25 +122,32 @@ else
120122
paths_search=`echo "-- $paths $ignore_paths" | tr "\n\r" " "`
121123
fi
122124

125+
set -x
123126
list_command="git rev-list --all --first-parent $log_range $paths_search"
124127
if jq -e 'length > 0' <<<"$filter_include"
125128
then
126129
list_command+=" | git rev-list --stdin --date-order --first-parent --no-walk=unsorted "
127-
whitelist_items=$(echo $filter_include | jq -r -c '.[]')
128-
for wli in "$whitelist_items"
130+
include_items=$(echo $filter_include | jq -r -c '.[]')
131+
for wli in "$include_items"
129132
do
130133
list_command+=" --grep=\"$wli\""
131134
done
135+
if [ "$filter_include_all_match" == "true" ]; then
136+
list_command+=" --all-match"
137+
fi
132138
fi
133139

134140
if jq -e 'length > 0' <<<"$filter_exclude"
135141
then
136-
list_command+=" | git rev-list --stdin --date-order --invert-grep --first-parent --no-walk=unsorted "
137-
blacklist_items=$(echo $filter_exclude | jq -r -c '.[]')
138-
for bli in "$blacklist_items"
142+
list_command+=" | git rev-list --stdin --date-order --invert-grep --first-parent --no-walk=unsorted "
143+
exclude_items=$(echo $filter_exclude | jq -r -c '.[]')
144+
for bli in "$exclude_items"
139145
do
140146
list_command+=" --grep=\"$bli\""
141147
done
148+
if [ "$filter_exclude_all_match" == "true" ]; then
149+
list_command+=" --all-match"
150+
fi
142151
fi
143152

144153

test/check.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,21 @@ it_skips_non_included_commits() {
513513
"
514514
}
515515

516+
it_skips_all_non_included_commits() {
517+
local repo=$(init_repo)
518+
local ref1=$(make_commit $repo)
519+
local ref2=$(make_commit_to_future $repo "not skipped commit")
520+
local ref3=$(make_commit $repo "not skipped commit 2")
521+
local ref4=$(make_commit $repo "should skip this commit")
522+
local ref5=$(make_commit $repo)
523+
524+
check_uri_with_filter $repo $ref1 "include" 'not\nskipped\n2' "true"| jq -e "
525+
. == [
526+
{ref: $(echo $ref3 | jq -R .)}
527+
]
528+
"
529+
}
530+
516531
it_skips_excluded_commits_conventional() {
517532
local repo=$(init_repo)
518533
local ref1=$(make_commit $repo)
@@ -995,6 +1010,7 @@ run it_skips_excluded_commits_conventional
9951010
run it_skips_non_included_commits
9961011
run it_skips_non_included_and_excluded_commits
9971012
run it_rejects_filter_with_incorrect_format
1013+
run it_skips_all_non_included_commits
9981014
run it_does_not_skip_marked_commits_when_disable_skip_configured
9991015
run it_fails_if_key_has_password_not_provided
10001016
run it_can_unlock_key_with_password

test/helpers.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,14 +636,15 @@ check_uri_with_filter() {
636636
local ref=$2
637637
local type=$3
638638
local value=$4
639+
local all_match=${5:-"false"}
639640

640641
jq -n "{
641642
source: {
642643
uri: $(echo $uri| jq -R .),
643644
commit_filter: {
644-
$(echo $type | jq -R .): [
645-
$(echo $value | jq -R .)
646-
]
645+
$(echo $type | jq -R .): $(echo -en $value | jq -sR 'split("\n") | if type=="string" then [.] else . end' ),
646+
$(echo $type"_all_match" | jq -R .): $(echo $all_match | jq -R .)
647+
647648
}
648649
},
649650
version: {

0 commit comments

Comments
 (0)