Skip to content

Commit d2262a4

Browse files
committed
nit: refactor when uri is checked
Signed-off-by: Taylor Silva <dev@taydev.net>
1 parent 9917986 commit d2262a4

7 files changed

Lines changed: 15 additions & 25 deletions

File tree

assets/check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ configure_credentials "$payload"
3838
destination=$TMPDIR/git-resource-repo-cache
3939
uri=$(jq -r '.source.uri // ""' <<< "$payload")
4040
uri=${uri# }
41+
if [[ -z "$uri" ]]; then
42+
echo "source.uri is required and must not be empty"
43+
exit 1
44+
fi
4145

4246
version_type=$(jq -r '.source.version_type // "commits"' <<< "$payload")
4347

assets/check_commits.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ filter_exclude_all_match=$(jq -r '.source.commit_filter.exclude_all_match // fal
1616
version_depth=$(jq -r '.source.version_depth // 1' <<< "$payload")
1717
reverse=false
1818

19-
if [[ -z "$uri" ]]; then
20-
echo "source.uri is required and must not be empty"
21-
exit 1
22-
fi
23-
2419
# Optimization when last commit only is checked and skip ci is disabled
2520
# Get the commit id with git ls-remote instead of downloading the whole repo
2621
if [ "$skip_ci_disabled" = "true" ] && \

assets/in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ configure_credentials "$payload"
5151
# These vars are used by multiple version_type's
5252
uri=$(jq -r '.source.uri // ""' <<< "$payload")
5353
uri=${uri# }
54+
if [[ -z "$uri" ]]; then
55+
echo "source.uri is required and must not be empty"
56+
exit 1
57+
fi
5458

5559
version_type=$(jq -r '.source.version_type // "commits"' <<< "$payload")
5660

assets/in_commits.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ if [ -z "$fetch_tags" ] || [ "$fetch_tags" == "null" ] ; then
2626
fetch_tags=$(jq -r '.source.fetch_tags' <<< "$payload")
2727
fi
2828

29-
if [ -z "$uri" ]; then
30-
echo "invalid payload (missing uri):"
31-
cat $payload
32-
exit 1
33-
fi
34-
3529
branchflag=""
3630
if [ -n "$branch" ]; then
3731
branchflag="--branch $branch"

assets/in_tags.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ gpg_keyserver=$(jq -r '.source.gpg_keyserver // "hkp://keyserver.ubuntu.com/"' <
1010
short_ref_format=$(jq -r '(.params.short_ref_format // "%s")' <<< "$payload")
1111
timestamp_format=$(jq -r '(.params.timestamp_format // "iso8601")' <<< "$payload")
1212

13-
if [ -z "$uri" ]; then
14-
echo "invalid payload (missing uri):"
15-
cat $payload
16-
exit 1
17-
fi
18-
1913
if [ "$disable_git_lfs" == "true" ]; then
2014
# skip the fetching of LFS objects for all following git commands
2115
export GIT_LFS_SKIP_SMUDGE=1
@@ -86,7 +80,7 @@ if [ "$submodules" != "none" ]; then
8680
fi
8781

8882
# check for ssh submodule_credentials
89-
submodule_cred=$(jq --arg submodule_url "${submodule_url}" '.source.submodule_credentials // [] | [.[] | select(.url==$submodule_url)] | first // empty' <<< ${payload})
83+
submodule_cred=$(jq --arg submodule_url "${submodule_url}" '.source.submodule_credentials // [] | [.[] | select(.url==$submodule_url)] | first // empty' <<< "${payload}")
9084

9185
if [[ -z ${submodule_cred} ]]; then
9286

assets/out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ configure_credentials "$payload"
4545
# These vars are used by multiple version_type's
4646
uri=$(jq -r '.source.uri // ""' <<< "$payload")
4747
uri=${uri# }
48+
if [[ -z "$uri" ]]; then
49+
echo "source.uri is required and must not be empty"
50+
exit 1
51+
fi
4852

4953
version_type=$(jq -r '.source.version_type // "commits"' <<< "$payload")
5054

assets/out_commits.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@ push_options=$(jq -r '.params.push_options // []' <<< "$payload")
1616
# useful for pushing to special ref types like refs/for in gerrit.
1717
refs_prefix=$(jq -r '.params.refs_prefix // "refs/heads"' <<< "$payload")
1818

19-
if [ -z "$uri" ]; then
20-
echo "invalid payload (missing uri)"
21-
exit 1
22-
fi
23-
2419
if [ -z "$branch" ] && [ "$only_tag" != "true" ] && [ -z "$override_branch" ]; then
25-
echo "invalid payload (missing branch)"
20+
echo "invalid payload. Must specify one of: source.branch, params.branch, or set params.only_tag=true"
2621
exit 1
2722
fi
2823

2924
if [ -z "$repository" ]; then
30-
echo "invalid payload (missing repository)"
25+
echo "invalid payload (missing params.repository)"
3126
exit 1
3227
fi
3328

0 commit comments

Comments
 (0)