drone_plugin/go_coverter/go_coverter.go

43 lines
688 B
Go
Raw Normal View History

2021-12-28 15:20:31 +08:00
package go_coverter
import (
"context"
2021-12-28 16:09:37 +08:00
"encoding/json"
2021-12-28 16:31:38 +08:00
"github.com/sirupsen/logrus"
2021-12-28 15:20:31 +08:00
2021-12-28 16:23:53 +08:00
"github.com/drone/drone-go/plugin/config"
2021-12-28 15:20:31 +08:00
"github.com/drone/drone-go/drone"
)
2021-12-28 16:23:53 +08:00
const defaultPipeline = `
kind: pipeline
name: default
steps:
- name: build
image: golang
commands:
- go build
- go test -v
`
2021-12-28 15:20:31 +08:00
// New returns a new conversion plugin.
2021-12-28 16:23:53 +08:00
func New() config.Plugin {
2021-12-28 15:20:31 +08:00
return &plugin{}
}
type plugin struct{}
2021-12-28 16:23:53 +08:00
func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, error) {
2021-12-28 16:09:37 +08:00
resp, err := json.Marshal(req)
if err != nil {
2021-12-28 16:31:38 +08:00
logrus.Error(err)
2021-12-28 16:09:37 +08:00
return nil, err
}
2021-12-28 16:31:38 +08:00
logrus.Infof("%s", string(resp))
2021-12-28 15:20:31 +08:00
return &drone.Config{
2021-12-28 16:23:53 +08:00
Data: defaultPipeline,
2021-12-28 15:20:31 +08:00
}, nil
}