Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifies the behavior of the tag_filter #165

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Tracks the commits in a [git](http://git-scm.com/) repository.

* `tag_filter`: *Optional.* If specified, the resource will only detect commits
that have a tag matching the expression that have been made against
the `branch`. Patterns are [glob(7)](http://man7.org/linux/man-pages/man7/glob.7.html)
the `branch`. If `branch` is set the filter will only match tags on that particular branch otherwise the filter will match tags from all branches. Patterns are [glob(7)](http://man7.org/linux/man-pages/man7/glob.7.html)
compatible (as in, bash compatible).

* `git_config`: *Optional.* If specified as (list of pairs `name` and `value`)
Expand All @@ -75,7 +75,6 @@ Tracks the commits in a [git](http://git-scm.com/) repository.
* `gpg_keyserver`: *Optional.* GPG keyserver to download the public keys from.
Defaults to `hkp:///keys.gnupg.net/`.


* `git_crypt_key`: *Optional.* Base64 encoded
[git-crypt](https://github.com/AGWA/git-crypt) key. Setting this will
unlock / decrypt the repository with `git-crypt`. To get the key simply
Expand Down
15 changes: 12 additions & 3 deletions assets/check
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ if [ -d $destination ]; then
git fetch
git reset --hard FETCH_HEAD
else
singlebranchflag="--single-branch"
mergedflag="--merged"
if [ -n "$tag_filter" ] && [ -z "$branch" ]; then
singlebranchflag=""
mergedflag=""
fi

branchflag=""
if [ -n "$branch" ]; then
branchflag="--branch $branch"
fi

git clone --single-branch $uri $branchflag $destination
git clone $singlebranchflag $uri $branchflag $destination
cd $destination
fi

Expand Down Expand Up @@ -71,10 +78,11 @@ fi

if [ -n "$tag_filter" ]; then
{
git_tag_base='git tag --list "$tag_filter" --sort=creatordate $mergedflag'
if [ -n "$ref" ]; then
git tag --list "$tag_filter" --sort=creatordate --contains $ref
eval $git_tag_base --contains $ref
else
git tag --list "$tag_filter" --sort=creatordate | tail -1
eval $git_tag_base | tail -1
fi
} | jq -R '.' | jq -s "map({ref: .})" >&3
else
Expand All @@ -84,3 +92,4 @@ else
set +f
} | jq -R '.' | jq -s "map({ref: .})" >&3
fi

8 changes: 7 additions & 1 deletion assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ configure_credentials $payload

uri=$(jq -r '.source.uri // ""' < $payload)
branch=$(jq -r '.source.branch // ""' < $payload)
tag_filter=$(jq -r '.source.tag_filter // ""' < $payload)
git_config_payload=$(jq -r '.source.git_config // []' < $payload)
ref=$(jq -r '.version.ref // "HEAD"' < $payload)
depth=$(jq -r '(.params.depth // 0)' < $payload)
Expand All @@ -48,6 +49,11 @@ if [ -z "$uri" ]; then
exit 1
fi

singlebranchflag="--single-branch"
if [ -n "$tag_filter" ] && [ -z "$branch" ]; then
singlebranchflag=""
fi

branchflag=""
if [ -n "$branch" ]; then
branchflag="--branch $branch"
Expand All @@ -58,7 +64,7 @@ if test "$depth" -gt 0 2> /dev/null; then
depthflag="--depth $depth"
fi

git clone --single-branch $depthflag $uri $branchflag $destination
git clone $singlebranchflag $depthflag $uri $branchflag $destination

cd $destination

Expand Down
34 changes: 34 additions & 0 deletions test/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,38 @@ it_can_check_with_tag_filter_with_cursor() {
'
}

it_can_check_with_tag_filter_for_all_branches() {
local repo=$(init_repo)
local ref1=$(make_commit $repo)
local ref2=$(make_annotated_tag $repo "1.0-staging" "a tag")
local ref3=$(make_commit $repo)
local ref4=$(make_annotated_tag $repo "2.0-staging" "a tag")
local ref5=$(make_commit_to_branch $repo "bogus")
local ref6=$(make_annotated_tag $repo "3.0-staging" "a tag")
local ref7=$(make_commit_to_branch $repo "bogus")
local ref8=$(make_annotated_tag $repo "4.0-staging" "a tag")

check_uri_with_tag_filter_no_branch $repo "*-staging" | jq -e '
. == [{ref: "4.0-staging"}]
'
}

it_ignores_tag_filter_for_other_branches() {
local repo=$(init_repo)
local ref1=$(make_commit $repo)
local ref2=$(make_annotated_tag $repo "1.0-staging" "a tag")
local ref3=$(make_commit $repo)
local ref4=$(make_annotated_tag $repo "2.0-staging" "a tag")
local ref5=$(make_commit_to_branch $repo "bogus")
local ref6=$(make_annotated_tag $repo "3.0-staging" "a tag")
local ref7=$(make_commit_to_branch $repo "bogus")
local ref8=$(make_annotated_tag $repo "4.0-staging" "a tag")

check_uri_with_tag_filter_on_branch $repo "*-staging" "master" | jq -e '
. == [{ref: "2.0-staging"}]
'
}

it_can_check_and_set_git_config() {
local repo=$(init_repo)
local ref=$(make_commit $repo)
Expand Down Expand Up @@ -489,6 +521,8 @@ run it_clears_netrc_even_after_errors
run it_can_check_empty_commits
run it_can_check_with_tag_filter
run it_can_check_with_tag_filter_with_cursor
run it_can_check_with_tag_filter_for_all_branches
run it_ignores_tag_filter_for_other_branches
run it_can_check_from_head_only_fetching_single_branch
run it_can_check_and_set_git_config
run it_can_check_from_a_ref_and_only_show_merge_commit
Expand Down
21 changes: 21 additions & 0 deletions test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,27 @@ check_uri_from_paths_ignoring() {
check_uri_with_tag_filter() {
local uri=$1
local tag_filter=$2

check_uri_with_tag_filter_on_branch $uri $tag_filter "master"
}

check_uri_with_tag_filter_on_branch() {
local uri=$1
local tag_filter=$2
local branch=$3
jq -n "{
source: {
uri: $(echo $uri | jq -R .),
tag_filter: $(echo $tag_filter | jq -R .),
branch: $(echo $branch | jq -R .)
}
}" | ${resource_dir}/check | tee /dev/stderr
}

check_uri_with_tag_filter_no_branch() {
local uri=$1
local tag_filter=$2

jq -n "{
source: {
uri: $(echo $uri | jq -R .),
Expand Down