Skip to content

Commit

Permalink
Merge pull request #12 from MolotovTv/feat-refact
Browse files Browse the repository at this point in the history
Refact
  • Loading branch information
ericrenard authored Nov 13, 2019
2 parents 2a1f7aa + 322f3fe commit 10b0546
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 160 deletions.
6 changes: 2 additions & 4 deletions cmd/last_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"log"

"github.com/molotovtv/tc/tc"

"github.com/molotovtv/tc/internal/config"
"github.com/spf13/cobra"
)

Expand All @@ -22,12 +20,12 @@ var lastBuildCmd = &cobra.Command{
env := args[0]
fmt.Println("Env:", env)

c, err := config.Load()
c, err := tc.LoadConfig()
if err != nil {
log.Fatal(err)
}

buildTypeID, err := config.BuildTypeID(env)
buildTypeID, err := c.BuildTypeID(env)
if err != nil {
log.Fatal(err)
}
Expand Down
45 changes: 45 additions & 0 deletions cmd/last_successful_build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cmd

import (
"fmt"
"log"

"github.com/molotovtv/tc/tc"
"github.com/spf13/cobra"
)

func init() {
RootCmd.AddCommand(buildsCmd)
}

var buildsCmd = &cobra.Command{
Use: "last-build-success",
Short: "Get successful builds by branch",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 2 {
fmt.Printf("builds-success [env] [branch]\n")
return
}
env := args[0]
branch := args[1]
fmt.Printf("Env:%s ; Branch:%s\n", env, branch)

c, err := tc.LoadConfig()
if err != nil {
log.Fatal(err)
}

buildTypeID, err := c.BuildTypeID(env)
if err != nil {
log.Fatal(err)
}

res, err := tc.LastBuildSuccessByBranch(c, buildTypeID, branch)
if err != nil {
log.Fatal(err)
}

fmt.Printf("%+v\n", res)
},
}
6 changes: 3 additions & 3 deletions cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"log"

"github.com/molotovtv/tc/internal/config"
"github.com/molotovtv/tc/tc"
"github.com/skratchdot/open-golang/open"
"github.com/spf13/cobra"
)
Expand All @@ -18,11 +18,11 @@ var openCmd = &cobra.Command{
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
env := args[0]
c, err := config.Load()
c, err := tc.LoadConfig()
if err != nil {
log.Fatal(err)
}
buildTypeID, err := config.BuildTypeID(env)
buildTypeID, err := c.BuildTypeID(env)
if err != nil {
log.Fatal(err)
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"strconv"

"github.com/fatih/color"
"github.com/molotovtv/tc/internal/config"
"github.com/molotovtv/tc/internal/git"
"github.com/molotovtv/tc/git"
"github.com/molotovtv/tc/tc"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -131,11 +130,11 @@ var pkgCmd = &cobra.Command{
log.Fatalf("tag %s does not validate, tags for packaging must be vx.y.z", tag)
return
}
c, err := config.Load()
c, err := tc.LoadConfig()
if err != nil {
log.Fatalf("%+v", err)
}
buildTypeID, err := config.BuildTypeID("packaging")
buildTypeID, err := c.BuildTypeID("packaging")
if err != nil {
log.Fatalf("%+v", err)
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/fatih/color"
"github.com/molotovtv/tc/tc"

"github.com/molotovtv/tc/internal/config"
"github.com/molotovtv/tc/internal/git"
"github.com/molotovtv/tc/git"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -71,12 +70,12 @@ var runCmd = &cobra.Command{
branch = tag
}

c, err := config.Load()
c, err := tc.LoadConfig()
if err != nil {
log.Fatalf("%+v", err)
}

buildTypeID, err := config.BuildTypeID(env)
buildTypeID, err := c.BuildTypeID(env)
if err != nil {
log.Fatalf("%+v", err)
}
Expand Down
23 changes: 0 additions & 23 deletions cmd/set_build.go

This file was deleted.

8 changes: 4 additions & 4 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/cheggaaa/pb"
"github.com/fatih/color"
"github.com/molotovtv/tc/internal/config"
"github.com/molotovtv/tc/tc"
"github.com/spf13/cobra"
)
Expand All @@ -28,12 +27,12 @@ var statusCmd = &cobra.Command{
env := args[0]
fmt.Println("Env:", env)

c, err := config.Load()
c, err := tc.LoadConfig()
if err != nil {
log.Fatal(err)
}

buildTypeID, err := config.BuildTypeID(env)
buildTypeID, err := c.BuildTypeID(env)
if err != nil {
log.Fatal(err)
}
Expand All @@ -46,7 +45,7 @@ var statusCmd = &cobra.Command{
},
}

func buildStatus(c config.Config, buildID int) {
func buildStatus(c tc.Config, buildID int) {
bar := pb.StartNew(100)
var build tc.DetailedBuild
signalChan := make(chan os.Signal, 1)
Expand Down Expand Up @@ -82,6 +81,7 @@ L:
return
}
if build.Status != tc.BuildStatusSuccess {
color.Magenta("%+v", build)
color.Red("Build failed!")
return
}
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ require (
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.27 // indirect
)

go 1.13
49 changes: 0 additions & 49 deletions internal/config/global.go

This file was deleted.

62 changes: 0 additions & 62 deletions internal/config/local.go

This file was deleted.

Loading

0 comments on commit 10b0546

Please sign in to comment.