Permalink
Browse files

made git and ci private.

  • Loading branch information...
markbates committed Mar 3, 2017
1 parent bb2dee3 commit 5d5f7817d79cbf909cd800acedd6ec7e5fd1233a
Showing with 42 additions and 17 deletions.
  1. +20 −0 .codeclimate.yml
  2. +4 −4 env/ci.go
  3. +1 −1 env/ci_test.go
  4. +9 −3 env/env.go
  5. +6 −7 env/git.go
  6. +2 −2 env/git_test.go
@@ -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/"
@@ -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),
@@ -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",
@@ -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
}
@@ -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),
@@ -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",

0 comments on commit 5d5f781

Please sign in to comment.