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