-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathautocorrectinfofile
executable file
·169 lines (131 loc) · 4.25 KB
/
autocorrectinfofile
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/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
##############################################################################
#echo "Diff LDAP against INFO.yaml"
tmpdir(){
DIR="/tmp/infofile/$purpose.$repo.$ldapgroup"
mkdir -p "$DIR"
}
parseoptions() {
if [[ -z $purpose ]]; then
purpose=correct
fi
echo " gerritclonebase $gerritclonebase"
echo " ldapgroup $ldapgroup"
echo " repo $repo"
echo " purpose $purpose"
if [[ $purpose =~ "READY_FOR_INFO" ]]; then
tmpdir "$@"
if ! [[ -d "$DIR"/"$repo" ]]; then
echo " git clone -q $gerritclonebase$repo $DIR/$repo || exit 1"
git clone -q "$gerritclonebase""$repo" "$DIR"/"$repo" || exit 1
fi
if [ ! -f "$DIR"/"$repo"/INFO.yaml ]; then
cp INFO.template.yaml "$DIR"/"$repo"/INFO.yaml || exit 1
else
echo "INFO file already exists, refusing to overwrite"
exit 1
fi
fi
if [[ $purpose =~ "LINT" ]]; then
tmpdir "$@"
if ! [[ -d "$DIR"/"$repo" ]]; then
echo " git clone -q $gerritclonebase$repo $DIR/$repo || exit 1"
git clone -q "$gerritclonebase""$repo" "$DIR"/"$repo" || exit 1
fi
if ! yamllint "$DIR"/"$repo"/INFO.yaml; then
echo "ERROR LINT FAILED"
exit 1
fi
fi
#I should only clone the review if their is a discrepancy in commiters
if [[ $purpose =~ "IN-REVIEW" ]]; then
tmpdir "$@"
if ! [[ -d "$DIR"/"$repo" ]]; then
echo " git clone -q $gerritclonebase$repo $DIR/$repo || exit 1"
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
git clone -q "$gerritclonebase""$repo" "$DIR"/"$repo" || exit 1
cd "$DIR"/"$repo" || exit
git fetch origin "$review" && git checkout --quiet FETCH_HEAD
cd "$SCRIPTDIR" || exit
yamllint "$DIR"/"$repo"/INFO.yaml
if ! yamllint "$DIR"/"$repo"/INFO.yaml; then
echo " ERROR LINT FAILED CANNOT AUTO CORRECT FILE IN REVIEW"
exit 1
fi
fi
fi
main "$@"
}
main() {
if [[ -z $DIR ]]; then
tmpdir "$@"
fi
echo " tmpdir = $DIR"
if lftools ldap yaml4info "$ldapgroup" 2>&- > "$DIR"/LDAP.yaml
then
echo " LDAP lookup sucssesfull"
else
echo " LDAP lookup failed"
exit 1
fi
if ! [[ -d "$DIR"/"$repo" ]]; then
echo " git clone -q $gerritclonebase/$repo $DIR/$repo || exit 1"
git clone -q "$gerritclonebase"/"$repo" "$DIR"/"$repo" || exit 1
fi
diff="$(diff <(lftools infofile get-committers "$DIR"/LDAP.yaml 2>&-| sort) <(lftools infofile get-committers "$DIR"/"$repo"/INFO.yaml 2>&- | sort))"
status="$?"
diff_array=()
onlyinINFO=()
onlyinLDAP=()
while IFS= read -r line; do
diff_array+=( "$line" )
if [[ $(echo "$line" | grep ">") ]];
then
onlyinINFO+=( "$(echo "$line" | awk -F"id: " '{ print $2 }')" )
fi
if [[ $(echo "$line" | grep "<") ]];
then
onlyinLDAP+=( "$(echo "$line" | awk -F"id: " '{ print $2 }')" )
fi
done < <(echo "${diff[@]}" )
if ! [ "${#onlyinINFO[@]}" -eq 0 ]; then
for missing in "${onlyinINFO[@]}"; do
if ! [ -z "$missing" ]; then
echo " DUMMY: sending invite to $missing"
lftools infofile get-committers --id "$missing" "$DIR"/"$repo"/INFO.yaml 2>&-
fi
done
fi
if ! [ "${#onlyinLDAP[@]}" -eq 0 ]; then
echo " These users are listed as commiters in LDAP and not in the INFO.yaml"
for missing in "${onlyinLDAP[@]}"; do
echo " lftools infofile sync-committers $DIR/$repo/INFO.yaml $DIR/LDAP.yaml $missing --repo $repo 2>&-"
lftools infofile sync-committers "$DIR"/"$repo"/INFO.yaml "$DIR"/LDAP.yaml "$missing" --repo "$repo" 2>&-
done
fi
echo " Exit status = $status"
exit "$status"
}
usage() {
cat << EOF
Must be called from lftools
eg: lftools ldap autocorrectinfofile
EOF
exit 1
}
if [[ -z "$*" ]]; then usage
fi
gerritclonebase="$1"
ldapgroup="$2"
repo="$3"
purpose="$4"
review="$5"
parseoptions "$@"