2018-05-03 22:28:41 +00:00
package main
import (
"fmt"
"os"
2018-05-05 14:01:50 +00:00
"github.com/ewgRa/ci-utils/src/diff_liner"
"github.com/ewgRa/ci-utils/src/hunspell_parser"
2018-05-03 22:28:41 +00:00
"github.com/google/go-github/github"
"flag"
"encoding/json"
)
func main ( ) {
prLiner := flag . String ( "pr-liner" , "" , "Pull request liner" )
hunspellParsedFile := flag . String ( "hunspell-parsed-file" , "" , "Hunspell parsed file name" )
file := flag . String ( "file" , "" , "Hunspell parsed file name" )
2018-05-04 22:36:18 +00:00
commit := flag . String ( "commit" , "" , "Commit" )
2018-05-03 22:28:41 +00:00
flag . Parse ( )
2018-05-04 22:36:18 +00:00
if * prLiner == "" || * hunspellParsedFile == "" || * file == "" || * commit == "" {
2018-05-03 22:28:41 +00:00
flag . Usage ( )
os . Exit ( 1 )
}
linerResp := diff_liner . ReadLinerResponse ( * prLiner )
hunspellParsedResp := hunspell_parser . ReadHunspellParserResponse ( * hunspellParsedFile )
2018-05-05 14:01:50 +00:00
var comments [ ] * github . PullRequestComment
2018-05-03 22:28:41 +00:00
for _ , resp := range hunspellParsedResp {
prLine := linerResp . GetDiffLine ( * file , resp . Line )
if prLine == 0 {
continue
}
2018-05-05 14:01:50 +00:00
body := fmt . Sprintf ( "Возможная ошибка в слове \"**%s**\".\n Варианты правильного написания \"**%s**\".\nЕ с ли слово \"%s\" является правильным, добавьте е г о в files/dictionary.dic" , resp . Word , resp . Alternative , resp . Word )
2018-05-03 22:28:41 +00:00
2018-05-05 14:01:50 +00:00
comments = append ( comments , & github . PullRequestComment {
2018-05-03 22:28:41 +00:00
Body : & body ,
2018-05-04 22:36:18 +00:00
CommitID : commit ,
2018-05-03 22:28:41 +00:00
Path : file ,
Position : & prLine ,
2018-05-05 14:01:50 +00:00
} )
}
2018-05-03 22:28:41 +00:00
2018-05-05 19:46:04 +00:00
if len ( comments ) > 0 {
jsonData , err := json . Marshal ( comments )
2018-05-03 22:28:41 +00:00
2018-05-05 19:46:04 +00:00
if err != nil {
panic ( err )
}
2018-05-05 14:01:50 +00:00
2018-05-05 19:46:04 +00:00
fmt . Println ( string ( jsonData ) )
}
2018-05-03 22:28:41 +00:00
}