Skip to content

Commit

Permalink
Merge branch 'master' into rm-repo-error
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 committed Feb 23, 2022
2 parents 5393195 + c4960cd commit 11b6d25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func setupRegistryService(c *cli.Context, s store.Store) model.RegistryService {
}

func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService {
return environments.Filesystem(c.StringSlice("environment"))
return environments.Parse(c.StringSlice("environment"))
}

// setupRemote helper function to setup the remote from the CLI arguments.
Expand Down
11 changes: 9 additions & 2 deletions server/plugins/environments/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ package environments
import (
"strings"

"github.com/rs/zerolog/log"

"github.com/woodpecker-ci/woodpecker/server/model"
)

type builtin struct {
globals []*model.Environ
}

// Filesystem returns a new local registry service.
func Filesystem(params []string) model.EnvironService {
// Parse returns a EnvironService based on a string slice where key and value are separated by a ":" delimeter.
func Parse(params []string) model.EnvironService {
var globals []*model.Environ

for _, item := range params {
kvPair := strings.SplitN(item, ":", 2)
if len(kvPair) != 2 {
// ignore items only containing a key and no value
log.Warn().Msgf("key '%s' has no value, will be ignored", kvPair[0])
continue
}
globals = append(globals, &model.Environ{Name: kvPair[0], Value: kvPair[1]})
}
return &builtin{globals}
Expand Down

0 comments on commit 11b6d25

Please sign in to comment.