diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 00000000..9e0ae72b --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,20 @@ +--- +engines: + golint: + enabled: true + checks: + GoLint/Naming/MixedCaps: + enabled: false + govet: + enabled: true + gofmt: + enabled: true + fixme: + enabled: true +ratings: + paths: + - "**.go" +exclude_paths: + - "**/*_test.go" + - "*_test.go" + - "vendor/" diff --git a/env/ci.go b/env/ci.go index 13ee24cc..ba5cb820 100644 --- a/env/ci.go +++ b/env/ci.go @@ -2,13 +2,13 @@ package env import "bytes" -type CI struct { +type ci struct { Name string BuildID string BuildURL string } -func (c CI) String() string { +func (c ci) String() string { out := &bytes.Buffer{} out.WriteString("CI_NAME=") out.WriteString(c.Name) @@ -19,8 +19,8 @@ func (c CI) String() string { return out.String() } -func loadCIInfo() CI { - return CI{ +func loadCIInfo() ci { + return ci{ Name: findVar(ciNameVars), BuildID: findVar(ciBuildIDVars), BuildURL: findVar(ciBuildURLVars), diff --git a/env/ci_test.go b/env/ci_test.go index a8f7686d..8360cb4e 100644 --- a/env/ci_test.go +++ b/env/ci_test.go @@ -35,7 +35,7 @@ func Test_loadCIFromENV_Alt_Vars(t *testing.T) { func Test_CI_String(t *testing.T) { r := require.New(t) - c := CI{ + c := ci{ Name: "codeclimate", BuildID: "a12345", BuildURL: "http://example.net", diff --git a/env/env.go b/env/env.go index 2ae3911a..a5a5d931 100644 --- a/env/env.go +++ b/env/env.go @@ -6,9 +6,10 @@ import ( "github.com/gobuffalo/envy" ) +// Environment represent the current testing environment type Environment struct { - Git Git - CI CI + Git git + CI ci } func (e Environment) String() string { @@ -19,9 +20,14 @@ func (e Environment) String() string { return out.String() } +// New environment. If there are problems loading parts of +// the environment an error will be returned. Validation errors +// are not considered an "error" here, but should be checked +// further down the chain, when validation of the environment +// is required. func New() (Environment, error) { e := Environment{} - git, err := FindGitInfo() + git, err := findGitInfo() if err != nil { return e, err } diff --git a/env/git.go b/env/git.go index 4359906b..008bb740 100644 --- a/env/git.go +++ b/env/git.go @@ -6,13 +6,13 @@ import ( "strings" ) -type Git struct { +type git struct { Branch string CommitSHA string CommittedAt string } -func (g Git) String() string { +func (g git) String() string { out := &bytes.Buffer{} out.WriteString("GIT_BRANCH=") out.WriteString(g.Branch) @@ -23,14 +23,14 @@ func (g Git) String() string { return out.String() } -func FindGitInfo() (Git, error) { +func findGitInfo() (git, error) { _, err := exec.LookPath("git") if err != nil { // git isn't present, so load from ENV vars: return loadGitFromENV() } - g := Git{} + g := git{} cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") out, err := cmd.Output() @@ -55,9 +55,8 @@ func FindGitInfo() (Git, error) { return g, nil } -func loadGitFromENV() (Git, error) { - // TODO: find via other variables: - return Git{ +func loadGitFromENV() (git, error) { + return git{ Branch: findVar(gitBranchVars), CommitSHA: findVar(gitCommitShaVars), CommittedAt: findVar(gitCommittedAtVars), diff --git a/env/git_test.go b/env/git_test.go index c62c50f6..5d60d842 100644 --- a/env/git_test.go +++ b/env/git_test.go @@ -9,7 +9,7 @@ import ( func Test_FindGitInfo(t *testing.T) { r := require.New(t) - g, err := FindGitInfo() + g, err := findGitInfo() r.NoError(err) r.NotZero(g.Branch) r.NotZero(g.CommitSHA) @@ -46,7 +46,7 @@ func Test_loadGitFromENV_Alt_Vars(t *testing.T) { func Test_Git_String(t *testing.T) { r := require.New(t) - g := Git{ + g := git{ Branch: "master", CommitSHA: "a12345", CommittedAt: "12:45",