Skip to content

Commit

Permalink
made git and ci private.
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Mar 3, 2017
1 parent bb2dee3 commit 5d5f781
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
20 changes: 20 additions & 0 deletions .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/"
8 changes: 4 additions & 4 deletions env/ci.go
Expand Up @@ -2,13 +2,13 @@ package env


import "bytes" import "bytes"


type CI struct { type ci struct {
Name string Name string
BuildID string BuildID string
BuildURL string BuildURL string
} }


func (c CI) String() string { func (c ci) String() string {
out := &bytes.Buffer{} out := &bytes.Buffer{}
out.WriteString("CI_NAME=") out.WriteString("CI_NAME=")
out.WriteString(c.Name) out.WriteString(c.Name)
Expand All @@ -19,8 +19,8 @@ func (c CI) String() string {
return out.String() return out.String()
} }


func loadCIInfo() CI { func loadCIInfo() ci {
return CI{ return ci{
Name: findVar(ciNameVars), Name: findVar(ciNameVars),
BuildID: findVar(ciBuildIDVars), BuildID: findVar(ciBuildIDVars),
BuildURL: findVar(ciBuildURLVars), BuildURL: findVar(ciBuildURLVars),
Expand Down
2 changes: 1 addition & 1 deletion env/ci_test.go
Expand Up @@ -35,7 +35,7 @@ func Test_loadCIFromENV_Alt_Vars(t *testing.T) {


func Test_CI_String(t *testing.T) { func Test_CI_String(t *testing.T) {
r := require.New(t) r := require.New(t)
c := CI{ c := ci{
Name: "codeclimate", Name: "codeclimate",
BuildID: "a12345", BuildID: "a12345",
BuildURL: "http://example.net", BuildURL: "http://example.net",
Expand Down
12 changes: 9 additions & 3 deletions env/env.go
Expand Up @@ -6,9 +6,10 @@ import (
"github.com/gobuffalo/envy" "github.com/gobuffalo/envy"
) )


// Environment represent the current testing environment
type Environment struct { type Environment struct {
Git Git Git git
CI CI CI ci
} }


func (e Environment) String() string { func (e Environment) String() string {
Expand All @@ -19,9 +20,14 @@ func (e Environment) String() string {
return out.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) { func New() (Environment, error) {
e := Environment{} e := Environment{}
git, err := FindGitInfo() git, err := findGitInfo()
if err != nil { if err != nil {
return e, err return e, err
} }
Expand Down
13 changes: 6 additions & 7 deletions env/git.go
Expand Up @@ -6,13 +6,13 @@ import (
"strings" "strings"
) )


type Git struct { type git struct {
Branch string Branch string
CommitSHA string CommitSHA string
CommittedAt string CommittedAt string
} }


func (g Git) String() string { func (g git) String() string {
out := &bytes.Buffer{} out := &bytes.Buffer{}
out.WriteString("GIT_BRANCH=") out.WriteString("GIT_BRANCH=")
out.WriteString(g.Branch) out.WriteString(g.Branch)
Expand All @@ -23,14 +23,14 @@ func (g Git) String() string {
return out.String() return out.String()
} }


func FindGitInfo() (Git, error) { func findGitInfo() (git, error) {
_, err := exec.LookPath("git") _, err := exec.LookPath("git")
if err != nil { if err != nil {
// git isn't present, so load from ENV vars: // git isn't present, so load from ENV vars:
return loadGitFromENV() return loadGitFromENV()
} }


g := Git{} g := git{}


cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
out, err := cmd.Output() out, err := cmd.Output()
Expand All @@ -55,9 +55,8 @@ func FindGitInfo() (Git, error) {
return g, nil return g, nil
} }


func loadGitFromENV() (Git, error) { func loadGitFromENV() (git, error) {
// TODO: find via other variables: return git{
return Git{
Branch: findVar(gitBranchVars), Branch: findVar(gitBranchVars),
CommitSHA: findVar(gitCommitShaVars), CommitSHA: findVar(gitCommitShaVars),
CommittedAt: findVar(gitCommittedAtVars), CommittedAt: findVar(gitCommittedAtVars),
Expand Down
4 changes: 2 additions & 2 deletions env/git_test.go
Expand Up @@ -9,7 +9,7 @@ import (


func Test_FindGitInfo(t *testing.T) { func Test_FindGitInfo(t *testing.T) {
r := require.New(t) r := require.New(t)
g, err := FindGitInfo() g, err := findGitInfo()
r.NoError(err) r.NoError(err)
r.NotZero(g.Branch) r.NotZero(g.Branch)
r.NotZero(g.CommitSHA) r.NotZero(g.CommitSHA)
Expand Down Expand Up @@ -46,7 +46,7 @@ func Test_loadGitFromENV_Alt_Vars(t *testing.T) {


func Test_Git_String(t *testing.T) { func Test_Git_String(t *testing.T) {
r := require.New(t) r := require.New(t)
g := Git{ g := git{
Branch: "master", Branch: "master",
CommitSHA: "a12345", CommitSHA: "a12345",
CommittedAt: "12:45", CommittedAt: "12:45",
Expand Down

0 comments on commit 5d5f781

Please sign in to comment.