Skip to content

Commit 39069e0

Browse files
re-implement
1 parent 590f478 commit 39069e0

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

cmd/api-linter/github_actions.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"strings"
2121

2222
"github.com/googleapis/api-linter/v2/lint"
23+
dpb "google.golang.org/protobuf/types/descriptorpb"
2324
)
2425

2526
// formatGitHubActionOutput returns lint errors in GitHub actions format.
@@ -34,8 +35,8 @@ func formatGitHubActionOutput(responses []lint.Response) []byte {
3435
fmt.Fprintf(&buf, "::error file=%s", response.FilePath)
3536

3637
if problem.Location != nil {
37-
loc := lint.FileLocationFromPBLocation(problem.Location, nil)
38-
fmt.Fprintf(&buf, ",line=%d,endLine=%d,col=%d,endColumn=%d", loc.Start.Line, loc.End.Line, loc.Start.Column, loc.End.Column)
38+
start, end := fileLocationFromPBLocation(problem.Location)
39+
fmt.Fprintf(&buf, ",line=%d,endLine=%d,col=%d,endColumn=%d", start.Line, end.Line, start.Column, end.Column)
3940
}
4041

4142
// GitHub uses :: as control characters (which are also used to delimit
@@ -54,3 +55,29 @@ func formatGitHubActionOutput(responses []lint.Response) []byte {
5455

5556
return buf.Bytes()
5657
}
58+
59+
type position struct {
60+
Line int
61+
Column int
62+
}
63+
64+
// Implementation copied from lint/problem.go
65+
func fileLocationFromPBLocation(l *dpb.SourceCodeInfo_Location) (start, end position) {
66+
start = position{
67+
Line: int(l.Span[0]) + 1,
68+
Column: int(l.Span[1]) + 1,
69+
}
70+
71+
if len(l.Span) == 4 {
72+
end = position{
73+
Line: int(l.Span[2]) + 1,
74+
Column: int(l.Span[3]),
75+
}
76+
} else {
77+
end = position{
78+
Line: int(l.Span[0]) + 1,
79+
Column: int(l.Span[2]),
80+
}
81+
}
82+
return start, end
83+
}

0 commit comments

Comments
 (0)