Skip to content

Commit 0a8ab91

Browse files
committed
close #240 prerunperm should not auth because
1 parent ef003bd commit 0a8ab91

File tree

8 files changed

+24
-22
lines changed

8 files changed

+24
-22
lines changed

cmd/cmdperm/prerunperm.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,9 @@ import (
55
"os"
66

77
"github.com/praqma/git-phlow/githandler"
8-
"github.com/praqma/git-phlow/ui"
9-
"github.com/praqma/git-phlow/setting"
108
"github.com/praqma/git-phlow/executor"
119
)
1210

13-
//RequiredAuthentication ...
14-
//Validates if the user has logged in before running the command
15-
func RequiredAuthentication() {
16-
stg := setting.NewToolStg()
17-
token := stg.Token
18-
user := stg.User
19-
20-
if token == "" || user == "" {
21-
fmt.Printf("Please run %s to connect to github \n", ui.Format.Bold("auth"))
22-
os.Exit(0)
23-
}
24-
}
25-
2611
//RequiredCurDirRepository ...
2712
//Validates if the command is runnign in a git repository
2813
func RequiredCurDirRepository() {

cmd/issues.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ var issueCmd = &cobra.Command{
1919
`, ui.Format.Bold("issues")),
2020
PreRun: func(cmd *cobra.Command, args []string) {
2121
cmdperm.RequiredCurDirRepository()
22-
cmdperm.RequiredAuthentication()
2322
},
2423
Run: func(cmd *cobra.Command, args []string) {
2524
phlow.Issues()

cmd/web.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ If no argument is given, it tries to find the issue of the currently checked out
2323
`, ui.Format.Bold("web")),
2424
PreRun: func(cmd *cobra.Command, args []string) {
2525
cmdperm.RequiredCurDirRepository()
26-
cmdperm.RequiredAuthentication()
2726
},
2827
Run: func(cmd *cobra.Command, args []string) {
2928
if len(args) > 0 {

cmd/workon.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ A new branch will be created, based on your remote default branch and named afte
2020
`, ui.Format.Bold("workon")),
2121
PreRun: func(cmd *cobra.Command, args []string) {
2222
cmdperm.RequiredCurDirRepository()
23-
cmdperm.RequiredAuthentication()
2423
},
2524
Run: func(cmd *cobra.Command, args []string) {
2625

phlow/workon.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ func WorkOn(keyOrID string, conf *setting.ProjectSetting, update WorkOnUpdate) {
8787
}
8888

8989
name, err := update(keyOrID, conf)
90+
if err != nil {
9091

92+
fmt.Println(err)
93+
os.Exit(1)
94+
}
95+
//ERROR CHECK HERE
9196
_, err = git.CheckOut("-b", name, conf.Remote+"/"+conf.IntegrationBranch)
9297
if err != nil {
9398
fmt.Println(err)

plugins/github.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ func GetIssueGitHub(URL, org, repo, key, token string) (*Issue, error) {
107107
}
108108
defer res.Body.Close()
109109

110+
if res.StatusCode == 401 {
111+
return nil, errors.New("Not Authorized \nVerify that you are authorized by running 'git phlow auth' with the same configuration")
112+
}
113+
110114
if res.StatusCode == 404 && (org == "" || repo == "") {
111115
return nil, errors.New("Could not reach GitHub API - Malformed URL \nVerify 'Remote' field is correct in configuration" +
112116
"\ntry 'git ls-remote --get <Remote from config>' should return: [email protected]:org/repo.git")
@@ -188,4 +192,4 @@ func SetAssigneeGitHub(URL, org, repo, token, issue, assignee string, ) (err err
188192
}
189193
defer res.Body.Close()
190194
return nil
191-
}
195+
}

plugins/jira.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/ioutil"
88
"fmt"
99
"bytes"
10+
"strings"
1011
)
1112

1213
//AuthenticateJIRA ...
@@ -48,6 +49,8 @@ func AuthorizeJIRA(URL, user, pass string) (token string, err error) {
4849
//GetJiraIssue ...
4950
func GetJiraIssue(URL, key, user, pass string) (*JiraIssue, error) {
5051

52+
pass = strings.TrimSpace(pass)
53+
5154
issueURL := "/rest/api/latest/issue/"
5255
req, _ := http.NewRequest("GET", URL+issueURL+key, nil)
5356
req.Header.Set("Content-Type", "application/json")
@@ -60,7 +63,17 @@ func GetJiraIssue(URL, key, user, pass string) (*JiraIssue, error) {
6063
}
6164
defer res.Body.Close()
6265

63-
body, err := ioutil.ReadAll(res.Body);
66+
if res.StatusCode == 401 {
67+
return nil, errors.New("Not Authorized \nVerify that you are authorized by running 'git phlow auth' with the same configuration")
68+
}
69+
70+
if res.StatusCode == 404 {
71+
return nil, errors.New("Could not find issue with ID " + key +
72+
" \nCheck you have permissions or that the issue exists \nVerify the configuration 'issue_url' is correct")
73+
74+
}
75+
76+
body, err := ioutil.ReadAll(res.Body)
6477
if err != nil {
6578
return nil, err
6679
}

plugins/plugin.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ type Authentication func(URL, user, pass string) (authenticated bool, err error)
1818
//interface for getting the default branch of the external service
1919
type DefaultBranch func(URL, org, repo, token string) (defaultBranch string, err error)
2020

21-
22-
2321
//PhlowLabels ...
2422
//Map of labels in the phlow
2523
var PhlowLabels map[string]*PhlowLabel

0 commit comments

Comments
 (0)