2016-01-18 23:38:49 +00:00
#!/bin/bash
2018-05-13 21:34:43 +00:00
if [ " ${ TRAVIS_PULL_REQUEST } " = "false" ] ; then
echo "Skip, because not a PR"
exit 0
fi
2016-01-19 08:15:30 +00:00
DIR = ` dirname $0 `
2016-01-18 23:38:49 +00:00
2018-01-03 00:57:31 +00:00
git config --global core.quotepath false
2018-01-02 15:28:17 +00:00
git diff HEAD^ --name-status | grep "^D" -v | sed 's/^.\t//g' | grep " \.md $" > /tmp/changed_files
2018-05-06 00:27:28 +00:00
curl -sH "Accept: application/vnd.github.v3.diff.json" https://api.github.com/repos/$TRAVIS_REPO_SLUG /pulls/$TRAVIS_PULL_REQUEST > /tmp/pr.diff
cat /tmp/pr.diff | diff_liner > /tmp/pr_liner.json
2016-01-18 23:38:49 +00:00
2018-05-06 00:27:28 +00:00
rm -f /tmp/comments.json
touch /tmp/comments.json
2017-01-13 17:40:40 +00:00
2018-05-06 00:27:28 +00:00
while read FILE; do
COMMIT = $( git log --pretty= format:"%H" -1 " $FILE " ) ;
echo " Проверка изменений в файле $FILE на опечатки... " ;
2016-01-18 23:38:49 +00:00
2018-05-06 00:27:28 +00:00
cat " $FILE " | sed 's/https\?:[^ ]*//g' | sed "s/[(][^)]*\.md[)]//g" | sed "s/[(]files[^)]*[)]//g" | hunspell -d dictionary,russian-aot-utf8,ru_RU,de_DE-utf8,en_US-utf8 > /tmp/hunspell.out
cat /tmp/hunspell.out | hunspell_parser > /tmp/hunspell_parsed.json
/tmp/check_spell -file " $FILE " -commit= $COMMIT -pr-liner /tmp/pr_liner.json -hunspell-parsed-file /tmp/hunspell_parsed.json >> /tmp/comments.json
2016-01-19 08:42:31 +00:00
2018-05-06 00:27:28 +00:00
echo " Проверка изменений в файле $FILE на недоступные ссылки... " ;
2016-01-18 23:38:49 +00:00
2018-05-06 00:27:28 +00:00
/tmp/check_links -file " $FILE " -commit= $COMMIT -pr-liner /tmp/pr_liner.json -expected-codes files/expected_codes.csv >> /tmp/comments.json
2017-01-12 23:27:07 +00:00
2018-05-06 00:27:28 +00:00
echo
done < /tmp/changed_files
2017-01-13 17:40:40 +00:00
2018-05-06 00:27:28 +00:00
jq -s '[.[][]]' /tmp/comments.json > /tmp/comments_array.json
2017-01-12 23:27:07 +00:00
2018-05-13 20:21:13 +00:00
cat /tmp/comments_array.json
2018-06-07 20:08:01 +00:00
EXIT_CODE = 0
2017-01-12 23:27:07 +00:00
2018-06-07 20:08:01 +00:00
if [ " $( cat /tmp/comments_array.json) " != "[]" ] ; then
2018-05-13 21:34:43 +00:00
curl -s https://api.github.com/repos/$TRAVIS_REPO_SLUG /pulls/$TRAVIS_PULL_REQUEST /comments > /tmp/pr_comments.json
github_comments_diff -comments /tmp/comments_array.json -exists-comments /tmp/pr_comments.json > /tmp/send_comments.json
2018-05-17 20:14:19 +00:00
curl -XPOST " https://github-api-bot.herokuapp.com/send_review?repo= $TRAVIS_REPO_SLUG &pr= $TRAVIS_PULL_REQUEST &body=Спасибо%20за %20PR.%20О б р а тите %20внима ние %20на %20р е зу льта ты%20а вто ма тиче с ко й%20пр о ве р ки%20о р фо г р а фии%20и%20с с ыло к " -d @/tmp/send_comments.json
2018-06-07 20:08:01 +00:00
EXIT_CODE = 1
2018-05-06 00:27:28 +00:00
fi
2018-01-02 15:28:17 +00:00
2016-01-19 08:52:01 +00:00
exit $EXIT_CODE