check-pr: add < and > as special cases and refactor (#11841)

pull/23/head
Sebastiaan Speck 2023-12-27 07:36:40 +01:00 committed by GitHub
parent 7b6c610196
commit 4e280a9efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 8 deletions

View File

@ -61,6 +61,31 @@ function check_missing_english_page() {
fi
}
function count_commands() {
local file="$1"
local regex="$2"
grep -c "$regex" "$file"
}
function strip_commands() {
local file="$1"
local regex="$2"
local stripped_commands=()
mapfile -t stripped_commands < <(
grep "$regex" "$file" |
sed 's/{{[^}]*}}/{{}}/g' |
sed 's/<[^>]*>//g' |
sed 's/"[^"]*"/""/g' |
sed "s/'[^']*'//g" |
sed 's/`//g'
)
printf "%s\n" "${stripped_commands[*]}"
}
function check_outdated_page() {
local page=$1
local english_page="pages/${page#pages*\/}"
@ -70,15 +95,17 @@ function check_outdated_page() {
return 1
fi
local english_commands=$(grep -c $command_regex "$english_page")
mapfile -t stripped_english_commands < <(grep $command_regex "$english_page" | sed 's/{{[^}]*}}/{{}}/g' | sed 's/"[^"]*"/""/g' | sed "s/'[^']*'//g" | sed 's/`//g')
local commands=$(grep -c $command_regex $page)
mapfile -t stripped_commands < <(grep $command_regex "$page" | sed 's/{{[^}]*}}/{{}}/g' | sed 's/"[^"]*"/""/g' | sed "s/'[^']*'//g" | sed 's/`//g')
local english_commands
english_commands=$(count_commands "$english_page" "$command_regex")
local commands
commands=$(count_commands "$page" "$command_regex")
local english_commands_as_string=$(printf "%s\n" "${stripped_english_commands[*]}")
local commands_as_string=$(printf "%s\n" "${stripped_commands[*]}")
local english_commands_as_string
english_commands_as_string=$(strip_commands "$english_page" "$command_regex")
local commands_as_string
commands_as_string=$(strip_commands "$page" "$command_regex")
if [[ $english_commands != $commands ]]; then
if [[ "$english_commands" != "$commands" ]]; then
printf "\x2d $MSG_OUTDATED" "$page" "based on number of commands"
elif [[ "$english_commands_as_string" != "$commands_as_string" ]]; then
printf "\x2d $MSG_OUTDATED" "$page" "based on the command contents itself"