Skip to content

Commit

Permalink
OBS-851 ignore problems on unmodified lines
Browse files Browse the repository at this point in the history
When running in CI mode all modified files are parsed and scanned. But when reporting errors to BitBucket we only send problems from modified lines (since it doesn't accept annotations on unmodified lines). This means that we can find a BUG on unmodified line and exit with non-zero code, but send a PASS report to BB.
Fix it by ignoring problems unless they are from modified lines during scan. Scan will discard anything and not pass it further if it's not modified.
  • Loading branch information
prymitive committed Aug 5, 2021
1 parent 19629c2 commit 61ca610
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cmd/pint/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,15 @@ func scanFiles(cfg config.Config, fcs discovery.FileFindResults, ld discovery.Li
Str("lines", output.FormatLineRangeString(rule.Lines())).
Msg("Found invalid rule")
}
if !lineResults.HasLines(rule.Lines()) {
log.Debug().Str("path", path).Str("lines", output.FormatLineRangeString(rule.Lines())).Msg("Skipping rule")
continue
}

if rule.Error.Err == nil {
checkList := cfg.GetChecksForRule(path, rule)
for _, check := range checkList {
check := check
scanJobs = append(scanJobs, scanJob{path: path, rule: rule, check: check})
scanJobs = append(scanJobs, scanJob{path: path, rule: rule, check: check, lines: lineResults})
}
} else {
scanJobs = append(scanJobs, scanJob{path: path, rule: rule, check: nil})
scanJobs = append(scanJobs, scanJob{path: path, rule: rule, check: nil, lines: lineResults})
}
}
}
Expand Down Expand Up @@ -158,6 +154,7 @@ type scanJob struct {
path string
rule parser.Rule
check checks.RuleChecker
lines discovery.LineFindResults
}

func scanWorker(jobs <-chan scanJob, results chan<- reporter.Report) {
Expand All @@ -173,7 +170,11 @@ func scanWorker(jobs <-chan scanJob, results chan<- reporter.Report) {
}}
} else {
for _, problem := range job.check.Check(job.rule) {
results <- reporter.Report{Path: job.path, Rule: job.rule, Problem: problem}
if job.lines.HasLines(problem.Lines) {
results <- reporter.Report{Path: job.path, Rule: job.rule, Problem: problem}
} else {
log.Debug().Str("path", job.path).Str("lines", output.FormatLineRangeString(problem.Lines)).Msg("Problem reported on unmodified lines, ignoring")
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/reporter/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ func (r BitBucketReporter) Submit(summary Summary) (err error) {
func (r BitBucketReporter) makeAnnotation(report Report, summary Summary, pb git.FileBlames) (annotations []BitBucketAnnotation) {
gitBlames, ok := pb[report.Path]
if !ok {
log.Debug().Str("path", report.Path).Msg("File not found in git blame")
return
}

reportLine := -1
for _, pl := range report.Problem.Lines {
commit := gitBlames.GetCommit(pl)
log.Debug().Str("commit", commit).Str("path", report.Path).Int("line", pl).Msg("Got commit for line")
if summary.FileChanges.HasCommit(commit) {
reportLine = pl
}
Expand All @@ -122,6 +124,7 @@ func (r BitBucketReporter) makeAnnotation(report Report, summary Summary, pb git
}

if reportLine < 0 {
log.Debug().Str("path", report.Path).Msg("No file line found, skipping")
return
}

Expand Down

0 comments on commit 61ca610

Please sign in to comment.