From b3918b96634c40bdc1592938fe99c000576c722b Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Sat, 5 May 2018 16:01:50 +0200 Subject: [PATCH] diff and send --- files/check-install.sh | 7 ++++--- files/check.sh | 10 ++++------ files/check_links.go | 28 +++++++++++++++------------- files/check_spell.go | 28 +++++++++++++++------------- 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/files/check-install.sh b/files/check-install.sh index a914e1a..09f577d 100644 --- a/files/check-install.sh +++ b/files/check-install.sh @@ -27,7 +27,8 @@ for dic in $dicList cat /usr/share/hunspell/$dic.aff | iconv --from ISO8859-1 --to UTF-8 | sed 's/SET ISO8859-1/SET UTF-8/' > /usr/share/hunspell/$dic-utf8.aff done -go get -u github.com/ewgRa/ci-utils/diff_liner/diff_liner -go get -u github.com/ewgRa/ci-utils/hunspell_parser/hunspell_parser -go get -u github.com/ewgRa/ci-utils/diff_liner/links_checker +go get -u github.com/ewgRa/ci-utils/utils/diff_liner +go get -u github.com/ewgRa/ci-utils/utils/hunspell_parser +go get -u github.com/ewgRa/ci-utils/utils/github_comments_diff +go get -u github.com/ewgRa/ci-utils/utils/github_comments_send diff --git a/files/check.sh b/files/check.sh index df82065..d6e8ac8 100644 --- a/files/check.sh +++ b/files/check.sh @@ -36,17 +36,15 @@ while read FILE; do echo done < /tmp/changed_files -# FIXME XXX: remove duplicated +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.json -exists-comments /tmp/pr_comments.json > /tmp/send_comments.json OUTPUT=$(cat /tmp/comments.json | (! grep .)); OUTPUT_EXIT_CODE=$? if [ $OUTPUT_EXIT_CODE -ne 0 ]; then - 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 - + github_comments_send -file /tmp/send_comments.json -repo $TRAVIS_REPO_SLUG -pr $TRAVIS_PULL_REQUEST EXIT_CODE=1 fi diff --git a/files/check_links.go b/files/check_links.go index e703103..a5ad839 100644 --- a/files/check_links.go +++ b/files/check_links.go @@ -6,8 +6,8 @@ import ( "flag" "bufio" "regexp" - "github.com/ewgRa/ci-utils/diff_liner" - "github.com/ewgRa/ci-utils/links_checker" + "github.com/ewgRa/ci-utils/src/diff_liner" + "github.com/ewgRa/ci-utils/src/links_checker" "gopkg.in/russross/blackfriday.v2" "encoding/json" "github.com/google/go-github/github" @@ -42,6 +42,8 @@ func main() { scanner := bufio.NewScanner(file) + var comments []*github.PullRequestComment + for scanner.Scan() { line++ @@ -63,22 +65,14 @@ func main() { continue } - body := fmt.Sprintf("Ссылка **%s** ... недоступна с кодом **%v**, ожидается **%v**.\\nЕсли это ожидаемый ответ, внесите \"%v,%s\" в files/expected_codes.csv", link, respCode, expectedCodes, respCode, link) + body := fmt.Sprintf("Ссылка **%s** ... недоступна с кодом **%v**, ожидается **%v**.\nЕсли это ожидаемый ответ, внесите \"%v,%s\" в files/expected_codes.csv", link, respCode, expectedCodes, respCode, link) - comment := &github.PullRequestComment{ + comments = append(comments, &github.PullRequestComment{ Body: &body, CommitID: commit, Path: fileName, Position: &prLine, - } - - jsonData, err := json.Marshal(comment) - - if err != nil { - panic(err) - } - - fmt.Println(string(jsonData)) + }) } } @@ -86,4 +80,12 @@ func main() { panic(err) } + + jsonData, err := json.Marshal(comments) + + if err != nil { + panic(err) + } + + fmt.Println(string(jsonData)) } diff --git a/files/check_spell.go b/files/check_spell.go index 8460e1a..955600a 100644 --- a/files/check_spell.go +++ b/files/check_spell.go @@ -3,8 +3,8 @@ package main import ( "fmt" "os" - "github.com/ewgRa/ci-utils/diff_liner" - "github.com/ewgRa/ci-utils/hunspell_parser" + "github.com/ewgRa/ci-utils/src/diff_liner" + "github.com/ewgRa/ci-utils/src/hunspell_parser" "github.com/google/go-github/github" "flag" "encoding/json" @@ -26,6 +26,8 @@ func main() { hunspellParsedResp := hunspell_parser.ReadHunspellParserResponse(*hunspellParsedFile) + var comments []*github.PullRequestComment + for _, resp := range hunspellParsedResp { prLine := linerResp.GetDiffLine(*file, resp.Line) @@ -33,21 +35,21 @@ func main() { continue } - body := fmt.Sprintf("Возможная ошибка в слове \"**%s**\".\\n Варианты правильного написания \"**%s**\".\\nЕсли слово \"%s\" является правильным, добавьте его в files/dictionary.dic", resp.Word, resp.Alternative, resp.Word) + body := fmt.Sprintf("Возможная ошибка в слове \"**%s**\".\n Варианты правильного написания \"**%s**\".\nЕсли слово \"%s\" является правильным, добавьте его в files/dictionary.dic", resp.Word, resp.Alternative, resp.Word) - comment := &github.PullRequestComment{ + comments = append(comments, &github.PullRequestComment{ Body: &body, CommitID: commit, Path: file, Position: &prLine, - } - - jsonData, err := json.Marshal(comment) - - if err != nil { - panic(err) - } - - fmt.Println(string(jsonData)) + }) } + + jsonData, err := json.Marshal(comments) + + if err != nil { + panic(err) + } + + fmt.Println(string(jsonData)) }