diff --git a/ci/notes/release-notes.md b/ci/notes/release-notes.md index 59a126e..87c6d6b 100644 --- a/ci/notes/release-notes.md +++ b/ci/notes/release-notes.md @@ -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 \ No newline at end of file + - deliver #55 (deliver in an agent version) @groenborg \ No newline at end of file diff --git a/cmd/agent.go b/cmd/agent.go index 8c74658..f06881c 100644 --- a/cmd/agent.go +++ b/cmd/agent.go @@ -4,6 +4,7 @@ import ( //"fmt" "fmt" + "github.com/praqma/git-phlow/options" "github.com/spf13/cobra" ) diff --git a/cmd/clean.go b/cmd/clean.go index 791cf09..2cb91de 100644 --- a/cmd/clean.go +++ b/cmd/clean.go @@ -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" diff --git a/cmd/deliver.go b/cmd/deliver.go index 0d03b30..bdecb04 100644 --- a/cmd/deliver.go +++ b/cmd/deliver.go @@ -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 @@ -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) + }, } @@ -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") } diff --git a/cmd/integrate.go b/cmd/integrate.go index 463e85b..721d19a 100644 --- a/cmd/integrate.go +++ b/cmd/integrate.go @@ -5,12 +5,13 @@ 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 @@ -18,7 +19,8 @@ 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) }, } diff --git a/cmd/mkalias.go b/cmd/mkalias.go index 8088750..5daa650 100644 --- a/cmd/mkalias.go +++ b/cmd/mkalias.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/praqma/git-phlow/options" "github.com/praqma/git-phlow/phlow" "github.com/spf13/cobra" diff --git a/cmd/workon.go b/cmd/workon.go index 73224d0..833382f 100644 --- a/cmd/workon.go +++ b/cmd/workon.go @@ -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 diff --git a/cmd/wrapup.go b/cmd/wrapup.go index d548c4b..5570b58 100644 --- a/cmd/wrapup.go +++ b/cmd/wrapup.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/praqma/git-phlow/options" "github.com/praqma/git-phlow/phlow" "github.com/spf13/cobra" diff --git a/githandler/branch.go b/githandler/branch.go index 6547c95..e2cc5b3 100644 --- a/githandler/branch.go +++ b/githandler/branch.go @@ -1,9 +1,10 @@ package githandler import ( - . "github.com/praqma/git-phlow/executor" "strconv" "strings" + + "github.com/praqma/git-phlow/executor" ) //BranchInfo ... @@ -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 } @@ -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 ... @@ -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 } diff --git a/githandler/branch_test.go b/githandler/branch_test.go index 830e311..6a75dc4 100644 --- a/githandler/branch_test.go +++ b/githandler/branch_test.go @@ -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) { diff --git a/githandler/git.go b/githandler/git.go index cbf1a59..42d0274 100644 --- a/githandler/git.go +++ b/githandler/git.go @@ -5,80 +5,80 @@ 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 ... @@ -86,12 +86,12 @@ 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 } @@ -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") diff --git a/main.go b/main.go index 51d2ec5..68a4e3e 100644 --- a/main.go +++ b/main.go @@ -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() + } diff --git a/options/option.go b/options/option.go index 18a261b..65b55c8 100644 --- a/options/option.go +++ b/options/option.go @@ -17,6 +17,9 @@ var ( //GlobalFlagForce ... GlobalFlagForce = false + //GlobalFlagShowTestOutput ... + GlobalFlagShowTestOutput bool + //GlobalFlagHumanReadable ... GlobalFlagHumanReadable bool diff --git a/options/output.go b/options/output.go index a01bf07..b2199a9 100644 --- a/options/output.go +++ b/options/output.go @@ -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) diff --git a/phlow/clean.go b/phlow/clean.go index 31924f1..0ea9de2 100644 --- a/phlow/clean.go +++ b/phlow/clean.go @@ -2,6 +2,7 @@ package phlow import ( "fmt" + "github.com/praqma/git-phlow/githandler" "github.com/praqma/git-phlow/options" ) diff --git a/phlow/clean_test.go b/phlow/clean_test.go new file mode 100644 index 0000000..553494e --- /dev/null +++ b/phlow/clean_test.go @@ -0,0 +1,42 @@ +package phlow + +import ( + "github.com/praqma/git-phlow/options" + "github.com/praqma/git-phlow/testfixture" + . "github.com/smartystreets/goconvey/convey" + "testing" +) + +func TestClean(t *testing.T) { + + Convey("Runnign tests on 'Clean' function", t, func() { + + testfixture.CreateTestRepository(t, false) + + Convey("Testing output of local clean function", func() { + options.GlobalFlagLocal = true + Clean("origin") + + }) + + testfixture.RemoveTestRepository(t) + }) + +} + +func TestCleanRemote(t *testing.T) { + + Convey("Runnign tests on 'Clean' function", t, func() { + + testfixture.CreateTestRepository(t, false) + + Convey("Testing output of clean function", func() { + options.GlobalFlagLocal = false + Clean("origin") + + }) + + testfixture.RemoveTestRepository(t) + }) + +} diff --git a/phlow/deliver.go b/phlow/deliver.go index 0bc19bb..47ed289 100644 --- a/phlow/deliver.go +++ b/phlow/deliver.go @@ -2,28 +2,26 @@ package phlow import ( "fmt" - "strings" - + "github.com/praqma/git-phlow/executor" "github.com/praqma/git-phlow/githandler" - "github.com/praqma/git-phlow/plugins" "github.com/praqma/git-phlow/options" + "os" + "strings" ) //Deliver ... -func Deliver() { +func Deliver(defaultBranch string) { branchInfo, _ := githandler.Branch() - dfBranch, _ := plugins.GetDefaultBranch(plugins.RepoURL) - githandler.Fetch() //Is branch master or is branch delivered - if strings.HasPrefix(branchInfo.Current, "delivered/") || (branchInfo.Current == dfBranch) { + if strings.HasPrefix(branchInfo.Current, "delivered/") || (branchInfo.Current == defaultBranch) { fmt.Printf("Could not deliver: %s", branchInfo.Current) return } - output, err := githandler.PushRename(branchInfo.Current, dfBranch) + output, err := githandler.PushRename(branchInfo.Current, defaultBranch) if err != nil { fmt.Println(err) return @@ -36,3 +34,77 @@ func Deliver() { } fmt.Printf("Branch %s is now delivered \n", options.BranchFormat(branchInfo.Current)) } + +//LocalDeliver ... +func LocalDeliver(defaultBranch string) { + + branchInfo, _ := githandler.Branch() + + //Is branch master or is branch delivered + if strings.HasPrefix(branchInfo.Current, "delivered/") || (branchInfo.Current == defaultBranch) { + fmt.Printf("You cannot deliver: %s \n", branchInfo.Current) + return + } + + fmt.Fprintf(os.Stdout, "Checking out default branch %s \n", options.BranchFormat(defaultBranch)) + //Checkout default branch: master + if err := githandler.CheckOut(defaultBranch); err != nil { + fmt.Println(err) + return + } + //Pull rebase latest changes + fmt.Fprintln(os.Stdout, "Trying to pull latest changes") + output, err := githandler.Pull() + if err != nil { + fmt.Println(err) + return + } + fmt.Println(output) + + fmt.Fprintf(os.Stdout, "Merging changes from branch %s into branch %s \n", options.BranchFormat(branchInfo.Current), options.BranchFormat(defaultBranch)) + //Merge feature branch into default + if err = githandler.Merge(branchInfo.Current); err != nil { + fmt.Println(err) + } + //Rename default branch to delivered + githandler.BranchRename(branchInfo.Current) + + //Push changes to github + fmt.Fprintf(os.Stdout, "Pushing changes to remote %s \n", options.BranchFormat(defaultBranch)) + output, err = githandler.Push() + if err != nil { + fmt.Println(err.Error()) + return + } + fmt.Fprintln(os.Stdout, output) + fmt.Printf("Branch %s fearlessly delivered to %s \n", options.BranchFormat(branchInfo.Current), options.BranchFormat(defaultBranch)) + +} + +//TestDeliver ... +//Run tests and returns +func TestDeliver(args []string) error { + + cmd, argv := convertCommand(args) + output, err := executor.ExecuteCommand(cmd, argv...) + + if err != nil { + return err + } + + if options.GlobalFlagShowTestOutput { + fmt.Println(output) + } + + return nil +} + +//ConvertCommand ... +//Formats the command to ExecutorCommand +func convertCommand(args []string) (string, []string) { + //Command with extra arguments + if len(args) > 1 { + return args[0], args[1:] + } + return args[0], []string{} +} diff --git a/phlow/deliver_test.go b/phlow/deliver_test.go new file mode 100644 index 0000000..b67da5a --- /dev/null +++ b/phlow/deliver_test.go @@ -0,0 +1,76 @@ +package phlow + +import ( + "github.com/praqma/git-phlow/options" + "github.com/praqma/git-phlow/testfixture" + . "github.com/smartystreets/goconvey/convey" + "testing" +) + +func TestTestDeliver(t *testing.T) { + Convey("Running tests on 'TestDeliver' function", t, func() { + + testfixture.CreateTestRepository(t, false) + + Convey("Wrong path to script should return error", func() { + err := TestDeliver([]string{"./lalalal"}) + t.Log(err) + So(err, ShouldNotBeNil) + }) + + Convey("Right path to script should not return error", func() { + err := TestDeliver([]string{"./test.sh"}) + t.Log(err) + So(err, ShouldBeNil) + }) + + Convey("Right path to error script should return error", func() { + err := TestDeliver([]string{"./testerr.sh"}) + t.Log(err) + So(err, ShouldNotBeNil) + }) + + Convey("Valid one line command should not return error", func() { + options.GlobalFlagShowTestOutput = true + err := TestDeliver([]string{"ls"}) + t.Log(err) + So(err, ShouldBeNil) + }) + + Convey("valid two line command should not return error", func() { + options.GlobalFlagShowTestOutput = true + err := TestDeliver([]string{"ls", "-lah"}) + t.Log(err) + So(err, ShouldBeNil) + }) + + testfixture.RemoveTestRepository(t) + + }) +} + +func TestConvertCommand(t *testing.T) { + Convey("Running tests on 'ConvertCommand' function", t, func() { + + testfixture.CreateTestRepository(t, false) + + Convey("input 'path' should return path only", func() { + cmd, args := convertCommand([]string{"./path/to/script.sh"}) + + So(cmd, ShouldEqual, "./path/to/script.sh") + So(args, ShouldBeEmpty) + }) + + Convey("multi argument should return command and arguments", func() { + cmd, args := convertCommand([]string{"multi", "line", "command", "and", "args"}) + + So(cmd, ShouldEqual, "multi") + So(args, ShouldContain, "line") + So(args, ShouldContain, "command") + So(args, ShouldContain, "and") + So(args, ShouldContain, "args") + }) + + testfixture.RemoveTestRepository(t) + }) +} diff --git a/phlow/localdeliver.go b/phlow/localdeliver.go deleted file mode 100644 index a6ab03a..0000000 --- a/phlow/localdeliver.go +++ /dev/null @@ -1,57 +0,0 @@ -package phlow - -import ( - "fmt" - "os" - "strings" - - "github.com/praqma/git-phlow/githandler" - "github.com/praqma/git-phlow/options" - "github.com/praqma/git-phlow/plugins" -) - -//LocalDeliver ... -func LocalDeliver() { - - branchInfo, _ := githandler.Branch() - dfBranch, _ := plugins.GetDefaultBranch(plugins.RepoURL) - - //Is branch master or is branch delivered - if strings.HasPrefix(branchInfo.Current, "delivered/") || (branchInfo.Current == dfBranch) { - fmt.Printf("You cannot deliver: %s \n", branchInfo.Current) - return - } - fmt.Fprintf(os.Stdout, "Checking out default branch %s \n", options.BranchFormat(dfBranch)) - //Checkout default branch: master - if err := githandler.CheckOut(dfBranch); err != nil { - fmt.Println(err) - return - } - //Pull rebase latest changes - fmt.Fprintln(os.Stdout, "Trying to pull latest changes") - output, err := githandler.Pull() - if err != nil { - fmt.Println(err) - return - } - fmt.Println(output) - - fmt.Fprintf(os.Stdout, "Merging changes from branch %s into branch %s \n", options.BranchFormat(branchInfo.Current), options.BranchFormat(dfBranch)) - //Merge feature branch into default - if err = githandler.Merge(branchInfo.Current); err != nil { - fmt.Println(err) - } - //Rename default branch to delivered - githandler.BranchRename(branchInfo.Current) - - //Push changes to github - fmt.Fprintf(os.Stdout, "Pushing changes to remote %s \n", options.BranchFormat(dfBranch)) - output, err = githandler.Push() - if err != nil { - fmt.Println(err.Error()) - return - } - fmt.Fprintln(os.Stdout, output) - fmt.Printf("Branch %s fearlessly delivered to %s \n", options.BranchFormat(branchInfo.Current), options.BranchFormat(dfBranch)) - -} diff --git a/phlow/phlow_test.go b/phlow/phlow_test.go index acd1a7d..635f0a1 100644 --- a/phlow/phlow_test.go +++ b/phlow/phlow_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/praqma/git-phlow/githandler" - "github.com/praqma/git-phlow/options" "github.com/praqma/git-phlow/testfixture" . "github.com/smartystreets/goconvey/convey" ) @@ -20,40 +19,6 @@ func TestGetIssueFromBranch(t *testing.T) { }) } -func TestClean(t *testing.T) { - - Convey("Runnign tests on 'Clean' function", t, func() { - - testfixture.CreateTestRepository(t, false) - - Convey("Testing output of local clean function", func() { - options.GlobalFlagLocal = true - Clean("origin") - - }) - - testfixture.RemoveTestRepository(t) - }) - -} - -func TestCleanRemote(t *testing.T) { - - Convey("Runnign tests on 'Clean' function", t, func() { - - testfixture.CreateTestRepository(t, false) - - Convey("Testing output of clean function", func() { - options.GlobalFlagLocal = false - Clean("origin") - - }) - - testfixture.RemoveTestRepository(t) - }) - -} - func TestUpNext(t *testing.T) { Convey("Running tests on 'GetNextBranch' function", t, func() { @@ -61,7 +26,7 @@ func TestUpNext(t *testing.T) { Convey("Testing output of clean function", func() { branches := githandler.BranchReady("origin") - res := GetNextBranch(branches) + res := getNextBranch(branches) So(res, ShouldEqual, "origin/ready/15-issue-branch") }) diff --git a/phlow/upnext.go b/phlow/upnext.go index 7f7906c..6b253a3 100644 --- a/phlow/upnext.go +++ b/phlow/upnext.go @@ -2,12 +2,16 @@ package phlow import ( "fmt" - "github.com/praqma/git-phlow/githandler" - "github.com/praqma/git-phlow/options" "os" "sort" + + "github.com/praqma/git-phlow/githandler" + "github.com/praqma/git-phlow/options" ) +//UpNext ... +//Returns the next branch ready for integration based on time of creation +//Oldest branches gets integrated first. func UpNext(remote string) { branches := githandler.BranchReady(remote) @@ -17,7 +21,7 @@ func UpNext(remote string) { fmt.Println("'ready/' branches found on remote") } - next := GetNextBranch(branches) + next := getNextBranch(branches) fmt.Fprint(os.Stdout, next) return } @@ -28,7 +32,9 @@ func UpNext(remote string) { } -func GetNextBranch(branches []string) string { +//getNextBranch +//Sort branches and returns the oldest ready branch +func getNextBranch(branches []string) string { m := make(map[int]string) var time int var err error diff --git a/phlow/workon.go b/phlow/workon.go index 39490e3..a7bbb32 100644 --- a/phlow/workon.go +++ b/phlow/workon.go @@ -7,8 +7,8 @@ import ( "strings" "github.com/praqma/git-phlow/githandler" - "github.com/praqma/git-phlow/plugins" "github.com/praqma/git-phlow/options" + "github.com/praqma/git-phlow/plugins" ) //WorkOn ... diff --git a/plugins/github_test.go b/plugins/github_test.go index 0f2ecea..a42ff13 100644 --- a/plugins/github_test.go +++ b/plugins/github_test.go @@ -5,9 +5,10 @@ import ( "net/http/httptest" "testing" + "strings" + "github.com/praqma/git-phlow/githandler" . "github.com/smartystreets/goconvey/convey" - "strings" ) func TestAuthorize(t *testing.T) { diff --git a/testfixture/gen_test_repo.sh b/testfixture/gen_test_repo.sh index 965e514..1ee4377 100755 --- a/testfixture/gen_test_repo.sh +++ b/testfixture/gen_test_repo.sh @@ -26,6 +26,11 @@ two_commits_on_master () { add_all_and_commit "1 commit - changes to readme" echo "file1" > file1.txt add_all_and_commit "2 commit - changes to file1" + echo "#!/bin/bash \n exit 0" > test.sh + chmod 755 ./test.sh + echo "#!/bin/bash \n exit 1" > testerr.sh + chmod 755 ./testerr.sh + add_all_and_commit "3 commit - test script added" } branch_foo_additions (){