@@ -13,6 +13,7 @@ import (
1313 "github.com/praqma/git-phlow/executor"
1414 "github.com/praqma/git-phlow/options"
1515 "strings"
16+ "errors"
1617)
1718
1819//WorkOnUpdate ...
@@ -21,21 +22,21 @@ import (
2122type WorkOnUpdate func (key string , projectSetting * setting.ProjectSetting ) (string , error )
2223
2324//WorkOnCaller ...
25+ //Toplevel workon function called from cmd
2426func WorkOnCaller (keyOrID string ) {
2527
2628 INIBlock := options .GlobalFlagTarget
2729 conf := setting .NewProjectStg (INIBlock )
2830
2931 if "jira" == strings .ToLower (conf .Service ) {
30-
3132 WorkOn (keyOrID , conf , UpdateJIRAIssue )
3233 return
3334 }
3435
3536 if "github" == strings .ToLower (conf .Service ) {
3637 _ , err := strconv .Atoi (keyOrID )
3738 if err != nil {
38- fmt .Fprintf ( os . Stdout , "Whoops \n Your argument, %s , is not a number! I only accept numbers \n " , keyOrID )
39+ fmt .Println ( "Whoops \n Your argument, " + keyOrID + " , is not a valid GitHub issue number \n " )
3940 os .Exit (0 )
4041 }
4142 WorkOn (keyOrID , conf , UpdateGithubIssue )
@@ -45,12 +46,13 @@ func WorkOnCaller(keyOrID string) {
4546 fmt .Println (conf .Service + "Is an unknown Service in you project .phlow file" )
4647}
4748
49+ //WorkOn ...
50+ //creates a new workspace from issue by given WorkOnUpdate and configuration
4851func WorkOn (keyOrID string , conf * setting.ProjectSetting , update WorkOnUpdate ) {
4952
5053 git := githandler.Git {Run : executor .RunGit }
5154
52- ui .PhlowSpinner .Start ("Setting up workspace" )
53- defer ui .PhlowSpinner .Stop ()
55+ fmt .Println ("Preparing workspace..." )
5456
5557 if _ , err := git .Fetch ("--all" ); err != nil {
5658 fmt .Println (err )
@@ -65,7 +67,6 @@ func WorkOn(keyOrID string, conf *setting.ProjectSetting, update WorkOnUpdate) {
6567
6668 branchInfo := githandler .AsList (out )
6769
68- fmt .Println (plugins .IssueFromBranchName (branchInfo .Current ))
6970 //Are we already on the branch we want to work on
7071 if plugins .IssueFromBranchName (branchInfo .Current ) == keyOrID {
7172 fmt .Fprintf (os .Stdout , "You are already on branch %s \n " , ui .Format .Branch (branchInfo .Current ))
@@ -77,28 +78,23 @@ func WorkOn(keyOrID string, conf *setting.ProjectSetting, update WorkOnUpdate) {
7778
7879 if _ , err = git .CheckOut (branch ); err != nil {
7980 fmt .Println (err )
81+ return
8082 }
81- ui . PhlowSpinner . Stop ()
83+
8284 fmt .Fprintf (os .Stdout , "Resuming to workspace: %s \n " , ui .Format .Branch (branch ))
8385 return
8486 }
8587 }
8688
87- //Get issue and do the transition
88-
8989 name , err := update (keyOrID , conf )
9090
91- //Proceed to create the new workspace
92-
9391 _ , err = git .CheckOut ("-b" , name , conf .Remote + "/" + conf .IntegrationBranch )
9492 if err != nil {
9593 fmt .Println (err )
9694 return
9795 }
9896
99- ui .PhlowSpinner .Stop ()
10097 fmt .Fprintf (os .Stdout , "Created workspace: %s \n " , ui .Format .Branch (name ))
101-
10298}
10399
104100//UpdateJIRAIssue ...
@@ -109,48 +105,39 @@ func UpdateJIRAIssue(key string, conf *setting.ProjectSetting) (string, error) {
109105 user , _ := git .Config ("--get" , "phlow.jirauser" )
110106 token , _ := git .Config ("--get" , "phlow.jiratoken" )
111107
112- //Get jira issue or fail
113108 issue , err := plugins .GetJiraIssue (conf .IssueURL , key , user , token )
114109 if err != nil {
115110 return "" , err
116111 }
117112
118113 var transitionErr error
119- var assignErr error
114+ assignErr := plugins . AssignUser ( conf . IssueURL , key , user , token )
120115
121116 //Get transition
122117 transition , err := plugins .GetTransitions (conf .IssueURL , key , user , token )
123118 if err == nil {
124119 for _ , tran := range transition .Transitions {
125- if tran .To .Name == "In Progress" {
120+ if tran .To .StatusCategory . Name == "In Progress" {
126121 transitionErr = plugins .DoTransition (conf .IssueURL , key , user , token , tran .ID )
122+
127123 break
128124 }
129125 }
126+ transitionErr = errors .New ("No 'In Progress' transition " )
130127 }
131128
132- assignErr = plugins .AssignUser (conf .IssueURL , key , user , token )
133-
134- ui .PhlowSpinner .Stop ()
135- if transitionErr != nil || assignErr != nil {
136- fmt .Fprintf (os .Stdout , "\n -------- Issue %s updated -------- \n " , ui .Format .Issue (issue .Key ))
137- } else {
138- fmt .Printf ("\n Issue %s could not be moved to 'In Progress'\n " , ui .Format .Issue (issue .Key ))
139- fmt .Printf ("Assingee '%s' could not be assigned to issue %s\n " , ui .Format .Assignee (user ), ui .Format .Issue (issue .Key ))
140- fmt .Println (ui .Format .Bold ("Go to Jira and manually set the assignee and state" ))
141-
142- }
129+ fmt .Printf ("\n -------- Issue %s-------- \n " , ui .Format .Issue (issue .Key ))
143130
144131 if transitionErr != nil {
145- fmt .Fprintf (os .Stdout , "Moved to => %s \n " , ui .Format .Label .G4Move (plugins .PhlowLabels ["In Progress" ].Title ))
132+ fmt .Printf ("Issue %s could not be moved to 'In Progress'\n " , ui .Format .Issue (issue .Key ))
133+ } else {
134+ fmt .Printf ("Moved to => %s \n " , ui .Format .Label .G4Move ("In Progress" ))
146135 }
147136
148137 if assignErr != nil {
149- fmt .Fprintf (os .Stdout , "Assignee => %s \n " , ui .Format .Assignee (user ))
150- }
151-
152- if transitionErr != nil || assignErr != nil {
153- fmt .Println ("----------------------------------" )
138+ fmt .Printf ("Assingee '%s' could not be assigned to issue %s\n " , ui .Format .Assignee (user ), ui .Format .Issue (issue .Key ))
139+ } else {
140+ fmt .Printf ("Assignee => %s \n " , ui .Format .Assignee (user ))
154141 }
155142
156143 return plugins .BranchNameFromIssue (issue .Key , issue .Fields .Summary ), nil
@@ -170,21 +157,19 @@ func UpdateGithubIssue(issue string, conf *setting.ProjectSetting) (string, erro
170157 panic (err )
171158 }
172159
160+ oap := githandler .OrgAndRepo (remote )
173161
174- orgAndRepo := githandler .OrgAndRepo (remote )
175- fmt .Println (orgAndRepo .Repository )
176-
177- issueOb , err := plugins .GetIssueGitHub (conf .IssueURL , orgAndRepo .Organisation , orgAndRepo .Repository , issue , token )
162+ issueOb , err := plugins .GetIssueGitHub (conf .IssueURL , oap .Organisation , oap .Repository , issue , token )
178163 if err != nil {
179- fmt .Println ("No matching issues" )
164+ fmt .Println (err )
180165 os .Exit (0 )
181166 }
182167
183- if _ , err := plugins .GitHub . SetLabel ( plugins . PhlowLabels [ "Status - in progress" ]. Title , issueOb . Number ); err != nil {
168+ if err := plugins .SetAssigneeGitHub ( conf . IssueURL , oap . Organisation , oap . Repository , token , issue , user ); err != nil {
184169 fmt .Println (err )
185170 }
186171
187- if err := plugins .GitHub . SetAssignee ( user , issueOb . Number ); err != nil {
172+ if _ , err := plugins .SetLabelGitHub ( conf . IssueURL , oap . Organisation , oap . Repository , token , plugins . PhlowLabels [ "Status - in progress" ]. Title , issue ); err != nil {
188173 fmt .Println (err )
189174 }
190175
0 commit comments