4
4
5
5
6
6
SPRINTS_PATH = sublime .packages_path () + '/Agile/sprints/'
7
+ PREFS_PATH = sublime .packages_path () + '/Agile/preferences.json'
7
8
8
9
def open_url (url ):
9
10
sublime .active_window ().run_command ('open_url' , {"url" : url })
10
11
12
+ def init_prefs ():
13
+ with open (PREFS_PATH , 'wb' ) as json_file :
14
+ prefs = { 'jira_root' : 'https://example.jira.com' }
15
+ json .dump (prefs , json_file )
16
+
17
+ def load_prefs ():
18
+ ensure_path (PREFS_PATH )
19
+
20
+ with open (PREFS_PATH , 'r+' ) as json_file :
21
+ try :
22
+ json_data = json .load (json_file )
23
+ return json_data
24
+ except ValueError as exc :
25
+ #enters if there is no data in the file yet`
26
+ init_prefs ()
27
+ load_prefs ()
28
+
29
+ def ensure_path (path , is_folder = False ):
30
+ if not os .path .exists (path ):
31
+ if is_folder :
32
+ os .makedirs (path )
33
+ else :
34
+ open (path , 'wb' ).close ()
35
+
11
36
def open_sprint_folders (origin ):
12
37
SPRINTS_PATH = sublime .packages_path () + '/Agile/sprints/'
13
38
sprint_folders = []
14
39
sprint_titles = []
15
40
16
- if not os .path .exists (SPRINTS_PATH ):
17
- os .makedirs (SPRINTS_PATH )
41
+ ensure_path (SPRINTS_PATH , True )
18
42
19
43
# get existing sprint folders
20
44
sprint_folders = os .listdir (SPRINTS_PATH )
@@ -58,7 +82,7 @@ def select_story(origin, sprint_path, index):
58
82
origin .window .show_quick_panel (story_titles , origin .story_selected )
59
83
60
84
# return paths to reference by index after selection
61
- return story_paths
85
+ return story_titles , story_paths
62
86
63
87
64
88
@@ -112,14 +136,14 @@ def save_story(self, story_title):
112
136
# display sprint folders via quick panel
113
137
# display stories associated w/ a sprint
114
138
class OpenStoryCommand (sublime_plugin .WindowCommand ):
115
- SPRINTS_PATH = sublime .packages_path () + '/Agile/sprints/'
116
139
117
140
def run (self ):
141
+ self .prefs = load_prefs ()
118
142
self .sprint_folders = open_sprint_folders (self )
119
143
120
144
def sprint_selected (self , index ):
121
145
self .sprint_path = SPRINTS_PATH + self .sprint_folders [index ]
122
- self .story_paths = select_story (self , self .sprint_path , index )
146
+ self .story_titles , self . story_paths = select_story (self , self .sprint_path , index )
123
147
124
148
# open the story json file
125
149
# iterate the groups, if any
@@ -128,13 +152,14 @@ def story_selected(self, index):
128
152
w = self .window
129
153
if index != - 1 :
130
154
self .story_path = self .story_paths [index ]
131
- #TODO: refactor this
132
- #url = 'https://iseatz.jira.com/browse/' + str(self.story_titles[index]).strip('[]').strip("'")
133
- #open_url(url)
155
+ if self .prefs ['jira_root' ]:
156
+ url = self .prefs ['jira_root' ] + '/browse/' + str (self .story_titles [index ]).strip ('[]' ).strip ("'" )
157
+ print url
158
+ open_url (url )
134
159
135
160
with open (self .sprint_path + '/' + self .story_path , 'rb' ) as json_file :
136
161
json_data = json .load (json_file )
137
- print json_data
162
+
138
163
# create the view groups
139
164
num_groups = len (json_data ['groups' ])
140
165
if num_groups > 1 :
@@ -179,7 +204,7 @@ def run(self):
179
204
180
205
def sprint_selected (self , index ):
181
206
self .sprint_path = SPRINTS_PATH + self .sprint_folders [index ]
182
- self .story_paths = select_story (self , self .sprint_path , index )
207
+ self .story_titles , self . story_paths = select_story (self , self .sprint_path , index )
183
208
184
209
def story_selected (self , index ):
185
210
if index != - 1 :
@@ -237,3 +262,17 @@ def you_sure_brah(self, index):
237
262
else :
238
263
return
239
264
265
+ class ConfigureJiraCommand (sublime_plugin .WindowCommand ):
266
+
267
+ def run (self ):
268
+ ensure_path (PREFS_PATH )
269
+ json_data = load_prefs ()
270
+ self .window .show_input_panel ('Enter Jira Root Url: ' , json_data ['jira_root' ], self .jira_added , None , None )
271
+
272
+ def jira_added (self , jira_root ):
273
+ with open (PREFS_PATH , 'r+' ) as json_file :
274
+ data = json .load (json_file )
275
+ data ['jira_root' ] = jira_root
276
+ json_file .seek (0 ) # write to the start of the file
277
+ json_file .write (json .dumps (data ))
278
+ json_file .truncate () # remove the old stuff
0 commit comments