mirror of https://github.com/CrimsonTome/tldr.git
check-pr: add outdated-check (#11498)
parent
b1fb8776a0
commit
8f1ca06f30
|
@ -10,7 +10,10 @@
|
||||||
# 3. Detect pages that were added in the 'common' platform although they
|
# 3. Detect pages that were added in the 'common' platform although they
|
||||||
# already exist under a platform specific directory.
|
# already exist under a platform specific directory.
|
||||||
# 4. Detect pages that do not exist as English pages yet.
|
# 4. Detect pages that do not exist as English pages yet.
|
||||||
# 5. Detect other miscellaneous anomalies in the pages folder.
|
# 5. Detect outdated pages. A page is marked as outdated when the number of
|
||||||
|
# commands differ from the number of commands in the English page or the
|
||||||
|
# contents of the commands differ from the English page.
|
||||||
|
# 6. Detect other miscellaneous anomalies in the pages folder.
|
||||||
#
|
#
|
||||||
# Results are printed to stdout, logs and errors to stderr.
|
# Results are printed to stdout, logs and errors to stderr.
|
||||||
#
|
#
|
||||||
|
@ -46,21 +49,49 @@ function check_duplicates {
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_missing_english_page() {
|
function check_missing_english_page() {
|
||||||
local page="$1"
|
local page=$1
|
||||||
local english_page="pages/${page#pages*\/}"
|
local english_page="pages/${page#pages*\/}"
|
||||||
|
|
||||||
|
if [[ "$page" = "$english_page" ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$english_page" ]]; then
|
if [[ ! -f "$english_page" ]]; then
|
||||||
printf "\x2d $MSG_NOT_EXISTS" "$page" "$english_page"
|
printf "\x2d $MSG_NOT_EXISTS" "$page" "$english_page"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function check_outdated_page() {
|
||||||
|
local page=$1
|
||||||
|
local english_page="pages/${page#pages*\/}"
|
||||||
|
local command_regex='^`.*`$'
|
||||||
|
|
||||||
|
if [[ "$page" = "$english_page" ]] || [[ ! -f "$english_page" ]]; then
|
||||||
|
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_as_string=$(printf "%s\n" "${stripped_english_commands[*]}")
|
||||||
|
local commands_as_string=$(printf "%s\n" "${stripped_commands[*]}")
|
||||||
|
|
||||||
|
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"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Look at git diff and check for copied/duplicated pages.
|
# Look at git diff and check for copied/duplicated pages.
|
||||||
function check_diff {
|
function check_diff {
|
||||||
local git_diff
|
local git_diff
|
||||||
local line
|
local line
|
||||||
local entry
|
local entry
|
||||||
|
|
||||||
git_diff=$(git diff --name-status --find-copies-harder --diff-filter=AC origin/main -- pages*/)
|
git_diff=$(git diff --name-status --find-copies-harder --diff-filter=ACM origin/main -- pages*/)
|
||||||
|
|
||||||
if [[ -n $git_diff ]]; then
|
if [[ -n $git_diff ]]; then
|
||||||
echo -e "Check PR: git diff:\n$git_diff" >&2
|
echo -e "Check PR: git diff:\n$git_diff" >&2
|
||||||
|
@ -85,9 +116,10 @@ function check_diff {
|
||||||
printf "\x2d $MSG_IS_COPY" "$file2" "$file1" "$percentage"
|
printf "\x2d $MSG_IS_COPY" "$file2" "$file1" "$percentage"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
A) # file1 was newly added
|
A|M) # file1 was newly added or modified
|
||||||
check_duplicates "$file1"
|
check_duplicates "$file1"
|
||||||
check_missing_english_page "$file1"
|
check_missing_english_page "$file1"
|
||||||
|
check_outdated_page "$file1"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done <<< "$git_diff"
|
done <<< "$git_diff"
|
||||||
|
@ -116,6 +148,7 @@ function check_structure {
|
||||||
|
|
||||||
MSG_EXISTS='The page `%s` already exists under the `%s` platform.\n'
|
MSG_EXISTS='The page `%s` already exists under the `%s` platform.\n'
|
||||||
MSG_NOT_EXISTS='The page `%s` does not exists as English page `%s` yet.\n'
|
MSG_NOT_EXISTS='The page `%s` does not exists as English page `%s` yet.\n'
|
||||||
|
MSG_OUTDATED='The page `%s` is outdated, %s.\n'
|
||||||
MSG_IS_COPY='The page `%s` seems to be a copy of `%s` (%d%% matching).\n'
|
MSG_IS_COPY='The page `%s` seems to be a copy of `%s` (%d%% matching).\n'
|
||||||
MSG_NOT_DIR='The file `%s` does not look like a directory.\n'
|
MSG_NOT_DIR='The file `%s` does not look like a directory.\n'
|
||||||
MSG_NOT_FILE='The file `%s` does not look like a regular file.\n'
|
MSG_NOT_FILE='The file `%s` does not look like a regular file.\n'
|
||||||
|
|
Loading…
Reference in New Issue