Skip to content

Commit

Permalink
smarter build list of runners
Browse files Browse the repository at this point in the history
create "pending" reports on tool start
  • Loading branch information
taraspos committed Oct 22, 2020
1 parent 3cdc676 commit f18714f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
34 changes: 24 additions & 10 deletions cmd/reviewdog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,8 @@ github-pr-check reporter as a fallback.
}
ctx = ct

// get list of runners, so we can create "green" for that runner
// if there are no issues from it
runnersList := strings.Split(opt.runners, ",")
if projectConf != nil {
for runner := range projectConf.Runner {
runnersList = append(runnersList, runner)
}
}

cs = bbservice.NewReportAnnotator(client,
build.Owner, build.Repo, build.SHA, runnersList)
build.Owner, build.Repo, build.SHA, getRunnersList(opt, projectConf))

// by default scan whole project with "filter.ModeNoFilter"
// Bitbucket pipelines doesn't give an easy way to know
Expand Down Expand Up @@ -768,3 +759,26 @@ func buildRunnersMap(runners string) map[string]bool {
}
return m
}

func getRunnersList(opt *option, conf *project.Config) []string {
if len(opt.runners) > 0 { // if runners explicitly defined, use them
return strings.Split(opt.runners, ",")
}

if conf != nil { // if this is a Project run, and no explicitly provided runners
// if no runners explicitly provided
// get all runners from config
list := make([]string, 0, len(conf.Runner))
for runner := range conf.Runner {
list = append(list, runner)
}
return list
}

// if this is simple run, get the single tool name
if name := toolName(opt); len(name) > 0 {
return []string{name}
}

return []string{}
}
33 changes: 20 additions & 13 deletions service/bitbucket/annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,32 @@ type ReportAnnotator struct {

// NewReportAnnotator creates new Bitbucket Report Annotator
func NewReportAnnotator(cli *openapi.APIClient, owner, repo, sha string, runners []string) *ReportAnnotator {
// pre populate map of annotations, so we still create passed (green) report
// if no issues found from the specific tool
annotations := make(map[string][]openapi.ReportAnnotation, len(runners))
for _, runner := range runners {
if len(runner) == 0 {
continue
}
annotations[runner] = []openapi.ReportAnnotation{}
}

return &ReportAnnotator{
r := &ReportAnnotator{
cli: cli,
sha: sha,
owner: owner,
repo: repo,
annotations: annotations,
annotations: make(map[string][]openapi.ReportAnnotation, len(runners)),
severityMap: map[rdf.Severity]string{
rdf.Severity_INFO: annotationSeverityLow,
rdf.Severity_WARNING: annotationSeverityMedium,
rdf.Severity_ERROR: annotationSeverityHigh,
},
duplicates: map[string]struct{}{},
}

// pre populate map of annotations, so we still create passed (green) report
// if no issues found from the specific tool
for _, runner := range runners {
if len(runner) == 0 {
continue
}
r.annotations[runner] = []openapi.ReportAnnotation{}
// create Pending report for each tool
_ = r.createOrUpdateReport(context.Background(), reportID(runner, reporter), reportTitle(runner, reporter), reportResultPending)
}

return r
}

// Post accepts a comment and holds it. Flush method actually posts comments to
Expand Down Expand Up @@ -101,7 +104,7 @@ func (r *ReportAnnotator) Flush(ctx context.Context) error {
// create/update/annotate report per tool
for tool, annotations := range r.annotations {
reportID := reportID(reporter, tool)
title := fmt.Sprintf("[%s] %s report", tool, reporter)
title := reportTitle(tool, reporter)
if len(annotations) == 0 {
// if no annotation, create Passed report
if err := r.createOrUpdateReport(ctx, reportID, title, reportResultPassed); err != nil {
Expand Down Expand Up @@ -196,3 +199,7 @@ func hashString(str string) string {
func reportID(ids ...string) string {
return strings.ReplaceAll(strings.ToLower(strings.Join(ids, "-")), " ", "_")
}

func reportTitle(tool, reporter string) string {
return fmt.Sprintf("[%s] %s report", tool, reporter)
}

0 comments on commit f18714f

Please sign in to comment.