mirror of https://github.com/CrimsonTome/tldr.git
Check PR: optimize script
parent
c88644a216
commit
11ad7b5203
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
# Check for duplicated pages.
|
# Check for duplicated pages.
|
||||||
function check_duplicates {
|
function check_duplicates {
|
||||||
local msg='The page `%s` already exists under the `%s` platform.\n'
|
|
||||||
local page=$1 # page path in the format 'platform/pagename.md'
|
local page=$1 # page path in the format 'platform/pagename.md'
|
||||||
local parts
|
local parts
|
||||||
local other
|
local other
|
||||||
|
@ -29,18 +28,16 @@ function check_duplicates {
|
||||||
|
|
||||||
case "$platform" in
|
case "$platform" in
|
||||||
common) # check if page already exists in other platforms
|
common) # check if page already exists in other platforms
|
||||||
for other in `ls pages/`; do
|
for other in ${PLATFORMS/common/}; do
|
||||||
if [ "$other" != 'common' ]; then
|
if [ -f "pages/$other/$file" ]; then
|
||||||
if [ -f "pages/$other/$file" ]; then
|
printf "\x2d $MSG_EXISTS" "$page" "$other"
|
||||||
printf "\x2d $msg" "$page" "$other"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*) # check if page already exists under common
|
*) # check if page already exists under common
|
||||||
if [ -f "pages/common/$file" ]; then
|
if [ -f "pages/common/$file" ]; then
|
||||||
printf "\x2d $msg" "$page" 'common'
|
printf "\x2d $MSG_EXISTS" "$page" 'common'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -48,7 +45,6 @@ function check_duplicates {
|
||||||
|
|
||||||
# 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 msg='The page `%s` seems to be a copy of `%s` (%d%% matching).\n'
|
|
||||||
local git_diff
|
local git_diff
|
||||||
local line
|
local line
|
||||||
local entry
|
local entry
|
||||||
|
@ -58,7 +54,7 @@ function check_diff {
|
||||||
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
|
||||||
else
|
else
|
||||||
echo 'Check PR: looks fine, no interesting changes detected.' >&2
|
echo 'Check PR: git diff looks fine, no interesting changes detected.' >&2
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -75,7 +71,7 @@ function check_diff {
|
||||||
percentage=${percentage#0}
|
percentage=${percentage#0}
|
||||||
percentage=${percentage#0}
|
percentage=${percentage#0}
|
||||||
|
|
||||||
printf "\x2d $msg" "$file2" "$file1" "$percentage"
|
printf "\x2d $MSG_IS_COPY" "$file2" "$file1" "$percentage"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
A) # file1 was newly added
|
A) # file1 was newly added
|
||||||
|
@ -87,19 +83,15 @@ function check_diff {
|
||||||
|
|
||||||
# Recursively check the pages/ folder for anomalies.
|
# Recursively check the pages/ folder for anomalies.
|
||||||
function check_structure {
|
function check_structure {
|
||||||
local msg_not_dir='The file `%s` does not look like a directory.\n'
|
for platform in $PLATFORMS; do
|
||||||
local msg_not_file='The file `%s` does not look like a regular file.\n'
|
if [ ! -d "pages/$platform" ]; then
|
||||||
local msg_not_md='The file `%s` does not have a `.md` extension.\n'
|
printf "\x2d $MSG_NOT_DIR" "pages/$platform"
|
||||||
|
|
||||||
for platform in pages/*; do
|
|
||||||
if [ ! -d "$platform" ]; then
|
|
||||||
printf "\x2d $msg_not_dir" "$platform"
|
|
||||||
else
|
else
|
||||||
for page in "$platform"/*; do
|
for page in "pages/$platform"/*; do
|
||||||
if [ ! -f "$page" ]; then
|
if [ ! -f "$page" ]; then
|
||||||
printf "\x2d $msg_not_file" "$page"
|
printf "\x2d $MSG_NOT_FILE" "$page"
|
||||||
elif [ "${page:(-3)}" != ".md" ]; then
|
elif [ "${page:(-3)}" != ".md" ]; then
|
||||||
printf "\x2d $msg_not_md" "$page"
|
printf "\x2d $MSG_NOT_MD" "$page"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
@ -110,6 +102,14 @@ function check_structure {
|
||||||
# MAIN
|
# MAIN
|
||||||
###################################
|
###################################
|
||||||
|
|
||||||
|
MSG_EXISTS='The page `%s` already exists under the `%s` platform.\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_FILE='The file `%s` does not look like a regular file.\n'
|
||||||
|
MSG_NOT_MD='The file `%s` does not have a `.md` extension.\n'
|
||||||
|
|
||||||
|
PLATFORMS=`ls pages/`
|
||||||
|
|
||||||
if [ "$TRAVIS" = "true" ] && [ "$TRAVIS_REPO_SLUG" = "tldr-pages/tldr" ] && [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
|
if [ "$TRAVIS" = "true" ] && [ "$TRAVIS_REPO_SLUG" = "tldr-pages/tldr" ] && [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
|
||||||
check_diff
|
check_diff
|
||||||
check_structure
|
check_structure
|
||||||
|
|
Loading…
Reference in New Issue