package gitea import ( "fmt" "strings" "code.gitea.io/sdk/gitea" "github.com/golangci/golangci-lint/pkg/report" "github.com/golangci/golangci-lint/pkg/result" "code.icb4dc0.de/prskr/nitter/nitters" ) var _ nitters.Nitter = (*prNitter)(nil) func NewPRNitter(cli *gitea.Client, cfg *GiteaPRConfig) *prNitter { return &prNitter{ Client: cli, cfg: cfg, } } type prNitter struct { *gitea.Client cfg *GiteaPRConfig } func (p prNitter) Report(report *report.Data, issues []result.Issue) error { warningsBuilder := strings.Builder{} for i := range report.Warnings { warningsBuilder.WriteString(fmt.Sprintf("\t- %s (%s)", report.Warnings[i].Text, report.Warnings[i].Tag)) } pullReviewOptions := gitea.CreatePullReviewOptions{ State: "comment", Body: fmt.Sprintf(`golangci-lint review results: Error: %s Warnings: %s `, report.Error, warningsBuilder.String()), Comments: make([]gitea.CreatePullReviewComment, 0, len(issues)), } for i := range issues { issue := issues[i] pullReviewOptions.Comments = append(pullReviewOptions.Comments, gitea.CreatePullReviewComment{ Path: issue.Pos.Filename, Body: "", NewLineNum: int64(issue.Pos.Line), }) } _, _, err := p.CreatePullReview(p.cfg.Namespace, p.cfg.Repo, p.cfg.PRIndex, pullReviewOptions) if err != nil { return err } return nil }