woodpecker/pipeline/parse.go
Jacob Floyd e34daae0cf
Move cncd/pipeline/pipeline/ to pipeline/ (#347)
* Refactor: move cncd/pipeline/ to pipeline/

* Refactor: move pipeline/pipeline/ to pipeline/
2021-09-24 13:18:34 +02:00

38 lines
721 B
Go

package pipeline
import (
"encoding/json"
"io"
"os"
"strings"
"github.com/woodpecker-ci/woodpecker/pipeline/backend"
)
// Parse parses the pipeline config from an io.Reader.
func Parse(r io.Reader) (*backend.Config, error) {
cfg := new(backend.Config)
err := json.NewDecoder(r).Decode(cfg)
if err != nil {
return nil, err
}
return cfg, nil
}
// ParseFile parses the pipeline config from a file.
func ParseFile(path string) (*backend.Config, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return Parse(f)
}
// ParseString parses the pipeline config from a string.
func ParseString(s string) (*backend.Config, error) {
return Parse(
strings.NewReader(s),
)
}