-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathget_git_history
executable file
·75 lines (64 loc) · 1.58 KB
/
get_git_history
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
#!/bin/bash
############################################
##
## Prints JSON array from git history
##
############################################
#
# Syntax: $0 [git-repo] [git-branch]
#
# JSON array will have elements like this:
#
# {
# "ts": "1576153516",
# "date": "2019-12-12T12:25:16Z",
# "group": "1.0",
# "channels": [
# {
# "name": "alpha",
# "version": "v1.0.6-rc.6"
# },
# {
# "name": "beta",
# "version": "v1.0.6-rc.6"
# },
# {
# "name": "rc",
# "version": "v1.0.6-rc.6"
# },
# {
# "name": "ea",
# "version": "v1.0.6-rc.6"
# },
# {
# "name": "stable",
# "version": "v1.0.6-rc.6"
# }
# ]
# }
#
############################################
_PWD=$PWD
WORKDIR=$(mktemp -d -p /tmp/)
REPO=${1:-https://github.com/flant/werf.git}
BRANCH=${2:-multiwerf}
git clone -q -b $BRANCH --single-branch $REPO $WORKDIR
test $? -gt 0 && exit 1
cd $WORKDIR
test $? -gt 0 && exit 1
_OUT=''
for i in $(git log --format="%H-%at" multiwerf.json); do
COMMIT_HASH=$( echo $i | cut -d- -f1 )
COMMIT_AUTH_TS=$( echo $i | cut -d- -f2 )
if [ -z $_OUT ]; then
echo -n '[';
else
# comma for element separation
echo -n ',';
fi
_OUT=`git show $COMMIT_HASH:multiwerf.json | jq -cM ".multiwerf[]| select(.group == \"1.0\") | {\"ts\":\"$COMMIT_AUTH_TS\",\"date\":\"\($COMMIT_AUTH_TS | tonumber| todate)\",\"group\":.group,\"channels\":.channels}"`
echo -n $_OUT
done
echo ']'
if [ -n $WORKDIR ]; then rm -rf $WORKDIR; fi
cd $_PWD