This commit is contained in:
parent
a79e0a4557
commit
b2dc7dbd57
7 changed files with 243 additions and 31 deletions
|
@ -6,6 +6,9 @@ package plugin
|
|||
|
||||
import (
|
||||
"context"
|
||||
"git.entr0py.de/garionion/drone-yaml-server/repo"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/drone/drone-go/plugin/config"
|
||||
|
@ -25,34 +28,41 @@ steps:
|
|||
`
|
||||
|
||||
// New returns a new config plugin.
|
||||
func New(param1, param2 string) config.Plugin {
|
||||
func New(repository, branch, token string, frequency time.Duration) config.Plugin {
|
||||
repos := repo.Repos{&repo.Repo{
|
||||
URL: repository,
|
||||
Token: token,
|
||||
Branch: branch,
|
||||
Frequency: frequency,
|
||||
}}
|
||||
repos.Init()
|
||||
|
||||
return &plugin{
|
||||
// TODO replace or remove these configuration
|
||||
// parameters. They are for demo purposes only.
|
||||
param1: param1,
|
||||
param2: param2,
|
||||
repos: repos,
|
||||
}
|
||||
}
|
||||
|
||||
type plugin struct {
|
||||
// TODO replace or remove these configuration
|
||||
// parameters. They are for demo purposes only.
|
||||
param1 string
|
||||
param2 string
|
||||
repos repo.Repos
|
||||
}
|
||||
|
||||
func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, error) {
|
||||
// TODO replace or remove
|
||||
// this demonstrates how we can override
|
||||
// and return a custom configuration file
|
||||
if req.Repo.Namespace == "some-organization" {
|
||||
return &drone.Config{
|
||||
Data: defaultPipeline,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// return nil and Drone will fallback to
|
||||
// the standard behavior for getting the
|
||||
// configuration file.
|
||||
configuration, err := p.repos.GetConfiguration(req.Repo.HTTPURL)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
if configuration != "" {
|
||||
return &drone.Config{
|
||||
Data: configuration,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue