mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 10:21:00 +00:00
d3eea72663
* upgrade to codeberg.org/6543/go-yaml2json v0.2.1 * upgraded github.com/bmatcuk/doublestar/v4 v4.0.2 => v4.2.0 * upgraded github.com/docker/cli v20.10.14+incompatible => v20.10.17+incompatible * upgraded github.com/docker/docker v20.10.14+incompatible => v20.10.17+incompatible * upgraded github.com/gin-gonic/gin v1.7.7 => v1.8.1 * upgraded github.com/golang-jwt/jwt/v4 v4.4.1 => v4.4.2 * upgraded github.com/moby/moby v20.10.14+incompatible => v20.10.17+incompatible * upgraded github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 => v0.0.0-20220808134915-39b0c02b01ae * upgraded github.com/lafriks/ttlcache/v3 v3.1.0 => v3.2.0 * upgraded github.com/mattn/go-sqlite3 v1.14.12 => v1.14.15 * upgraded github.com/lib/pq v1.10.5 => v1.10.6 * github.com/prometheus/client_golang v1.12.1 => v1.13.0 * upgraded github.com/urfave/cli/v2 v2.5.1 => v2.11.2 * upgraded github.com/rs/zerolog v1.26.1 => v1.27.0 * upgraded golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 => v0.0.0-20220822191816-0ebed06d0094 * upgraded github.com/xanzy/go-gitlab v0.64.0 => v0.73.1 * upgraded google.golang.org/grpc v1.47.0 => v1.49.0
36 lines
824 B
Go
36 lines
824 B
Go
package schema
|
|
|
|
import (
|
|
"bytes"
|
|
_ "embed"
|
|
"fmt"
|
|
"io"
|
|
|
|
"codeberg.org/6543/go-yaml2json"
|
|
"github.com/xeipuuv/gojsonschema"
|
|
)
|
|
|
|
//go:embed schema.json
|
|
var schemaDefinition []byte
|
|
|
|
// Lint lints an io.Reader against the Woodpecker schema.json
|
|
func Lint(r io.Reader) ([]gojsonschema.ResultError, error) {
|
|
schemaLoader := gojsonschema.NewBytesLoader(schemaDefinition)
|
|
buff := new(bytes.Buffer)
|
|
err := yaml2json.StreamConvert(r, buff)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Failed to load yml file %w", err)
|
|
}
|
|
|
|
documentLoader := gojsonschema.NewBytesLoader(buff.Bytes())
|
|
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Validation failed %w", err)
|
|
}
|
|
|
|
if !result.Valid() {
|
|
return result.Errors(), fmt.Errorf("Config not valid")
|
|
}
|
|
|
|
return nil, nil
|
|
}
|