diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..0385e3430 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true diff --git a/api/rest/client.go b/api/rest/client.go index f056be12a..219363301 100644 --- a/api/rest/client.go +++ b/api/rest/client.go @@ -22,9 +22,9 @@ type Client struct { client *http.Client } -func New(BaseURL *url.URL, token string, httpClient *http.Client) *Client { +func New(baseURL *url.URL, token string, httpClient *http.Client) *Client { return &Client{ - BaseURL: BaseURL, + BaseURL: baseURL, circleToken: token, client: httpClient, } @@ -37,13 +37,13 @@ func NewFromConfig(host string, config *settings.Config) *Client { endpoint += "/" } - BaseURL, _ := url.Parse(host) + baseURL, _ := url.Parse(host) client := config.HTTPClient client.Timeout = 10 * time.Second return New( - BaseURL.ResolveReference(&url.URL{Path: endpoint}), + baseURL.ResolveReference(&url.URL{Path: endpoint}), config.Token, client, ) diff --git a/cmd/config.go b/cmd/config.go index 85387c89c..d2afbef52 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -84,12 +84,15 @@ func newConfigCommand(globalConfig *settings.Config) *cobra.Command { pipelineParamsFilePath, _ := cmd.Flags().GetString("pipeline-parameters") orgID, _ := cmd.Flags().GetString("org-id") orgSlug, _ := cmd.Flags().GetString("org-slug") - configPath := config.DefaultConfigPath - if len(args) >= 1 { - configPath = args[0] + path := config.DefaultConfigPath + if configPath != "" { + path = configPath + } + if len(args) == 1 { + path = args[0] } return compiler.ProcessConfig(config.ProcessConfigOpts{ - ConfigPath: configPath, + ConfigPath: path, OrgID: orgID, OrgSlug: orgSlug, PipelineParamsFilePath: pipelineParamsFilePath, diff --git a/config/commands.go b/config/commands.go index 6dff218dc..2167e6859 100644 --- a/config/commands.go +++ b/config/commands.go @@ -111,8 +111,6 @@ type ValidateConfigOpts struct { VerboseOutput bool } -// func determineConfigPath(configPath string) - // The arg is actually optional, in order to support compatibility with the --path flag. func (c *ConfigCompiler) ValidateConfig(opts ValidateConfigOpts) error { var err error diff --git a/config/commands_test.go b/config/commands_test.go index 0588f6d4b..dc6e7a16a 100644 --- a/config/commands_test.go +++ b/config/commands_test.go @@ -50,7 +50,7 @@ func TestGetOrgID(t *testing.T) { } -var testYaml = `version: 2.1\n\norbs:\n node: circleci/node@5.0.3\n\njobs:\n datadog-hello-world:\n docker:\n - image: cimg/base:stable\n steps:\n - run: |\n echo \"doing something really cool\"\nworkflows:\n datadog-hello-world:\n jobs:\n - datadog-hello-world` +var testYaml = `version: 2.1\n\norbs:\n node: circleci/node@5.0.3\n\njobs:\n datadog-hello-world:\n docker:\n - image: cimg/base:stable\n steps:\n - run: |\n echo \"doing something really cool\"\nworkflows:\n datadog-hello-world:\n jobs:\n - datadog-hello-world\n` func TestValidateConfig(t *testing.T) { t.Run("validate config works as expected", func(t *testing.T) { diff --git a/config/config.go b/config/config.go index d65e58dc0..7d17b75e5 100644 --- a/config/config.go +++ b/config/config.go @@ -121,7 +121,6 @@ func (c *ConfigCompiler) ConfigQuery( return configCompilationResp, nil } -// #nosec func loadYaml(path string) (string, error) { var err error var config []byte diff --git a/config/config_test.go b/config/config_test.go index d78cb8252..deeba3c00 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -106,7 +106,7 @@ func TestCompiler(t *testing.T) { err = json.Unmarshal(reqBody, &req) assert.NoError(t, err) assert.Equal(t, "1234", req.Options.OwnerID) - assert.Equal(t, "test: test", req.ConfigYaml) + assert.Equal(t, "test: test\n", req.ConfigYaml) fmt.Fprintf(w, `{"valid":true,"source-yaml":"source","output-yaml":"output","errors":[]}`) })) defer svr.Close() @@ -125,7 +125,8 @@ func TestCompiler(t *testing.T) { func TestLoadYaml(t *testing.T) { t.Run("tests load yaml", func(t *testing.T) { - expected := `test: test` + expected := `test: test +` actual, err := loadYaml("testdata/test.yml") assert.NoError(t, err) assert.Equal(t, expected, actual) diff --git a/config/testdata/config-no-orb.yml b/config/testdata/config-no-orb.yml index 0832df3e7..35f2573f2 100644 --- a/config/testdata/config-no-orb.yml +++ b/config/testdata/config-no-orb.yml @@ -10,4 +10,4 @@ jobs: workflows: datadog-hello-world: jobs: - - datadog-hello-world \ No newline at end of file + - datadog-hello-world diff --git a/config/testdata/config.yml b/config/testdata/config.yml index 84c85b42a..d5f89b865 100644 --- a/config/testdata/config.yml +++ b/config/testdata/config.yml @@ -13,4 +13,4 @@ jobs: workflows: datadog-hello-world: jobs: - - datadog-hello-world \ No newline at end of file + - datadog-hello-world diff --git a/config/testdata/test.yml b/config/testdata/test.yml index b8d503804..e5239010e 100644 --- a/config/testdata/test.yml +++ b/config/testdata/test.yml @@ -1 +1 @@ -test: test \ No newline at end of file +test: test