grim/convey

A bunch more linting

2018-02-19, Gary Kramlich
ba0997ff0c93
Parents f3a61cc7b59d
Children 2e301c2a4e30
A bunch more linting
--- a/loaders/bitbucket/loader.go Mon Feb 19 00:14:29 2018 -0600
+++ b/loaders/bitbucket/loader.go Mon Feb 19 00:43:38 2018 -0600
@@ -32,6 +32,10 @@
"github.com/go-yaml/yaml"
)
+const (
+ defaultPlan = "default"
+)
+
// Loader is a loader.Loader that loads bitbucket-pipelines.yml files
type Loader struct{}
@@ -51,19 +55,19 @@
loginTask := ""
logoutTask := ""
- image := defImage
+ img := defImage
if pipeline.Steps.Image.Name != "" {
- image = pipeline.Steps.Image
+ img = pipeline.Steps.Image
// if the step has an image with a username, we need to add the tasks to login and logout
- if image.Username != "" {
- registry, _, _ := docker.ParseImage(image.Name)
+ if img.Username != "" {
+ registry, _, _ := docker.ParseImage(img.Name)
// create and add the login task to the stage
loginTask = fmt.Sprintf("%s-%d-login", name, idx)
cfg.Tasks[loginTask] = &docker.Login{
- Username: image.Username,
- Password: image.Password,
+ Username: img.Username,
+ Password: img.Password,
Server: registry,
}
@@ -73,7 +77,7 @@
Server: registry,
}
}
- } else if image.Username != "" {
+ } else if img.Username != "" {
// if we're using the global image and it has a username, we need to add the tasks to the stage
loginTask = "login"
logoutTask = "logout"
@@ -84,16 +88,16 @@
plan.Stages[idx].Tasks = append(plan.Stages[idx].Tasks, loginTask)
}
- parsedTasks, err := script.Parse(image.Name, "/bin/sh", pipeline.Steps.Script)
+ parsedTasks, err := script.Parse(img.Name, "/bin/sh", pipeline.Steps.Script)
if err != nil {
return err
}
for idx, task := range parsedTasks {
- name := fmt.Sprintf("%s-%d", name, idx)
- cfg.Tasks[name] = task
+ taskName := fmt.Sprintf("%s-%d", name, idx)
+ cfg.Tasks[taskName] = task
- plan.Stages[0].Tasks = append(plan.Stages[0].Tasks, name)
+ plan.Stages[0].Tasks = append(plan.Stages[0].Tasks, taskName)
}
@@ -112,8 +116,8 @@
func addPipelines(base string, defImage image, pipelines map[string][]pipeline, cfg *config.Config) error {
for name, branchPipeline := range pipelines {
if len(branchPipeline) > 0 {
- name := fmt.Sprintf("%s-%s", base, name)
- err := addPipeline(name, defImage, branchPipeline, cfg)
+ planName := fmt.Sprintf("%s-%s", base, name)
+ err := addPipeline(planName, defImage, branchPipeline, cfg)
if err != nil {
return err
}
@@ -190,7 +194,6 @@
// LoadOverride loads the given override file into the config.
func (l *Loader) LoadOverride(base, path string, data []byte, cfg *config.Config, disableDeprecated bool) {
- return
}
// Filenames returns the list for filenames that this loader supports.
@@ -205,7 +208,7 @@
// DefaultPlan returns the default plan name.
func (l *Loader) DefaultPlan() string {
- return "default"
+ return defaultPlan
}
// ResolvePlanName resolves the plan name if the one in the config contains a
@@ -213,8 +216,8 @@
func (l *Loader) ResolvePlanName(plan string, cfg *config.Config, st *state.State) string {
if plan != "" {
// try to shortcut if we can
- if plan == "default" {
- return "default"
+ if plan == defaultPlan {
+ return defaultPlan
}
customPlan := fmt.Sprintf("custom-%s", plan)
@@ -256,5 +259,5 @@
}
}
- return "default"
+ return defaultPlan
}
--- a/loaders/bitbucket/types.go Mon Feb 19 00:14:29 2018 -0600
+++ b/loaders/bitbucket/types.go Mon Feb 19 00:43:38 2018 -0600
@@ -44,7 +44,7 @@
type rawImage image
raw := rawImage{}
- if err := unmarshal(&raw); err != nil {
+ if err = unmarshal(&raw); err != nil {
return err
}
--- a/loaders/codebuild/loader.go Mon Feb 19 00:14:29 2018 -0600
+++ b/loaders/codebuild/loader.go Mon Feb 19 00:43:38 2018 -0600
@@ -32,6 +32,7 @@
"bitbucket.org/rw_grim/convey/tasks"
)
+// Loader defines an AWS CodeBuild configuration.
type Loader struct {
region string
image string
@@ -62,24 +63,7 @@
return nil
}
-// Need more input to figure out how this works.
-// func (l *Loader) loadDefaultEnvironment() []string {
-// return []string{
-// "AWS_DEFAULT_REGION=",
-// "AWS_REGION=" + l.region,
-// "CODEBUILD_BUILD_ARN=",
-// "CODEBUILD_BUILD_ID=",
-// "CODEBUILD_BUILD_IMAGE=" + l.image,
-// "CODEBUILD_BUILD_SUCCEEDING=1", // hard coded for now 1 for succeeding, 0 for failing
-// "CODEBUILD_INITIATOR=convey",
-// "CODEBUILD_KMS_KEY_ID=",
-// "CODEBUILD_RESOLVED_SOURCE_VERSION=",
-// "CODEBUILD_SOURCE_REPO_URL=",
-// "CODEBUILD_SOURCE_VERSION=",
-// "CODEBUILD_SRC_DIR=",
-// }
-// }
-
+// Load loads an AWS CodeBuild buildspec.yml.
func (l *Loader) Load(path, base string, data []byte, options []string, disableDeprecated bool) (*config.Config, error) {
err := l.loadOptions(options)
if err != nil {
@@ -201,21 +185,27 @@
plan.Stages = append(plan.Stages, exportStage)
}
+// LoadOverride just satisfies the Loader interface an is not implemented.
func (l *Loader) LoadOverride(path, base string, data []byte, config *config.Config, disableDeprecated bool) {
}
+// Filenames returns the filenames defining AWS CodeBuild configurations.
func (l *Loader) Filenames() []string {
return []string{"buildspec.yml"}
}
+// OverrideSuffix just satisfies the Loader interface and is not used.
func (l *Loader) OverrideSuffix() string {
return ""
}
+// DefaultPlan returns the default plan to use when an AWS CodeBuild
+// configuration is loaded.
func (l *Loader) DefaultPlan() string {
return "default"
}
+// ResolvePlanName satisfies the LoaderInterface and returns the default value.
func (l *Loader) ResolvePlanName(plan string, cfg *config.Config, st *state.State) string {
return plan
}
--- a/loaders/codebuild/types.go Mon Feb 19 00:14:29 2018 -0600
+++ b/loaders/codebuild/types.go Mon Feb 19 00:43:38 2018 -0600
@@ -31,6 +31,8 @@
BaseDirectory string `yaml:"base-directory"`
}
+// CodeBuild defines the data structure for the top level AWS CodeBuild
+// configuration.
type CodeBuild struct {
Version string `yaml:"version"`
Environment environment `yaml:"env"`
--- a/loaders/convey/convey.go Mon Feb 19 00:14:29 2018 -0600
+++ b/loaders/convey/convey.go Mon Feb 19 00:43:38 2018 -0600
@@ -150,24 +150,24 @@
}
if cfg.RequiredVersion != "" {
- verRange, err := semver.ParseRange(cfg.RequiredVersion)
- if err != nil {
- return nil, err
+ verRange, nErr := semver.ParseRange(cfg.RequiredVersion)
+ if nErr != nil {
+ return nil, nErr
}
- curVer, err := semver.Make(consts.Version)
- if err != nil {
- return nil, err
+ curVer, nErr := semver.Make(consts.Version)
+ if nErr != nil {
+ return nil, nErr
}
if !verRange(curVer) {
- err := fmt.Errorf(
- "convey version %s required, but %s is in use.",
+ nErr = fmt.Errorf(
+ "convey version %s required, but %s is in use",
cfg.RequiredVersion,
consts.Version,
)
- return nil, err
+ return nil, nErr
}
}
--- a/loaders/convey/tasks.go Mon Feb 19 00:14:29 2018 -0600
+++ b/loaders/convey/tasks.go Mon Feb 19 00:43:38 2018 -0600
@@ -37,10 +37,16 @@
// figure out the engine
if rawEngine != "" {
- logger.Warn("the engine attribute is deprecated and will be removed in a future version. Please update to the new type format as this format will be removed in a future version.")
+ msg := "the engine attribute is deprecated and will be removed in a future version. Please update to the new type format as this format will be removed in a future version."
+ if err := logger.Warn(msg); err != nil {
+ fmt.Printf("error reporting warning: %s\n", err)
+ }
if rawEngine == "intrinsic" {
- logger.Warn("the intrinsic engine is deprecated, using convey instead")
+ msg := "the intrinsic engine is deprecated, using convey instead"
+ if err := logger.Warn(msg); err != nil {
+ fmt.Printf("error reporting warning: %s\n", err)
+ }
rawEngine = "convey"
}
@@ -55,13 +61,10 @@
}
typeName := fmt.Sprintf("%s/%s", legacyEngine, legacyType)
-
- logger.Warnf(
- "converted deprecated task format {engine: '%s', type: '%s'} to type %s. Please update to the new type format as this format will be removed in a future version.",
- rawEngine,
- rawType,
- typeName,
- )
+ msgFmt := "converted deprecated task format {engine: '%s', type: '%s'} to type %s. Please update to the new type format as this format will be removed in a future version."
+ if err := logger.Warnf(msgFmt, rawEngine, rawType, typeName); err != nil {
+ fmt.Printf("error reporting warning: %s\n", err)
+ }
task, ok := cConfig.TasksMap[typeName]
if !ok {