mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-20 22:28:35 +00:00
56a854fe14
* update github.com/docker/cli * update github.com/docker/distribution * update github.com/docker/docker * update github.com/gin-gonic/gin * update github.com/golang-jwt/jwt/v4 * update github.com/golangci/golangci-lint * update github.com/gorilla/securecookie * update github.com/mattn/go-sqlite3 * update github.com/moby/moby * update github.com/prometheus/client_golang * update github.com/xanzy/go-gitlab
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package printers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/golangci/golangci-lint/pkg/result"
|
|
)
|
|
|
|
type github struct {
|
|
w io.Writer
|
|
}
|
|
|
|
const defaultGithubSeverity = "error"
|
|
|
|
// NewGithub output format outputs issues according to GitHub actions format:
|
|
// https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
|
|
func NewGithub(w io.Writer) Printer {
|
|
return &github{w: w}
|
|
}
|
|
|
|
// print each line as: ::error file=app.js,line=10,col=15::Something went wrong
|
|
func formatIssueAsGithub(issue *result.Issue) string {
|
|
severity := defaultGithubSeverity
|
|
if issue.Severity != "" {
|
|
severity = issue.Severity
|
|
}
|
|
|
|
ret := fmt.Sprintf("::%s file=%s,line=%d", severity, issue.FilePath(), issue.Line())
|
|
if issue.Pos.Column != 0 {
|
|
ret += fmt.Sprintf(",col=%d", issue.Pos.Column)
|
|
}
|
|
|
|
ret += fmt.Sprintf("::%s (%s)", issue.Text, issue.FromLinter)
|
|
return ret
|
|
}
|
|
|
|
func (p *github) Print(_ context.Context, issues []result.Issue) error {
|
|
for ind := range issues {
|
|
_, err := fmt.Fprintln(p.w, formatIssueAsGithub(&issues[ind]))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|