Skip to content

Commit

Permalink
Adds an editorconfig file to the repo to ensure that all files have n…
Browse files Browse the repository at this point in the history
…ewline characters
  • Loading branch information
elliotforbes committed Mar 27, 2023
1 parent 62deb45 commit 670cd2d
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 17 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions api/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
)
Expand Down
11 changes: 7 additions & 4 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions config/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ type ValidateConfigOpts struct {
VerboseOutput bool
}

// func determineConfigPath(configPath string)

// The <path> arg is actually optional, in order to support compatibility with the --path flag.
func (c *ConfigCompiler) ValidateConfig(opts ValidateConfigOpts) error {
var err error
Expand Down
2 changes: 1 addition & 1 deletion config/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestGetOrgID(t *testing.T) {

}

var testYaml = `version: 2.1\n\norbs:\n node: circleci/[email protected]\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/[email protected]\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) {
Expand Down
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func (c *ConfigCompiler) ConfigQuery(
return configCompilationResp, nil
}

// #nosec
func loadYaml(path string) (string, error) {
var err error
var config []byte
Expand Down
5 changes: 3 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion config/testdata/config-no-orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
workflows:
datadog-hello-world:
jobs:
- datadog-hello-world
- datadog-hello-world
2 changes: 1 addition & 1 deletion config/testdata/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
workflows:
datadog-hello-world:
jobs:
- datadog-hello-world
- datadog-hello-world
2 changes: 1 addition & 1 deletion config/testdata/test.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test: test
test: test

0 comments on commit 670cd2d

Please sign in to comment.