1
0
mirror of https://github.com/ru-de/faq.git synced 2024-11-22 18:32:19 +00:00
faq-de/files/ci/go/check_spell/main.go
Evgeniy Sokolov 9788ccd5e1
Github Actions for checks (#574)
* github actions ci

* github actions ci

* github actions ci

* github actions ci

* github actions ci

* github actions ci

* no deprecation

* debug

* debug

* debug

* fix

* fix

* fix

* fix

* fix

* forgotten files

* fix

* fix

* fix

* fix

* oganize everything related to ci in one folder

* add check

* fix path

* get changed files

* try this env

* expected codes file moved

* test check

* test check

* test check

* docker for local test ci and fix dict download

* local setup and some updates

* rollback

* right email
2020-11-12 23:42:25 +01:00

58 lines
1.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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")
file := flag.String("file", "", "File name that checked")
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
}
body := fmt.Sprintf("Возможная ошибка в слове \"**%s**\".\n Варианты правильного написания \"**%s**\".\nЕсли слово \"%s\" является правильным, добавьте его в files/ci/dictionary.dic", resp.Word, resp.Alternative, resp.Word)
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))
}
}