Skip to content

Commit

Permalink
Merge pull request #219 from cloudflare/fix-ci
Browse files Browse the repository at this point in the history
Correctly report line numbers
  • Loading branch information
prymitive committed Apr 6, 2022
2 parents 6bdd36c + db62066 commit 5d3783e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
27 changes: 12 additions & 15 deletions cmd/pint/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ func tryDecodingYamlError(e string) (int, string) {
return 1, e
}

func scanProblem(path, owner string, err error) reporter.Report {
line, e := tryDecodingYamlError(err.Error())
return reporter.Report{
Path: path,
Owner: owner,
Problem: checks.Problem{
Lines: []int{line},
Reporter: yamlParseReporter,
Text: e,
Severity: checks.Fatal,
},
}
}

func checkRules(ctx context.Context, workers int, cfg config.Config, entries []discovery.Entry) (summary reporter.Summary) {
jobs := make(chan scanJob, workers*5)
results := make(chan reporter.Report, workers*5)
Expand Down Expand Up @@ -128,7 +114,18 @@ func scanWorker(ctx context.Context, jobs <-chan scanJob, results chan<- reporte
return
default:
if job.entry.PathError != nil {
results <- scanProblem(job.entry.Path, job.entry.Owner, job.entry.PathError)
line, e := tryDecodingYamlError(job.entry.PathError.Error())
results <- reporter.Report{
Path: job.entry.Path,
ModifiedLines: job.entry.ModifiedLines,
Problem: checks.Problem{
Lines: []int{line},
Reporter: yamlParseReporter,
Text: e,
Severity: checks.Fatal,
},
Owner: job.entry.Owner,
}
} else if job.entry.Rule.Error.Err != nil {
results <- reporter.Report{
Path: job.entry.Path,
Expand Down
1 change: 1 addition & 0 deletions cmd/pint/tests/0070_bitbucket_string.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ env BITBUCKET_AUTH_TOKEN="12345"
pint.error -l debug --no-color ci
! stdout .
stderr 'result\\":\\"FAIL\\"'
stderr ',\\"line\\":1,'
stderr 'level=debug msg="Sending a request to BitBucket" method=PUT'
stderr 'level=debug msg="BitBucket request completed" status=200'
stderr 'level=debug msg="Sending a request to BitBucket" method=DELETE'
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.17.3

### Fixed

- File parse errors didn't report correct line numbers when running `pint ci`.

## v0.17.2

### Fixed
Expand Down
10 changes: 5 additions & 5 deletions internal/discovery/git_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ func (f GitBranchFinder) Find() (entries []Entry, err error) {
return nil, fmt.Errorf("failed to run git blame for %s: %w", path, err)
}

alloweLines := []int{}
allowedLines := []int{}
for _, lb := range lbs {
// skip commits that are not part of our diff
if _, ok := commits[lb.Commit]; !ok {
continue
}
alloweLines = append(alloweLines, lb.Line)
allowedLines = append(allowedLines, lb.Line)
}

els, err := readFile(path, !matchesAny(f.relaxed, path))
Expand All @@ -127,11 +127,11 @@ func (f GitBranchFinder) Find() (entries []Entry, err error) {
}
for _, e := range els {
if len(e.ModifiedLines) == 0 {
e.ModifiedLines = alloweLines
if isOverlap(alloweLines, e.Rule.Lines()) {
e.ModifiedLines = allowedLines
if isOverlap(allowedLines, e.Rule.Lines()) {
entries = append(entries, e)
}
} else if isOverlap(alloweLines, e.ModifiedLines) {
} else if isOverlap(allowedLines, e.ModifiedLines) {
entries = append(entries, e)
}
}
Expand Down

0 comments on commit 5d3783e

Please sign in to comment.