-
Notifications
You must be signed in to change notification settings - Fork 8
/
inactivecommitters
executable file
·108 lines (85 loc) · 3.01 KB
/
inactivecommitters
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# SPDX-License-Identifier: EPL-1.0
##############################################################################
# Copyright (c) 2018 The Linux Foundation and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
##############################################################################
datediff() {
d1=$(date -d "$1" +%s)
d2=$(date -d "$2" +%s)
echo $(( (d1 - d2) / 86400 )) days ago
}
main() {
echo "checking $gerriturl participation for group $group"
echo
currentdate=$(date +%Y-%m-%d)
while read -r line; do
currenetgroup="$group"
group="$(echo "$line" | awk -F"," '{print $1}')"
id="$(echo "$line" | awk -F"," '{print $2}')"
fullname="$(echo "$line" | awk -F"," '{print $3}')"
email="$(echo "$line" | awk -F"," '{print $NF}')"
if [[ "$group" != "$currenetgroup" ]]; then
echo
echo "####### $group #####"
fi
time_ago=$(date -d "-12 month" +%Y-%m-%d)
updated=$(curl --silent -G \
"https://$gerriturl/changes/?q=reviewedby:$id+after:$time_ago%20OR%20owner:$id+after:$time_ago&n=1" \
| grep "updated" \
| awk '{print $2}' \
| sed s,\",,g
)
if [[ -z $updated ]]; then
updated=$(curl --silent -G \
"https://$gerriturl/changes/?q=reviewedby:$id%20OR%20owner:$id&n=1" \
| grep "updated" \
| awk '{print $2}' \
| sed s,\",,g
)
if [[ -z $updated ]]; then
echo -n " ERROR $id, $fullname, $email has no activity "
registered_on=$(ssh -n -p 29418 $gerritssh "gerrit gsql -c \"select registered_on from accounts where full_name = \\\"$fullname\\\" \" ")
whenreg=$(echo $registered_on | awk '{ print $3, $4 }' | awk '{print $1}'| sed s,\(,,g)
if [[ $whenreg == 0 ]]; then
echo "AND USER NEVER REGISTERED"
else
echo -n "REGISTERED ON $whenreg "
datediff "$currentdate" "$whenreg"
fi
else
echo -n " WARNING $id, $fullname, $email inactive since $updated "
datediff "$currentdate" "$updated"
fi
else
echo " OK $id, $fullname, $email last submision or review $updated"
fi
done < <(lftools ldap csv "$group")
}
usage() {
cat << EOF
This program searches gerrit by email for user participation
Email list can be built with 'ldap-lookup'
Program outputs users who have not used gerrit at all, or in the last 6 months
users from this list can be slated to have their access revoked.
If you encounter: "Cant contact LDAP server"
you will need to add:
TLS_CACERT /path/to/ca.crt in /etc/openldap/ldap.conf
ca.crt can be found on any collab system in /etc/ipa/ca.crt
Usage:
$1 target gerrit url
$2 target ldap group
ex: $0 gerrit.opnfv.org/gerrit opnfv-gerrit-releng-submitters
EOF
}
if [[ $# -eq 0 ]] ; then usage "$@"
exit 1
fi
gerriturl="$1"
gerritssh=${gerriturl%/*}
group="$2"
main