From 467fa8d404ddead2a8c8bca1ea0a39bcb4767c05 Mon Sep 17 00:00:00 2001 From: Simon Groenborg Date: Fri, 18 Aug 2017 13:24:35 +0200 Subject: [PATCH] close #185 auth for jira --- ci/CHANGELOG.md | 23 ++++++------ ci/pipeline.yml | 2 +- ci/test/test.sh | 2 +- ci/windows/go-test-windows.ps1 | 3 +- githandler/git.go | 4 ++- phlow/issues_test.go | 45 ++++++++++++----------- phlow/mkalias.go | 12 ++++--- plugins/gh.go | 15 ++++---- setting/config.go | 57 ----------------------------- setting/config_test.go | 66 ---------------------------------- setting/setting_test.go | 5 ++- 11 files changed, 60 insertions(+), 174 deletions(-) delete mode 100644 setting/config.go delete mode 100644 setting/config_test.go diff --git a/ci/CHANGELOG.md b/ci/CHANGELOG.md index 7dfe4f9..718b3bc 100644 --- a/ci/CHANGELOG.md +++ b/ci/CHANGELOG.md @@ -1,19 +1,18 @@ ## Changelog -The new release of git-phlow adds support for windows in _beta_. Overall improvements have been made to increase stability and remove -various bugs and odd behaviours. +git phlow have had a _huge_ makeover in this release. Configuration have been introduced, and git phlow now works by reading +configuration from a .phlow file, instead of guessing your remote and integration branch. This also brings support for new services like Jira and bitbucket. +The underlying git implementation have been stabilized and is now up and running on windows, so do not feel cheated anymore. #### Features -- Windows is now support in a pre-release version -- Add Less and More browsing #150 @groenborg -- Add no-color option for windows #148 @kryptag +- Auth for jira #185 @groenborg +git phlow can now authorize against Jira using the right configuration. See [docs](docs/README.md) + +- phlow as configuration #192 @groenborg +git phlow now works based on a .phlow config file #### Improvements -- Use Scanner in stead of buffered Reader #149 @groenborg -- Add windows binary to GitHub release #151 @groenborg -- Added windows worker to concourse ci #144 +- git for windows is stabilized #### Bug fixes -- Colors are buggy when terminal width is changed #131 @groenborg -- username and password are no longer printed #158 @groenborg -- version was stuck at 1.0.0 #167 @groenborg -- Windows release is now zip and not tar.gz #169 @groenborg +- pull when setting up workspace #193 @lakruzz + diff --git a/ci/pipeline.yml b/ci/pipeline.yml index aedd7ae..1d82de8 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -6,7 +6,7 @@ jobs: - get: tollgate trigger: true - get: gp-version - params: {bump: patch} + params: {bump: major} - put: gp-version params: {file: gp-version/version} - task: integration diff --git a/ci/test/test.sh b/ci/test/test.sh index 840d6ef..873592d 100755 --- a/ci/test/test.sh +++ b/ci/test/test.sh @@ -14,7 +14,7 @@ go install github.com/onsi/ginkgo/ginkgo # run tests -go test -v ./... +ginkgo -v -r -trace -cover diff --git a/ci/windows/go-test-windows.ps1 b/ci/windows/go-test-windows.ps1 index afb96eb..6becb21 100644 --- a/ci/windows/go-test-windows.ps1 +++ b/ci/windows/go-test-windows.ps1 @@ -12,8 +12,7 @@ cd $env:GOPATH/src/github.com/praqma/git-phlow go get -d -t -v ./... #RUN TESTS -cd executor -go test -p 1 -v +go test -v ./... # USES THE LATEST EXITCODE, WHICH IS FROM GO TEST, AND EXITS WITH THAT. THIS FIXIS # ISSUE #152 diff --git a/githandler/git.go b/githandler/git.go index 18abd0e..691b1de 100644 --- a/githandler/git.go +++ b/githandler/git.go @@ -84,7 +84,7 @@ func (os *Git) Config(argv ...string) (string, error) { return strings.Replace(stdOut, "\n", "", -1), nil } -//DEPRECATESD SECTION --------------------------------------------------------------- +//Deprecated //FormatPatch ... //dry runs patch to see if we can auto merge func FormatPatch(buf *bytes.Buffer, remoteBranch string) (err error) { @@ -95,6 +95,7 @@ func FormatPatch(buf *bytes.Buffer, remoteBranch string) (err error) { return } +//Deprecated //StatusPorcelain ... //generates behind and ahead status func StatusPorcelain() (string, error) { @@ -105,6 +106,7 @@ func StatusPorcelain() (string, error) { return strings.TrimSpace(out), nil } +//Deprecated //PushRename ... func PushRename(branch, defaultBranch string) (string, error) { remote := ConfigBranchRemote(defaultBranch) diff --git a/phlow/issues_test.go b/phlow/issues_test.go index 8774609..d7b149b 100644 --- a/phlow/issues_test.go +++ b/phlow/issues_test.go @@ -13,24 +13,26 @@ var _ = Describe("Issue", func() { Describe("GetPager on windows", func() { Context("with pager set", func() { It("should return testpager", func() { - EXPECTED := "testpager" + if runtime.GOOS == "windows" { + EXPECTED := "testpager" - err := os.Setenv("PAGER", "testpager") - ACTUAL := phlow.GetPager() + err := os.Setenv("PAGER", "testpager") + ACTUAL := phlow.GetPager() - Ω(ACTUAL).Should(Equal(EXPECTED)) - Ω(err).Should(BeNil()) + Ω(ACTUAL).Should(Equal(EXPECTED)) + Ω(err).Should(BeNil()) + } }) }) Context("with pager unset", func() { It("should return more", func() { - err := os.Unsetenv("PAGER") + if runtime.GOOS == "windows" { + err := os.Unsetenv("PAGER") - ACTUAL := phlow.GetPager() - EXPECTED := "more" + ACTUAL := phlow.GetPager() + EXPECTED := "more" - if runtime.GOOS == "windows" { Ω(ACTUAL).Should(Equal(EXPECTED)) Ω(err).Should(BeNil()) } @@ -44,26 +46,29 @@ var _ = Describe("Issue", func() { Describe("GetPager on Unix", func() { Context("with pager set", func() { It("Should return less", func() { - EXPECTED := "less" + if runtime.GOOS != "windows" { + EXPECTED := "less" - err := os.Setenv("PAGER", "less") - ACTUAL := phlow.GetPager() + err := os.Setenv("PAGER", "less") + ACTUAL := phlow.GetPager() - Ω(ACTUAL).Should(Equal(EXPECTED)) - Ω(err).Should(BeNil()) + Ω(ACTUAL).Should(Equal(EXPECTED)) + Ω(err).Should(BeNil()) + } }) }) Context("with pager unset", func() { It("Should return nothing", func() { - err := os.Unsetenv("PAGER") - - ACTUAL := phlow.GetPager() - EXPECTED := "" + if runtime.GOOS != "windows" { + err := os.Unsetenv("PAGER") - Ω(ACTUAL).Should(Equal(EXPECTED)) - Ω(err).Should(BeNil()) + ACTUAL := phlow.GetPager() + EXPECTED := "" + Ω(ACTUAL).Should(Equal(EXPECTED)) + Ω(err).Should(BeNil()) + } }) }) diff --git a/phlow/mkalias.go b/phlow/mkalias.go index b8fbbe0..8021956 100644 --- a/phlow/mkalias.go +++ b/phlow/mkalias.go @@ -3,16 +3,18 @@ package phlow import ( "fmt" "github.com/praqma/git-phlow/ui" - "github.com/praqma/git-phlow/setting" + "github.com/praqma/git-phlow/githandler" + "github.com/praqma/git-phlow/executor" ) //MakeAliasCaller ... func MakeAliasCaller() { - MakeAlias(setting.GitConfig{}) + MakeAlias() } //MakeAlias ... -func MakeAlias(conf setting.Configurator) { +func MakeAlias() { + git := githandler.Git{Run: executor.RunGit} aliases := make(map[string]string) aliases["alias.wrapup"] = "phlow wrapup" aliases["alias.workon"] = "phlow workon" @@ -23,10 +25,10 @@ func MakeAlias(conf setting.Configurator) { for group, value := range aliases { - str := conf.Get(group) + str, _ := git.Config("--global", "--get", group) if str == "" { fmt.Printf("Creating alias %s \n", ui.Format.Alias(group)) - conf.Set(group, value) + git.Config("--global", group, value) } else { fmt.Printf("Alias %s already exists \n", ui.Format.Alias(group)) } diff --git a/plugins/gh.go b/plugins/gh.go index c683257..8d2f4a7 100644 --- a/plugins/gh.go +++ b/plugins/gh.go @@ -12,7 +12,7 @@ import ( "github.com/praqma/git-phlow/githandler" "github.com/praqma/git-phlow/options" - "github.com/praqma/git-phlow/setting" + "github.com/praqma/git-phlow/executor" ) var GitHub *GitHubImpl @@ -27,6 +27,7 @@ type GitHubImpl struct { token string } +//Deprecated - This need to be redone to fit configuration - refer to: AuthorizeGitHub and AuthenticateGitHub they are changed to work the new way //init ... //creates a new GitHub request object with all the gh api urls func init() { @@ -40,12 +41,12 @@ func init() { userRepo: "/user/repos", } - stg := setting.NewToolStg() - + git := githandler.Git{Run: executor.RunGit} + t, _ := git.Config("--get", "phlow.token") info, _ := githandler.Remote() org := info.Organisation repo := info.Repository - token := stg.Token + token := t GitHub = &GitHubImpl{ urls, @@ -110,9 +111,6 @@ func AuthenticateGitHub(githubBaseURL string, user, token string) (bool, error) return true, nil } - -// ------------------------------------------ DEPRECATE SECTION - //GetIssues ... func (g *GitHubImpl) GetIssues() (issues []Issue, err error) { URL := fmt.Sprintf(g.URLNoEsc(urls.issueURL), g.org, g.repo) @@ -156,7 +154,6 @@ func (g *GitHubImpl) SetLabel(label string, issue int) (labels []Label, err erro return re, nil } - //Default ... //Get default branch of a GitHub issue func (g *GitHubImpl) Default() (defaultBranch string, err error) { @@ -228,6 +225,7 @@ func createGHPermissions() (string, error) { return string(b2b), nil } +//Deprecated //Auth ... //Auth request to gh func (g *GitHubImpl) Auth(user, pass string) (token string, err error) { @@ -253,6 +251,7 @@ func (g *GitHubImpl) Auth(user, pass string) (token string, err error) { return re.Token, nil } +//Deprecated //CheckAuth ... //Checks personal access token validity by requesting private repositories and checking status code func (g *GitHubImpl) CheckAuth() (bool, error) { diff --git a/setting/config.go b/setting/config.go deleted file mode 100644 index e61e8c4..0000000 --- a/setting/config.go +++ /dev/null @@ -1,57 +0,0 @@ -package setting - -import ( - "strings" - "github.com/praqma/git-phlow/executor" -) - -const ( - //PhlowUser ... - PhlowUser = "phlow.user" - - //PhlowToken ... - PhlowToken = "phlow.token" -) - -//DefaultGitConfig ... -func DefaultGitConfig() Configurator { - return GitConfig{Run: executor.RunCommand} -} - -//Configurator ... -//Interface for system configurations -type Configurator interface { - Set(group string, value string) - Get(group string) string - Unset(group string) -} - -//GitConfig ... -type GitConfig struct { - Run executor.Runner -} - -//Get ... -func (pc GitConfig) Get(group string) string { - output, err := pc.Run("git", "config", "--global", "--get", group) - if err != nil { - panic(err) - } - return strings.Replace(output, "\n", "", -1) -} - -//Set ... -func (pc GitConfig) Set(group string, value string) { - _, err := pc.Run("git", "config", "--global", group, value) - if err != nil { - panic(err) - } -} - -//Unset ... -func (pc GitConfig) Unset(group string) { - _, err := pc.Run("git", "config", "--global", "--unset", group) - if err != nil { - panic(err) - } -} diff --git a/setting/config_test.go b/setting/config_test.go deleted file mode 100644 index 24f37db..0000000 --- a/setting/config_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package setting_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "errors" - "github.com/praqma/git-phlow/setting" -) - -var _ = Describe("Config", func() { - Describe("Testing configurator", func() { - Context("", func() { - It("Set should not panic", func() { - conf := setting.GitConfig{Run: func(command string, argv ...string) (string, error) { - return "token\n", nil - }} - - var fun = func() { conf.Set(setting.PhlowToken, "value") } - Ω(fun).ToNot(Panic()) - }) - - It("Unset should not panic", func() { - conf := setting.GitConfig{Run: func(command string, argv ...string) (string, error) { - return "token\n", nil - }} - - var fun = func() { conf.Set(setting.PhlowToken, "value") } - Ω(fun).ToNot(Panic()) - }) - - It("Get should return EXPECTED", func() { - EXPECTED := "token" - conf := setting.GitConfig{Run: func(command string, argv ...string) (string, error) { - return "token\n", nil - }} - - ACTUAL := conf.Get(setting.PhlowUser) - Ω(ACTUAL).Should(Equal(EXPECTED)) - }) - - }) - - Context("when it panics", func() { - conf := setting.GitConfig{Run: func(command string, argv ...string) (string, error) { - return "", errors.New("") - }} - - It("Set should panic", func() { - var f = func() { conf.Set("invalid", "value") } - Ω(f).To(Panic()) - }) - - It("Get should panic", func() { - var f = func() { conf.Get("invalid") } - Ω(f).To(Panic()) - }) - It("Unset should panic", func() { - - var f = func() { conf.Unset("invalid") } - Ω(f).To(Panic()) - }) - - }) - - }) -}) diff --git a/setting/setting_test.go b/setting/setting_test.go index 0d4956c..2e39425 100644 --- a/setting/setting_test.go +++ b/setting/setting_test.go @@ -5,6 +5,7 @@ import ( "github.com/praqma/git-phlow/setting" . "github.com/onsi/gomega" "github.com/go-errors/errors" + "runtime" ) var _ = Describe("Setting", func() { @@ -18,7 +19,9 @@ var _ = Describe("Setting", func() { It("global should not be empty", func() { local := setting.GetGlobal() - Ω(local).ShouldNot(BeEmpty()) + if runtime.GOOS != "windows" { + Ω(local).ShouldNot(BeEmpty()) + } }) })