Skip to content

Commit

Permalink
remove '...' and duplicate entries of '---' in final yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
foosinn committed Mar 12, 2019
1 parent d93a611 commit bf462ee
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"path"
"regexp"
"strconv"
"strings"

Expand All @@ -24,18 +25,25 @@ func New(server, token string, concat bool) config.Plugin {
}
}

type plugin struct {
server string
token string
concat bool
}
type (
plugin struct {
server string
token string
concat bool
}

type droneConfig struct {
Name string `yaml:"name"`
Kind string `yaml:"kind"`
}
droneConfig struct {
Name string `yaml:"name"`
Kind string `yaml:"kind"`
}
)

var dedupRegex = regexp.MustCompile(`(?ms)(---[\s]*){2,}`)

func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, error) {
logrus.Infof("--- STARTED ---- %s ---", req.Build.Ref)
defer logrus.Infof("--- FINISHED --- %s ---", req.Build.Ref)

// log
logrus.Debugf("Build: %+v", req.Build)
logrus.Debugf("Repo: %+v", req.Repo)
Expand Down Expand Up @@ -90,6 +98,13 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config,
changedFiles = append(changedFiles, *file.Filename)
}
}
if len(changedFiles) > 0 {
changedList := strings.Join(changedFiles, "\n ")
logrus.Debugf("Changed files: \n %s", changedList)
} else {
logrus.Warn("No changed files found!")
return nil, errors.New("No changed files found")
}

// collect drone.yml files
configData := ""
Expand Down Expand Up @@ -151,6 +166,10 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config,
return nil, errors.New("Did not find a .drone.yml")
}

// cleanup
configData = strings.ReplaceAll(configData, "...", "")
configData = string(dedupRegex.ReplaceAll([]byte(configData), []byte("---")))

return &drone.Config{Data: configData}, nil
}

Expand Down

0 comments on commit bf462ee

Please sign in to comment.