2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2018 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
13 #echo "Diff LDAP against INFO.yaml"
17 DIR="/tmp/infofile/$purpose.$repo.$ldapgroup"
24 if [[ -z $purpose ]]; then
28 echo " gerritclonebase $gerritclonebase"
29 echo " ldapgroup $ldapgroup"
31 echo " purpose $purpose"
33 if [[ $purpose =~ "READY_FOR_INFO" ]]; then
37 if ! [[ -d "$DIR"/"$repo" ]]; then
38 echo " git clone -q $gerritclonebase$repo $DIR/$repo || exit 1"
39 git clone -q "$gerritclonebase""$repo" "$DIR"/"$repo" || exit 1
41 if [ ! -f "$DIR"/"$repo"/INFO.yaml ]; then
42 cp INFO.template.yaml "$DIR"/"$repo"/INFO.yaml || exit 1
44 echo "INFO file already exists, refusing to overwrite"
50 if [[ $purpose =~ "LINT" ]]; then
54 if ! [[ -d "$DIR"/"$repo" ]]; then
55 echo " git clone -q $gerritclonebase$repo $DIR/$repo || exit 1"
56 git clone -q "$gerritclonebase""$repo" "$DIR"/"$repo" || exit 1
58 if ! yamllint "$DIR"/"$repo"/INFO.yaml; then
59 echo "ERROR LINT FAILED"
65 #I should only clone the review if their is a discrepancy in commiters
66 if [[ $purpose =~ "IN-REVIEW" ]]; then
70 if ! [[ -d "$DIR"/"$repo" ]]; then
71 echo " git clone -q $gerritclonebase$repo $DIR/$repo || exit 1"
72 SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
73 git clone -q "$gerritclonebase""$repo" "$DIR"/"$repo" || exit 1
74 cd "$DIR"/"$repo" || exit
75 git fetch origin "$review" && git checkout --quiet FETCH_HEAD
76 cd "$SCRIPTDIR" || exit
77 yamllint "$DIR"/"$repo"/INFO.yaml
78 if ! yamllint "$DIR"/"$repo"/INFO.yaml; then
79 echo " ERROR LINT FAILED CANNOT AUTO CORRECT FILE IN REVIEW"
91 if [[ -z $DIR ]]; then
96 if lftools ldap yaml4info "$ldapgroup" 2>&- > "$DIR"/LDAP.yaml
98 echo " LDAP lookup sucssesfull"
100 echo " LDAP lookup failed"
104 if ! [[ -d "$DIR"/"$repo" ]]; then
105 echo " git clone -q $gerritclonebase/$repo $DIR/$repo || exit 1"
106 git clone -q "$gerritclonebase"/"$repo" "$DIR"/"$repo" || exit 1
109 diff="$(diff <(lftools infofile get-committers "$DIR"/LDAP.yaml 2>&-| sort) <(lftools infofile get-committers "$DIR"/"$repo"/INFO.yaml 2>&- | sort))"
116 while IFS= read -r line; do
117 diff_array+=( "$line" )
118 if [[ $(echo "$line" | grep ">") ]];
120 onlyinINFO+=( "$(echo "$line" | awk -F"id: " '{ print $2 }')" )
122 if [[ $(echo "$line" | grep "<") ]];
124 onlyinLDAP+=( "$(echo "$line" | awk -F"id: " '{ print $2 }')" )
126 done < <(echo "${diff[@]}" )
129 if ! [ "${#onlyinINFO[@]}" -eq 0 ]; then
130 for missing in "${onlyinINFO[@]}"; do
131 if ! [ -z "$missing" ]; then
132 echo " DUMMY: sending invite to $missing"
133 lftools infofile get-committers --id "$missing" "$DIR"/"$repo"/INFO.yaml 2>&-
138 if ! [ "${#onlyinLDAP[@]}" -eq 0 ]; then
139 echo " These users are listed as commiters in LDAP and not in the INFO.yaml"
140 for missing in "${onlyinLDAP[@]}"; do
141 echo " lftools infofile sync-committers $DIR/$repo/INFO.yaml $DIR/LDAP.yaml $missing --repo $repo 2>&-"
142 lftools infofile sync-committers "$DIR"/"$repo"/INFO.yaml "$DIR"/LDAP.yaml "$missing" --repo "$repo" 2>&-
147 echo " Exit status = $status"
154 Must be called from lftools
155 eg: lftools ldap autocorrectinfofile
160 if [[ -z "$*" ]]; then usage