Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Merge d043c09 into f01562d
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ authored Aug 19, 2017
2 parents f01562d + d043c09 commit 0d14273
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
3 changes: 2 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/viper"
"log"
"os"
stderrors "errors"
)

// When initializing this class the following methods must be called:
Expand Down Expand Up @@ -54,7 +55,7 @@ func (c *configuration) ReadConfig(configFilePath string) error {

if !utils.FileExists(configFilePath) {
log.Print("The configuration file could not be found. Skipping")
return errors.Custom("The configuration file could not be found. Skipping")
return stderrors.New("The configuration file could not be found. Skipping")
}

log.Printf("Loading configuration file: %s", configFilePath)
Expand Down
3 changes: 2 additions & 1 deletion pkg/engine/engine_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"capsulecd/pkg/utils"
"fmt"
"github.com/Masterminds/semver"
stderrors "errors"
)

type engineBase struct {
Expand Down Expand Up @@ -96,7 +97,7 @@ func (e *engineBase) BumpVersion(currentVersion string) (string, error) {
case "patch":
return fmt.Sprintf("%d.%d.%d", v.Major(), v.Minor(), v.Patch()+1), nil
default:
return "", errors.Custom("Unknown version bump interval")
return "", stderrors.New("Unknown version bump interval")
}

}
Expand Down
9 changes: 3 additions & 6 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package errors

import (
"errors"
"fmt"
"os"
)

func CheckErr(err error) {
if err != nil {
panic(fmt.Sprintf("ERROR: %s", err))
fmt.Printf("FATAL: %+v\n", err)
os.Exit(1)
}
}

func Custom(args string) error {
return errors.New(args)
}

// Raised when there is an issue with the filesystem for scm checkout
type ScmFilesystemError string

Expand Down
23 changes: 8 additions & 15 deletions pkg/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@ func TestCheckErr_WithoutError(t *testing.T) {
})
}

func TestCheckErr_Error(t *testing.T) {
t.Parallel()

//assert
require.Panics(t, func() {
errors.CheckErr(errors.Custom("This is an error"))
})
}

func TestCustom(t *testing.T) {
t.Parallel()

//assert
require.Implements(t, (*error)(nil), errors.Custom("my error"), "should implement the error interface")
}
//func TestCheckErr_Error(t *testing.T) {
// t.Parallel()
//
// //assert
// require.Panics(t, func() {
// errors.CheckErr(stderrors.New("This is an error"))
// })
//}

func TestErrors(t *testing.T) {
t.Parallel()
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/cmd.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package utils

import (
"capsulecd/pkg/errors"
"fmt"
"github.com/kvz/logstreamer"
"log"
"os"
"os/exec"
"path"
stderrors "errors"
)

//http://craigwickesser.com/2015/02/golang-cmd-with-custom-environment/
Expand Down Expand Up @@ -45,7 +45,7 @@ func CmdExec(cmdName string, cmdArgs []string, workingDir string, environ []stri
if workingDir != "" && path.IsAbs(workingDir) {
cmd.Dir = workingDir
} else if workingDir != "" {
return errors.Custom("Working Directory must be an absolute path")
return stderrors.New("Working Directory must be an absolute path")
}
//cmdReader, err := cmd.StdoutPipe()
//if err != nil {
Expand Down
14 changes: 9 additions & 5 deletions pkg/utils/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"strings"
"time"
stderrors "errors"
)

// Clone a git repo into a local directory.
Expand Down Expand Up @@ -222,11 +223,14 @@ func GitTag(repoPath string, version string) (string, error) {
return "", lerr
}

//TODO: this should be a annotated tag.
//tagId, terr := repo.Tags.CreateLightweight(version, commit, false) //TODO: this should be an annotated tag.

//tagId, terr := repo.Tags.CreateLightweight(version, commit, false)
tagId, terr := repo.Tags.Create(version, commit, gitSignature(), fmt.Sprintf("(%s) Automated packaging of release by CapsuleCD", version))
return tagId.String(), terr
if terr != nil {
return "", terr;
}

tagObj, terr := repo.LookupTag(tagId)
return tagObj.TargetId().String(), terr
}

func GitPush(repoPath string, localBranch string, remoteBranch string, tagName string) error {
Expand Down Expand Up @@ -414,7 +418,7 @@ func getGitIgnore(languageName string) ([]byte, error) {
defer resp.Body.Close()

if resp.StatusCode != 200 {
return nil, errors.Custom(fmt.Sprintf("Could not find .gitignore for '%s'", languageName))
return nil, stderrors.New(fmt.Sprintf("Could not find .gitignore for '%s'", languageName))
}

return ioutil.ReadAll(resp.Body)
Expand Down

0 comments on commit 0d14273

Please sign in to comment.