2016-01-18 23:38:49 +00:00
#!/bin/bash
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-05-03 22:28:41 +00:00
go build -o /tmp/check_spell $DIR /check_spell.go
go build -o /tmp/check_links $DIR /check_links.go
2018-01-03 00:32:04 +00:00
( cat $DIR /dictionary.dic; echo ) | sed '/^$/d' | wc -l > /tmp/dictionary.dic
( cat $DIR /dictionary.dic; echo ) | sed '/^$/d' >> /tmp/dictionary.dic
2016-01-19 08:42:31 +00:00
2018-01-03 00:32:04 +00:00
echo "SET UTF-8" >> /tmp/dictionary.aff
sudo mv /tmp/dictionary.* /usr/share/hunspell
2016-01-19 12:50:18 +00:00
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-03 22:28:41 +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-03 22:28:41 +00:00
rm -f /tmp/comments.json
touch /tmp/comments.json
2017-01-12 23:27:07 +00:00
2018-05-03 22:28:41 +00:00
while read FILE; do
2018-05-04 22:36:18 +00:00
COMMIT = $( git log --pretty= format:"%H" -1 " $FILE " ) ;
2018-05-03 22:28:41 +00:00
echo -n " Проверка изменений в файле $FILE на опечатки... " ;
2017-01-12 23:27:07 +00:00
2018-05-03 22:28:41 +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
2018-05-04 22:36:18 +00:00
/tmp/check_spell -file " $FILE " -commit= $COMMIT -pr-liner /tmp/pr_liner.json -hunspell-parsed-file /tmp/hunspell_parsed.json >> /tmp/comments.json
2017-01-12 23:27:07 +00:00
2018-05-03 22:28:41 +00:00
echo -n " Проверка изменений в файле $FILE на недоступные ссылки... " ;
2017-01-12 23:27:07 +00:00
2018-05-04 22:36:18 +00:00
/tmp/check_links -file " $FILE " -commit= $COMMIT -pr-liner /tmp/pr_liner.json -expected-codes files/expected_codes.csv >> /tmp/comments.json
2018-01-02 15:28:17 +00:00
echo
done < /tmp/changed_files
2017-01-12 23:27:07 +00:00
2018-05-05 07:34:20 +00:00
# FIXME XXX: remove duplicated
2018-05-03 22:28:41 +00:00
OUTPUT = $( cat /tmp/comments.json | ( ! grep .) ) ;
OUTPUT_EXIT_CODE = $?
if [ $OUTPUT_EXIT_CODE -ne 0 ] ; then
2018-05-05 07:34:20 +00:00
while read -r COMMENT; do
cat $COMMENT > /tmp/comment.json
curl -s -XPOST https://api.github.com/repos/$TRAVIS_REPO_SLUG /pulls/$TRAVIS_PULL_REQUEST /comments?access_token= $GH_TOKEN -d @/tmp/comment.json > /tmp/git_answer.json
done < /tmp/comments.json
2018-05-03 22:28:41 +00:00
EXIT_CODE = 1
fi
2016-01-19 08:52:01 +00:00
exit $EXIT_CODE