-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
executable file
·78 lines (69 loc) · 1.67 KB
/
functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
#
# Extract URL from the payload
# We expect, this value should be declared like that:
#
# - name: fyzon
# type: fyzon-resource
# source:
# url: "http://ci.my.host"
#
# @param payload
#
function extractUrl() {
url=$(echo "$1" | jq -r '(.source.url )')
echo $url
}
#
# Extract project ID from the payload
#
#
function extractProjectId() {
project_id=$(echo "$1" | jq -r '(.params.project_id)')
echo $project_id
}
#
# Extract delimeter from the payload
#
#
function extractDelimeter() {
delimeter=$(echo "$1" | jq -r '(.params.delimeter)')
echo $delimeter
}
#
# Extract format for the exported data
#
function extractFormat() {
exportFormat=$(echo "$1" | jq -r '(.params.format)')
echo $exportFormat
}
#
# Extract countries.
# We want to get as result array of strings in format "country|fyzonURL",
# later it would be easy to download them in a loop
#
# Playground: https://jqplay.org/s/Dt53PSGbUq
#
function extractCountries() {
countries=$(echo "$1" | jq -r '.params.countries[]|to_entries|map(.key + "|" + .value)|.[]')
echo "${countries[@]}"
}
#
# Download one file from Fyzon, this command cound be called in the loop
#
# @param line extracted from extractCountries() function, such as "gb|messages-gb.properties"
# @param format. Expected "json", "properties" etc...
# @param project_id
# @param base url of Fyzon
# @param delimeter (optional)
#
function buildUrlToFile() {
# extract the first part of the line before "|"
country="${1%|*}"
if [ -z "$5" ] || [ "$5" == "null" ]; then
delimeterArg=""
else
delimeterArg="?delimeter=$5"
fi
echo "$4/api/project/$3/file/$country/$2$delimeterArg"
}