forked from RasmusVoss/gitflow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitflow-gerrit
60 lines (53 loc) · 1.9 KB
/
gitflow-gerrit
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
#!/bin/sh
#
# git-flow extension to bundle common gerrit functions
#
password=""
gerrit_check(){
local val1=$(gerrit_url)
local val2=$(gerrit_user)
local val3=$(gerrit_pwd)
local val4=`curl -0 -3 -L -u $(gerrit_user):$(gerrit_pwd) -s --ssl-allow-beast "$(gerrit_url)/a/changes/?q=is:open" -w "%{http_code}" -o /dev/null`
[ "$val4" != "200" ] && die "Cannot connect to gerrit. Status: $val4"
[ "$val4" == "500" ] && die "Please check username and password"
[ -z "$val1" -o -z "$val2" -o -z "$val3" -o "$val4" != "200" ] && echo 0
[ -z "$val1" -o -z "$val2" -o -z "$val3" -o "$val4" != "200" ] || echo 1
}
gerrit_url() {
local val
val=$(git config --get "gerrit.baseurl" | sed 's,^\(https?://[^:]*/.*[^/]\)$,\1,')
[[ -z "$val" ]] && die "Please set gerrit.baseurl in git config. Format: https://host/gerrit"
echo $val
}
gerrit_user() {
local val
val=$(git config --get "gerrit.user")
[[ -z "$val" ]] && die "Please set gerrit.user in git config"
echo $val
}
gerrit_pwd() {
val=$(git config --get "gerrit.pwd")
#[[ -z "$val" ]] && ( warn "Please enter password (or set in config gerrit.pwd):"; read -s val )
[[ -z "$val" ]] && die "Please set gerrit.pwd"
echo $val
}
gerrit_query() {
local subst=$(echo "$1" | sed 's/ /+/g')
local res=`curl -0 -3 -L -u $(gerrit_user):$(gerrit_pwd) -s --ssl-allow-beast "$(gerrit_url)/a/changes/?q=$subst&format=JSON&o=LABELS&o=CURRENT_REVISION&o=ALL_REVISIONS" -b cookie -c cookie | tail -n +2 | sed 's/\r?\n//g'`
echo $res
}
gerrit_query_filter() {
local res=$(cat)
rows=$(echo "$res" | gitflow-JSON.sh | grep -c '\[[0-9+]\]')
[ "$rows" == "1" ] || return 1
local filter=$1
value=$(echo "$res" | gitflow-JSON.sh | sed -n "s/^\[0,\"$filter\"]\t//p" | sed 's/"//g')
[ "$value" ] || return 1
echo "$value"
}
gerrit_query_filter_open() {
local res=$(cat)
status=$(echo "$res" | gerrit_query_filter status)
result=[ "$status" == "NEW" -o "$status" == "SUBMITTED" ]
echo "$result"
}