-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved uuid checks on commit hook and make targets
- Loading branch information
1 parent
7ca6664
commit b1f8baf
Showing
5 changed files
with
111 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script finds empty @id: and replace with new uuids | ||
# Then it finds for duplicates and replaces last occurrence with new uuids | ||
# finally it fixes '@id:xyz' to '@id: xyz' (missing space after :) | ||
|
||
ID_TOKEN="@id:" | ||
|
||
# finds occurrences of empty @id: testimony tags | ||
EMPTY_IDS=$(grep -E -i -r -n "${ID_TOKEN}(.+[[:blank:]]|$)" tests/foreman/ --include=*.py) | ||
|
||
if [ -n "$EMPTY_IDS" ]; then | ||
echo "Generating new UUIDS for empty id tags..." | ||
else | ||
echo "No empty id was found" | ||
fi | ||
|
||
# iterate if any empty @id found | ||
for output_line in $EMPTY_IDS | ||
do | ||
if (echo "$output_line" | grep "tests/foreman"); then | ||
OLDIFS=$IFS | ||
# splits the grep output to get filename and occurrence line number | ||
IFS=':' read -r filename line <<< $output_line | ||
# generate uuid and place in specific line number | ||
NEW_ID=$(python -c 'import uuid; print(uuid.uuid4())') | ||
sed -r -i~ "${line}s/${ID_TOKEN}(.+[[:blank:]]|$)/${ID_TOKEN} ${NEW_ID}/g" $filename | ||
IFS=$OLDIFS | ||
fi | ||
done | ||
|
||
# This script finds duplicated @id and replaces with new uuids | ||
|
||
DUP_EXISTS=$(grep -r -i $ID_TOKEN tests/foreman/ --include=*.py | sort | uniq -d | grep $ID_TOKEN) | ||
|
||
if [ -n "$DUP_EXISTS" ]; then | ||
echo "Generating new UUIDS for duplicated id tags..." | ||
else | ||
echo "No duplicated id was found" | ||
fi | ||
|
||
grep -r -i $ID_TOKEN tests/foreman/ --include=*.py | sort | uniq -d | grep $ID_TOKEN | while read -r line ; do | ||
OLDIFS=$IFS | ||
IFS=':' read -r dup_file dup_id <<< $line | ||
echo "filename: $dup_file" | ||
echo "Id to replace: $dup_id" | ||
NEW_ID=$(python -c 'import uuid; print(uuid.uuid4())') | ||
echo "Replacing with the new id: $NEW_ID" | ||
LAST_LINE=$(grep -i -n "$dup_id" $dup_file | tail -1) | ||
|
||
IFS=':' read -r linenumber linecontent <<< $LAST_LINE | ||
echo $linenumber | ||
trimmed_linecontent=$(echo $linecontent) | ||
sed -i~ "${linenumber}s/${trimmed_linecontent}/${ID_TOKEN} ${NEW_ID}/g" $dup_file | ||
echo "----------------------------------------------------------------" | ||
IFS=$OLDIFS | ||
done | ||
|
||
# This script finds @id: missing spaces after : | ||
|
||
|
||
MISSING_SPACES=$(grep -E -i -r -n "${ID_TOKEN}[^ ]" tests/foreman/ --include=*.py) | ||
|
||
if [ -n "$MISSING_SPACES" ]; then | ||
echo "Fixing id: tags missing spaces..." | ||
else | ||
echo "No id missing spaces was found" | ||
fi | ||
|
||
grep -E -i -r -n "${ID_TOKEN}[^ ]" tests/foreman/ --include=*.py | while read -r line ; do | ||
OLDIFS=$IFS | ||
IFS=':' read -r missing_file linenumber linecontent <<< $line | ||
IFS=':' read -r tag uuid <<< $linecontent | ||
trimmed_linecontent=$(echo $linecontent) | ||
sed -i~ "${linenumber}s/${trimmed_linecontent}/${tag}: ${uuid}/g" $missing_file | ||
IFS=$OLDIFS | ||
done |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.