Skip to content

Commit ebde571

Browse files
committed
Correcting the scenario when result of json can be an object or an array, so to tackle both the scenarios in the function of fallbacking
1 parent 7924866 commit ebde571

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

src/docker-outside-of-docker/install.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,17 @@ get_previous_version() {
156156
output=$(curl -s "$repo_url");
157157

158158
check_packages jq
159-
160-
message=$(echo "$output" | jq -r '.message')
161159

162-
if [[ $message == "API rate limit exceeded"* ]]; then
163-
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}"
164-
echo -e "\nAttempting to find latest version using GitHub tags."
165-
find_prev_version_from_git_tags prev_version "$url" "tags/v"
166-
declare -g ${variable_name}="${prev_version}"
167-
else
168-
echo -e "\nAttempting to find latest version using GitHub Api."
160+
if echo "$output" | jq -e 'type == "object"' > /dev/null; then
161+
message=$(echo "$output" | jq -r '.message')
162+
if [[ $message == "API rate limit exceeded"* ]]; then
163+
echo -e "\nAn attempt to find previous to latest version using GitHub Api Failed... \nReason: ${message}"
164+
echo -e "\nAttempting to find previous to latest version using GitHub tags."
165+
find_prev_version_from_git_tags prev_version "$url" "tags/v"
166+
declare -g ${variable_name}="${prev_version}"
167+
fi
168+
elif echo "$output" | jq -e 'type == "array"' > /dev/null; then
169+
echo -e "\nAttempting to find previous version using GitHub Api."
169170
version=$(echo "$output" | jq -r '.[1].tag_name')
170171
declare -g ${variable_name}="${version#v}"
171172
fi

test/docker-outside-of-docker/docker_build_compose_fallback.sh

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,21 @@ get_previous_version() {
112112
local variable_name=$3
113113
local mode=$4
114114
prev_version=${!variable_name}
115-
116115
output=$(curl -s "$repo_url");
117-
118116
check_packages jq
119-
120-
message=$(echo "$output" | jq -r '.message')
121-
122-
if [[ $message == "API rate limit exceeded"* ]] || [[ $mode == 'mode1' ]]; then
123-
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}"
124-
echo -e "\nAttempting to find latest version using GitHub tags."
125-
find_prev_version_from_git_tags prev_version "$url" "tags/v"
126-
declare -g ${variable_name}="${prev_version}"
127-
else
128-
echo -e "\nAttempting to find latest version using GitHub Api."
117+
if echo "$output" | jq -e 'type == "object"' > /dev/null; then
118+
message=$(echo "$output" | jq -r '.message')
119+
if [[ $message == "API rate limit exceeded"* ]] || [[ $mode == 'mode1' ]]; then
120+
echo -e "\nAn attempt to find previous to latest version using GitHub Api Failed... \nReason: ${message}"
121+
echo -e "\nAttempting to find previous to latest version using GitHub tags."
122+
find_prev_version_from_git_tags prev_version "$url" "tags/v"
123+
declare -g ${variable_name}="${prev_version}"
124+
fi
125+
elif echo "$output" | jq -e 'type == "array"' > /dev/null; then
126+
echo -e "\nAttempting to find previous version using GitHub Api."
129127
version=$(echo "$output" | jq -r '.[1].tag_name')
130128
declare -g ${variable_name}="${version#v}"
131-
fi
132-
echo "${variable_name}=${!variable_name}"
129+
fi
133130
}
134131

135132
get_github_api_repo_url() {

0 commit comments

Comments
 (0)