Skip to content

Commit

Permalink
close #54 add the ability to run a test during deliver
Browse files Browse the repository at this point in the history
  • Loading branch information
groenborg committed Mar 15, 2017
1 parent e5c3251 commit 11a0386
Show file tree
Hide file tree
Showing 24 changed files with 311 additions and 148 deletions.
11 changes: 7 additions & 4 deletions ci/notes/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ prefixed with 'delivered'.

Agent commands have now been added. So the extension can be used by integration services.


Features
- agent commands
- updated documentation
- agent commands @groenborg
- updated documentation @groenborg
- clean #60 (remove delivered branches from workspace) @groenborg
- colored output #41 (messages are now more informative and pretty) @groenborg
- deliver with tests #54 @groenborg
- flag (s) for showing test output


Agent Features
- upnext #55 (get next branch for integration) @groenborg
- integrate #55 (deliver in an agent version) @groenborg
- deliver #55 (deliver in an agent version) @groenborg
1 change: 1 addition & 0 deletions cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
//"fmt"

"fmt"

"github.com/praqma/git-phlow/options"
"github.com/spf13/cobra"
)
Expand Down
1 change: 1 addition & 0 deletions cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/praqma/git-phlow/githandler"
"github.com/praqma/git-phlow/options"
"github.com/praqma/git-phlow/phlow"
Expand Down
33 changes: 26 additions & 7 deletions cmd/deliver.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package cmd

import (
"fmt"
"os"

"github.com/praqma/git-phlow/options"
"github.com/praqma/git-phlow/phlow"
"github.com/praqma/git-phlow/plugins"
"github.com/spf13/cobra"
)

// deliverCmd represents the deliver command
var deliverCmd = &cobra.Command{
Use: "deliver",
Use: "deliver [test args]",
Short: "deliver changes to remote master",
Long: `
[deliver] fetches the latest changes and tries to push the committed changes
Expand All @@ -17,18 +21,32 @@ created with workon, or a branch which if not your default (typically master).
the delivered branch will prefix the branchname with "ready/",
so integration services supporting the workflow can pick up the changes.
--local - if you deliver with local, the branch will be merged
with your default branch and pushed to your "remote default branch"
and prefixed with "/delivered"
if you deliver with local, the branch will be merged with your default branch,
and pushed to your "remote default branch" and prefixed with "/delivered"
`,
Run: func(cmd *cobra.Command, args []string) {

defaultBranch, _ := plugins.GetDefaultBranch(plugins.RepoURL)

//Run tests before deliver
if len(args) > 0 {
if err := phlow.TestDeliver(args); err != nil {
fmt.Println(options.ErrorFormat("!! Tests did not exit with code 0 !!"))
fmt.Println(err)
os.Exit(1)
}
fmt.Println(options.SuccessFormat("Tests exited with code 0 - starting deliver process"))
}

//If Run if local deliver
if options.GlobalFlagLocal {
phlow.LocalDeliver()
} else {
phlow.Deliver()
phlow.LocalDeliver(defaultBranch)
return
}

//Deliver with ready branch
phlow.Deliver(defaultBranch)

},
}

Expand All @@ -37,4 +55,5 @@ func init() {

//Flag for local deliver
deliverCmd.Flags().BoolVarP(&options.GlobalFlagLocal, "local", "l", false, "local delivery")
deliverCmd.Flags().BoolVarP(&options.GlobalFlagShowTestOutput, "showtest", "s", false, "show test output")
}
6 changes: 4 additions & 2 deletions cmd/integrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import (

"github.com/praqma/git-phlow/options"
"github.com/praqma/git-phlow/phlow"
"github.com/praqma/git-phlow/plugins"
"github.com/spf13/cobra"
)

// integrateCmd represents the integrate command
var integrateCmd = &cobra.Command{
Use: "integrate",
Use: "deliver",
Short: "deliver work in agent version",
Long: fmt.Sprintf(`
%s delivers the changes in an agent version. The current branch if will be merged into the default branch
with your default branch and pushed to the remote.
`, options.Bold("integrate")),
Run: func(cmd *cobra.Command, args []string) {

phlow.LocalDeliver()
defaultBranch, _ := plugins.GetDefaultBranch(plugins.RepoURL)
phlow.LocalDeliver(defaultBranch)
},
}

