harness-drone/plugin/converter/starlark.go
2019-09-02 23:05:30 -07:00

50 lines
1.1 KiB
Go

// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
// +build !oss
package converter
import (
"bytes"
"context"
"strings"
"github.com/drone/drone/core"
)
// Starlark returns a conversion service that converts the
// starlark file to a yaml file.
func Starlark(enabled bool) core.ConvertService {
return &starlarkPlugin{
enabled: enabled,
}
}
type starlarkPlugin struct {
enabled bool
}
func (p *starlarkPlugin) Convert(ctx context.Context, req *core.ConvertArgs) (*core.Config, error) {
if p.enabled == false {
return nil, nil
}
// if the file extension is not jsonnet we can
// skip this plugin by returning zero values.
switch {
case strings.HasSuffix(req.Repo.Config, ".script"):
case strings.HasSuffix(req.Repo.Config, ".star"):
case strings.HasSuffix(req.Repo.Config, ".starlark"):
default:
return nil, nil
}
// convert the jsonnet file to yaml
buf := new(bytes.Buffer)
return &core.Config{
Data: buf.String(),
}, nil
}