Skip to content

Commit 6d5730d

Browse files
committed
close #164 detect github and bitbucket
1 parent dc3dfed commit 6d5730d

File tree

20 files changed

+387
-99
lines changed

20 files changed

+387
-99
lines changed

ci/test/test.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#!/bin/sh
22
set -e -u -x
33

4-
#CREATE GO DIRECTORY STRUCTURE
5-
#THE STRUCTURE IS NECESSARY FOR GO TOOLS OTHERWISE
6-
# 'build' AND 'get' WILL FAIL
7-
8-
mkdir -p $GOPATH/src/github.com/praqma
9-
cp -R git-phlow/ $GOPATH/src/github.com/praqma
4+
#Set new GOPATH to current dir
5+
export GOPATH=$PWD
6+
export PATH=$PATH:$GOPATH/bin
107

118
# RESOLVE DEPENDENCIES - TEST AND PRODUCTION
129
cd $GOPATH/src/github.com/praqma/git-phlow
13-
go get -d -t -v ./...
10+
go get -t -d -v ./...
11+
12+
#install ginkgo
13+
go install github.com/onsi/ginkgo/ginkgo
14+
15+
16+
# run tests
17+
go test -p 1 -v ./...
18+
19+
1420

15-
#RUN WHOLE TEST SUITE IN VERBOSE MODE
16-
#THE P FLAG ENSURES TESTS WILL RUN SEQUENTIALLY
17-
#THEY WILL FAIL IN PARALLEL BECAUSE THE TESTFIXTURE CREATES CONFLICTING DIRECTORIES
18-
#HOWEVER THIS IS NOT RELATED TO THE RESULTS OF THE TESTS
19-
go test -v -p 1 ./...

ci/test/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ platform: linux
44
image_resource:
55
type: docker-image
66
source: {repository: golang, tag: "1.8"}
7+
8+
params:
9+
coveralls: token
710

811
inputs:
912
- name: git-phlow
13+
path: src/github.com/praqma/git-phlow
1014

1115
run:
12-
path: git-phlow/ci/test/test.sh
16+
path: src/github.com/praqma/git-phlow/ci/test/test.sh

cmd/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Auth will prompt you for a GitHub username and password to generate a token.
1818
Don't worry, the token does not include admininstrator rights, only access to manage issues for public repositories.
1919
`, ui.Format.Bold("auth")),
2020
Run: func(cmd *cobra.Command, args []string) {
21-
phlow.Auth()
21+
phlow.AuthCaller()
2222
},
2323
}
2424

cmd/cmdperm/prerunperm.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import (
66

77
"github.com/praqma/git-phlow/githandler"
88
"github.com/praqma/git-phlow/ui"
9+
"github.com/praqma/git-phlow/platform"
910
)
1011

1112
//RequiredAuthentication ...
1213
//Validates if the user has logged in before running the command
1314
func RequiredAuthentication() {
14-
token := githandler.ConfigGet("token", "phlow")
15-
user := githandler.ConfigGet("user", "phlow")
15+
conf := platform.DefaultConfiguration()
16+
token := conf.Get(platform.PhlowToken)
17+
user := conf.Get(platform.PhlowUser)
1618

1719
if token == "" || user == "" {
1820
fmt.Printf("Please run %s to connect to github \n", ui.Format.Bold("auth"))

cmd/mkalias.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package cmd
33
import (
44
"fmt"
55

6-
"github.com/praqma/git-phlow/phlow"
76
"github.com/praqma/git-phlow/ui"
87
"github.com/spf13/cobra"
8+
"github.com/praqma/git-phlow/phlow"
99
)
1010

1111
// mkaliasCmd represents the mkalias command
@@ -18,7 +18,7 @@ This allows you to use 'git workon', rather than 'git phlow workon'.
1818
The aliases are added to your global .gitconfig file.
1919
`, ui.Format.Bold("mkalias")),
2020
Run: func(cmd *cobra.Command, args []string) {
21-
phlow.MkAlias()
21+
phlow.MakeAliasCaller()
2222
},
2323
}
2424

executor/executor.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ func verboseOutput(argv ...string) {
2020
fmt.Println()
2121
}
2222

23-
2423
//Commander ...
2524
//interface for os executions
2625
type Commander interface {
2726
Run() error
2827
}
2928

3029
//ExecuteCommander ...
31-
//Execute a function with control over stdout and stdin
30+
//Run a function with control over stdout and stdin
3231
func ExecuteCommander(c Commander) error {
3332
err := c.Run()
3433
if err != nil {
@@ -37,6 +36,34 @@ func ExecuteCommander(c Commander) error {
3736
return nil
3837
}
3938

39+
40+
//Runner ...
41+
//Runner type for git executions
42+
type Runner func(command string, argv ...string) (string, error)
43+
44+
//Run ...
45+
//implemented runner
46+
func Run(command string, argv ...string) (string, error) {
47+
var stdOutBuffer, stdErrBuffer bytes.Buffer
48+
exe := exec.Command(command, argv...)
49+
50+
if options.GlobalFlagVerbose {
51+
verboseOutput(exe.Args...)
52+
}
53+
54+
exe.Stderr = &stdErrBuffer
55+
exe.Stdout = &stdOutBuffer
56+
57+
err := exe.Run()
58+
if err != nil {
59+
if out := stdOutBuffer.String(); stdErrBuffer.String() == "" {
60+
return "", errors.New(out)
61+
}
62+
return "", errors.New(stdErrBuffer.String())
63+
}
64+
return stdOutBuffer.String(), nil
65+
}
66+
4067
//ExecuteCommand ...
4168
//Executes a single command from strings
4269
func ExecuteCommand(command string, argv ...string) (string, error) {

githandler/config.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

githandler/git.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package githandler
22

33
import (
4-
"fmt"
54
"regexp"
65
"strings"
76

87
"github.com/praqma/git-phlow/executor"
98
"bytes"
109
"os/exec"
10+
"fmt"
1111
)
1212

1313
//CheckOut ...
@@ -21,9 +21,8 @@ func CheckoutNewBranchFromRemote(branch, defaultBranch string) error {
2121
remote := ConfigBranchRemote(defaultBranch)
2222
_, err := executor.ExecuteCommand("git", "checkout", "-b", branch, remote+"/"+defaultBranch)
2323
return err
24-
}
25-
2624

25+
}
2726

2827
//FormatPatch ...
2928
//dry runs patch to see if we can auto merge
@@ -137,3 +136,10 @@ func remoteURLExtractor(url string) *RemoteInfo {
137136
//Clone from local repo
138137
return &RemoteInfo{}
139138
}
139+
140+
//ConfigBranchRemote ...
141+
func ConfigBranchRemote(branch string) string {
142+
configArg := fmt.Sprintf("branch.%s.remote", branch)
143+
output, _ := executor.ExecuteCommand("git", "config", configArg)
144+
return strings.Replace(output, "\n", "", -1)
145+
}

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

3-
import "github.com/praqma/git-phlow/cmd"
3+
import (
4+
"github.com/praqma/git-phlow/cmd"
5+
)
46

57
func main() {
68
cmd.Execute()

options/option.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ var (
1414
//GlobalFlagMine ...
1515
GlobalFlagMine = false
1616

17-
18-
19-
2017
//GlobalFlagVersion ...
2118
GlobalFlagVersion = false
2219

@@ -47,3 +44,15 @@ var (
4744
//Date date of build
4845
Date string
4946
)
47+
48+
func init() {
49+
50+
}
51+
52+
func windows() {
53+
54+
}
55+
56+
func unix() {
57+
58+
}

0 commit comments

Comments
 (0)