Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func GeneralHandler(ctx context.Context, log *xlog.Logger, a Agent, execRun func
}
}

return Report(ctx, a, lintResults)
return Report(ctx, a, lintResults, unexpected)
}

// ExecRun executes a command.
Expand Down Expand Up @@ -178,7 +178,7 @@ func GeneralParse(log *xlog.Logger, output []byte) (map[string][]LinterOutput, [
// Report reports the lint results.
// This function should be always called even in custom linter handler since it will filter out the lint errors that are not related to the PR.
// and handle some special cases like auto-generated files.
func Report(ctx context.Context, a Agent, lintResults map[string][]LinterOutput) error {
func Report(ctx context.Context, a Agent, lintResults map[string][]LinterOutput, unexpected []string) error {
log := util.FromContext(ctx)
var (
num = a.Provider.GetCodeReviewInfo().Number
Expand All @@ -200,7 +200,7 @@ func Report(ctx context.Context, a Agent, lintResults map[string][]LinterOutput)
metric.IncIssueCounter(orgRepo, linterName, a.Provider.GetCodeReviewInfo().URL, a.Provider.GetCodeReviewInfo().HeadSHA, float64(countLinterErrors(lintResults)))
}

return a.Provider.Report(ctx, a, lintResults)
return a.Provider.Report(ctx, a, lintResults, unexpected)
}

// LineParser is a function that parses a line of linter output.
Expand Down
2 changes: 1 addition & 1 deletion internal/lint/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Provider interface {
// Base on the linter outputs, the provider will create or update or delete the comments for the PR/MR.
HandleComments(ctx context.Context, outputs map[string][]LinterOutput) error
// Report reports the lint results to the provider.
Report(ctx context.Context, agent Agent, lintResults map[string][]LinterOutput) error
Report(ctx context.Context, agent Agent, lintResults map[string][]LinterOutput, unexpected []string) error
// GetFiles returns the files that match the given predicate in the PR/MR.
// if predicate is nil, it returns all the files except removed files in the PR/MR.
// NOTE(CarlJi): this is a simplified definition since only the file path is returned.
Expand Down
23 changes: 14 additions & 9 deletions internal/lint/providergithub.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func filterLinterOutputs(outputs map[string][]LinterOutput, comments []*github.P
return toAdds, toDeletes
}

const Reference = "If you have any questions about this comment, feel free to [raise an issue here](https://github.com/qiniu/reviewbot)."
const Reference = "If you have any questions about this comment, feel free to [raise an issue here](https://github.com/qiniu/reviewbot) or contact the administrator."

func toGithubCheckRunAnnotations(linterOutputs map[string][]LinterOutput) []*github.CheckRunAnnotation {
var annotations []*github.CheckRunAnnotation
Expand Down Expand Up @@ -321,7 +321,7 @@ func (g *GithubProvider) HandleComments(ctx context.Context, outputs map[string]
return nil
}

func (g *GithubProvider) Report(ctx context.Context, a Agent, lintResults map[string][]LinterOutput) error {
func (g *GithubProvider) Report(ctx context.Context, a Agent, lintResults map[string][]LinterOutput, unexpectResults []string) error {
log := util.FromContext(ctx)
linterName := a.LinterConfig.Name
org := a.Provider.GetCodeReviewInfo().Org
Expand All @@ -331,7 +331,7 @@ func (g *GithubProvider) Report(ctx context.Context, a Agent, lintResults map[st

switch a.LinterConfig.ReportType {
case config.GitHubCheckRuns:
check := newBaseCheckRun(a, lintResults)
check := newBaseCheckRun(a, lintResults, unexpectResults)
ch, err := g.CreateCheckRun(ctx, org, repo, check)
if err != nil {
if !errors.Is(err, context.Canceled) {
Expand Down Expand Up @@ -362,7 +362,7 @@ func (g *GithubProvider) Report(ctx context.Context, a Agent, lintResults map[st
metric.NotifyWebhookByText(ConstructGotchaMsg(linterName, a.Provider.GetCodeReviewInfo().URL, addedCmts[0].GetHTMLURL(), lintResults))
case config.GitHubMixType:
// report all lint results as a check run summary, but not annotations
check := newMixCheckRun(a, lintResults)
check := newMixCheckRun(a, lintResults, unexpectResults)
ch, err := g.CreateCheckRun(ctx, org, repo, check)
if err != nil {
if !errors.Is(err, context.Canceled) {
Expand Down Expand Up @@ -763,7 +763,7 @@ func (g *GithubProvider) refreshToken() (string, error) {
}

// newBaseCheckRun creates the base check run options.
func newBaseCheckRun(a Agent, lintErrs map[string][]LinterOutput) github.CreateCheckRunOptions {
func newBaseCheckRun(a Agent, lintErrs map[string][]LinterOutput, unexpected []string) github.CreateCheckRunOptions {
var (
headSha = a.Provider.GetCodeReviewInfo().HeadSHA
startTime = a.Provider.GetCodeReviewInfo().UpdatedAt
Expand Down Expand Up @@ -800,17 +800,22 @@ func newBaseCheckRun(a Agent, lintErrs map[string][]LinterOutput) github.CreateC
}

if len(annotations) > 0 {
check.Conclusion = github.String("failure")
check.Conclusion = github.String("neutral")
} else {
check.Conclusion = github.String("success")
}

if len(unexpected) > 0 {
check.Conclusion = github.String("failure")
check.Output.Title = github.String(fmt.Sprintf("%s failed to execute, please check it", linterName))
check.Output.Summary = github.String(fmt.Sprintf(":information_source: %s's execution scripts and output are in the [log](%s).\n :recycle: You can check to see if the script is working in your repository.\n :busts_in_silhouette: If it's missing something critical, contact reviewbot administrator to add it.", linterName, logURL))
}
return check
}

func newMixCheckRun(a Agent, lintErrs map[string][]LinterOutput) github.CreateCheckRunOptions {
check := newBaseCheckRun(a, lintErrs)
if len(lintErrs) == 0 {
func newMixCheckRun(a Agent, lintErrs map[string][]LinterOutput, unexpected []string) github.CreateCheckRunOptions {
check := newBaseCheckRun(a, lintErrs, unexpected)
if len(lintErrs) == 0 && len(unexpected) != 0 {
// if no lint errors, just return the base check run
return check
}
Expand Down
2 changes: 1 addition & 1 deletion internal/lint/providergitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func linterNamePrefixGitLab(linterName string) string {
return fmt.Sprintf("[**%s**]", linterName)
}

func (g *GitlabProvider) Report(ctx context.Context, a Agent, lintResults map[string][]LinterOutput) error {
func (g *GitlabProvider) Report(ctx context.Context, a Agent, lintResults map[string][]LinterOutput, unexpected []string) error {
linterName := a.LinterConfig.Name
org := a.Provider.GetCodeReviewInfo().Org
repo := a.Provider.GetCodeReviewInfo().Repo
Expand Down
2 changes: 1 addition & 1 deletion internal/linters/doc/note-check/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func noteCheckHandler(ctx context.Context, a lint.Agent) error {
}
}

return lint.Report(ctx, a, outputs)
return lint.Report(ctx, a, outputs, nil)
}

const NoteSuggestion = "A Note is recommended to use \"MARKER(uid): note body\" format."
Expand Down
2 changes: 1 addition & 1 deletion internal/linters/go/gofmt/gofmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func gofmtHandler(ctx context.Context, a lint.Agent) error {
return err
}

return lint.Report(ctx, a, parsedOutput)
return lint.Report(ctx, a, parsedOutput, nil)
}

type Gofmt struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/linters/go/gomodcheck/gomodcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func goModCheckHandler(ctx context.Context, a lint.Agent) error {
log.Errorf("gomodchecks parse output failed: %v", err)
return err
}
return lint.Report(ctx, a, parsedOutput)
return lint.Report(ctx, a, parsedOutput, nil)
}

func goModCheckOutput(log *xlog.Logger, a lint.Agent) (map[string][]lint.LinterOutput, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/linters/shell/shellcheck/shellcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ func shellcheck(ctx context.Context, a lint.Agent) error {

// even if the lintResults is empty, we still need to report the result
// since we need delete the existed comments related to the linter
return lint.Report(ctx, a, lintResults)
return lint.Report(ctx, a, lintResults, nil)
}
Loading