2018-05-06 00:27:28 +00:00
package main
import (
"fmt"
"os"
"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"
)
func main ( ) {
prLiner := flag . String ( "pr-liner" , "" , "Pull request liner" )
hunspellParsedFile := flag . String ( "hunspell-parsed-file" , "" , "Hunspell parsed file name" )
2018-05-17 23:09:41 +00:00
file := flag . String ( "file" , "" , "File name that checked" )
2018-05-06 00:27:28 +00:00
commit := flag . String ( "commit" , "" , "Commit" )
flag . Parse ( )
if * prLiner == "" || * hunspellParsedFile == "" || * file == "" || * commit == "" {
flag . Usage ( )
os . Exit ( 1 )
}
linerResp := diff_liner . ReadLinerResponse ( * prLiner )
hunspellParsedResp := hunspell_parser . ReadHunspellParserResponse ( * hunspellParsedFile )
var comments [ ] * github . PullRequestComment
for _ , resp := range hunspellParsedResp {
prLine := linerResp . GetDiffLine ( * file , resp . Line )
if prLine == 0 {
continue
}
2020-11-12 22:42:25 +00:00
body := fmt . Sprintf ( "Возможная ошибка в слове \"**%s**\".\n Варианты правильного написания \"**%s**\".\nЕ с ли слово \"%s\" является правильным, добавьте е г о в files/ci/dictionary.dic" , resp . Word , resp . Alternative , resp . Word )
2018-05-06 00:27:28 +00:00
comments = append ( comments , & github . PullRequestComment {
Body : & body ,
CommitID : commit ,
Path : file ,
Position : & prLine ,
} )
}
if len ( comments ) > 0 {
jsonData , err := json . Marshal ( comments )
if err != nil {
panic ( err )
}
fmt . Println ( string ( jsonData ) )
}
}