2023-11-03 10:44:03 +00:00
|
|
|
package errors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"go.uber.org/multierr"
|
|
|
|
|
2024-04-15 08:04:21 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/pipeline/errors/types"
|
2023-11-03 10:44:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type LinterErrorData struct {
|
2023-11-04 14:30:47 +00:00
|
|
|
File string `json:"file"`
|
2023-11-03 10:44:03 +00:00
|
|
|
Field string `json:"field"`
|
|
|
|
}
|
|
|
|
|
2023-11-04 14:30:47 +00:00
|
|
|
type DeprecationErrorData struct {
|
|
|
|
File string `json:"file"`
|
|
|
|
Field string `json:"field"`
|
|
|
|
Docs string `json:"docs"`
|
|
|
|
}
|
|
|
|
|
2024-04-24 14:07:16 +00:00
|
|
|
type BadHabitErrorData struct {
|
|
|
|
File string `json:"file"`
|
|
|
|
Field string `json:"field"`
|
|
|
|
Docs string `json:"docs"`
|
|
|
|
}
|
|
|
|
|
2024-04-15 08:04:21 +00:00
|
|
|
func GetLinterData(e *types.PipelineError) *LinterErrorData {
|
|
|
|
if e.Type != types.PipelineErrorTypeLinter {
|
2023-11-03 10:44:03 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if data, ok := e.Data.(*LinterErrorData); ok {
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-04-15 08:04:21 +00:00
|
|
|
func GetPipelineErrors(err error) []*types.PipelineError {
|
|
|
|
var pipelineErrors []*types.PipelineError
|
2023-11-03 10:44:03 +00:00
|
|
|
for _, _err := range multierr.Errors(err) {
|
2024-04-15 08:04:21 +00:00
|
|
|
var err *types.PipelineError
|
2023-11-03 10:44:03 +00:00
|
|
|
if errors.As(_err, &err) {
|
|
|
|
pipelineErrors = append(pipelineErrors, err)
|
|
|
|
} else {
|
2024-04-15 08:04:21 +00:00
|
|
|
pipelineErrors = append(pipelineErrors, &types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
Message: _err.Error(),
|
2024-04-15 08:04:21 +00:00
|
|
|
Type: types.PipelineErrorTypeGeneric,
|
2023-11-03 10:44:03 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pipelineErrors
|
|
|
|
}
|
|
|
|
|
|
|
|
func HasBlockingErrors(err error) bool {
|
|
|
|
if err == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
errs := GetPipelineErrors(err)
|
|
|
|
|
|
|
|
for _, err := range errs {
|
|
|
|
if !err.IsWarning {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|