Expand Down
1 change: 1 addition & 0 deletions cmd/mkalias.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/praqma/git-phlow/options"
"github.com/praqma/git-phlow/phlow"
"github.com/spf13/cobra"
Expand Down
5 changes: 3 additions & 2 deletions cmd/workon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"fmt"
"os"
"strconv"

"github.com/praqma/git-phlow/options"
"github.com/praqma/git-phlow/phlow"
"github.com/spf13/cobra"
"os"
"strconv"
)

// workonCmd represents the workon command
Expand Down
1 change: 1 addition & 0 deletions cmd/wrapup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/praqma/git-phlow/options"
"github.com/praqma/git-phlow/phlow"
"github.com/spf13/cobra"
Expand Down
17 changes: 9 additions & 8 deletions githandler/branch.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package githandler

import (
. "github.com/praqma/git-phlow/executor"
"strconv"
"strings"

"github.com/praqma/git-phlow/executor"
)

//BranchInfo ...
Expand All @@ -17,12 +18,12 @@ func Branch() (*BranchInfo, error) {
var err error
info := BranchInfo{}

current, cErr := ExecuteCommand("git", "rev-parse", "--abbrev-ref", "HEAD")
current, cErr := executor.ExecuteCommand("git", "rev-parse", "--abbrev-ref", "HEAD")
if cErr != nil {
return nil, err
}

output, lErr := ExecuteCommand("git", "branch", "-a")
output, lErr := executor.ExecuteCommand("git", "branch", "-a")
if lErr != nil {
return nil, err
}
Expand All @@ -40,20 +41,20 @@ func Branch() (*BranchInfo, error) {

//BranchRename ...
func BranchRename(name string) error {
_, err := ExecuteCommand("git", "branch", "-m", name, "delivered/"+name)
_, err := executor.ExecuteCommand("git", "branch", "-m", name, "delivered/"+name)
return err
}

//BranchDelete ...
func BranchDelete(name, remote string, deleteRemote, force bool) (string, error) {
if deleteRemote {
return ExecuteCommand("git", "push", remote, "--delete", name)
return executor.ExecuteCommand("git", "push", remote, "--delete", name)
}

if force {
return ExecuteCommand("git", "branch", "-D", name)
return executor.ExecuteCommand("git", "branch", "-D", name)
}
return ExecuteCommand("git", "branch", "-d", name)
return executor.ExecuteCommand("git", "branch", "-d", name)
}

//BranchDelivered ...
Expand Down Expand Up @@ -94,7 +95,7 @@ func BranchReady(remote string) (remoteBranches []string) {

//BranchTime ...
func BranchTime(name string) (int, error) {
output, err := ExecuteCommand("git", "log", "-n 1", name, "--format=format:%ct")
output, err := executor.ExecuteCommand("git", "log", "-n 1", name, "--format=format:%ct")
if err != nil {
return -1, err
}
Expand Down
3 changes: 2 additions & 1 deletion githandler/branch_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package githandler

import (
"testing"

"github.com/praqma/git-phlow/testfixture"
. "github.com/smartystreets/goconvey/convey"
"testing"
)

func TestBranch(t *testing.T) {
Expand Down
34 changes: 17 additions & 17 deletions githandler/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,93 @@ import (
"regexp"
"strings"

. "github.com/praqma/git-phlow/executor"
"github.com/praqma/git-phlow/executor"
)

//ConfigBranchRemote ...
func ConfigBranchRemote(branch string) string {
configArg := fmt.Sprintf("branch.%s.remote", branch)
output, _ := ExecuteCommand("git", "config", configArg)
output, _ := executor.ExecuteCommand("git", "config", configArg)
return strings.Replace(output, "\n", "", -1)
}

//ConfigGet ...
func ConfigGet(key, group string) string {
pair := fmt.Sprintf("%s.%s", group, key)
output, _ := ExecuteCommand("git", "config", "--global", "--get", pair)
output, _ := executor.ExecuteCommand("git", "config", "--global", "--get", pair)
return strings.Replace(output, "\n", "", -1)
}

//ConfigSet ...
func ConfigSet(key, value, group string) error {
pair := fmt.Sprintf("%s.%s", group, key)
_, err := ExecuteCommand("git", "config", "--global", pair, value)
_, err := executor.ExecuteCommand("git", "config", "--global", pair, value)
return err
}

//CheckOut ...
func CheckOut(branch string) error {
_, err := ExecuteCommand("git", "checkout", branch)
_, err := executor.ExecuteCommand("git", "checkout", branch)
return err
}

//CheckoutNewBranchFromRemote ...
func CheckoutNewBranchFromRemote(branch, defaultBranch string) error {
remote := ConfigBranchRemote(defaultBranch)
_, err := ExecuteCommand("git", "checkout", "-b", branch, remote+"/"+defaultBranch)
_, err := executor.ExecuteCommand("git", "checkout", "-b", branch, remote+"/"+defaultBranch)
return err
}

//Status ...
func Status() error {
_, err := ExecuteCommand("git", "status")
_, err := executor.ExecuteCommand("git", "status")
return err
}

//Add ...
func Add() error {
_, err := ExecuteCommand("git", "add", "--all")
_, err := executor.ExecuteCommand("git", "add", "--all")
return err
}

//Commit ...
func Commit(message string) (string, error) {
return ExecuteCommand("git", "commit", "-m", message)
return executor.ExecuteCommand("git", "commit", "-m", message)
}

//Fetch ...
func Fetch() error {
_, err := ExecuteCommand("git", "fetch", "--all")
_, err := executor.ExecuteCommand("git", "fetch", "--all")
return err
}

//FetchPrune ...
func FetchPrune() error {
_, err := ExecuteCommand("git", "fetch", "--prune")
_, err := executor.ExecuteCommand("git", "fetch", "--prune")
return err
}

//Pull ...
func Pull() (string, error) {
return ExecuteCommand("git", "pull", "--rebase")
return executor.ExecuteCommand("git", "pull", "--rebase")
}

//Push ...
func Push() (string, error) {
return ExecuteCommand("git", "push")
return executor.ExecuteCommand("git", "push")
}

//PushRename ...
func PushRename(branch, defaultBranch string) (string, error) {
remote := ConfigBranchRemote(defaultBranch)
str := fmt.Sprintf("%s:ready/%s", branch, branch)

return ExecuteCommand("git", "push", remote, str)
return executor.ExecuteCommand("git", "push", remote, str)
}

//Merge ...
func Merge(branch string) error {
_, err := ExecuteCommand("git", "merge", branch)
_, err := executor.ExecuteCommand("git", "merge", branch)
return err
}

Expand All @@ -107,11 +107,11 @@ func Remote(defaultBranch string) (*RemoteInfo, error) {
var res string
var err error

if res, err = ExecuteCommand("git", "config", fmt.Sprintf("branch.%s.remote", defaultBranch)); err != nil {
if res, err = executor.ExecuteCommand("git", "config", fmt.Sprintf("branch.%s.remote", defaultBranch)); err != nil {
return nil, err
}
res = strings.Trim(res, "\n")
if res, err = ExecuteCommand("git", "config", "--get", fmt.Sprintf("remote.%s.url", res)); err != nil {
if res, err = executor.ExecuteCommand("git", "config", "--get", fmt.Sprintf("remote.%s.url", res)); err != nil {
return nil, err
}
res = strings.Trim(res, "\n")
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ import (

func main() {
cmd.Execute()
//s := spinner.New(spinner.CharSets[9], 60*time.Millisecond) // Build our new spinner
//s.Prefix = "prefixed text: " // Prefix text before the spinner
//s.Suffix = " pushing" // Append text after the spinner
//
//s.Start() // Start the spinner
//time.Sleep(4 * time.Second) // Run for some time to simulate work
//s.Stop()

}
3 changes: 3 additions & 0 deletions options/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ var (
//GlobalFlagForce ...
GlobalFlagForce = false

//GlobalFlagShowTestOutput ...
GlobalFlagShowTestOutput bool

//GlobalFlagHumanReadable ...
GlobalFlagHumanReadable bool

Expand Down
10 changes: 10 additions & 0 deletions options/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ func Bold(message string) string {
return color.New(color.Bold).SprintFunc()(message)
}

//SuccessFormat ...
func SuccessFormat(err string) string {
return color.New(color.FgHiGreen).SprintFunc()(err)
}

//ErrorFormat ...
func ErrorFormat(err string) string {
return color.New(color.FgHiRed).SprintFunc()(err)
}

//LabelFormat ...
func LabelFormat(message string) string {
return color.New(color.FgBlack).Add(color.Bold).Add(color.BgHiWhite).SprintFunc()(message)
Expand Down
Loading

0 comments on commit 11a0386

Please sign in to comment.