Skip to content

Commit e53f0b8

Browse files
committed
jira support
1 parent 010f8f4 commit e53f0b8

File tree

4 files changed

+62
-13
lines changed

4 files changed

+62
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
sprints/*
33
StoryManager.pyc
4+
preferences.json

Default.sublime-commands

+4
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@
1818
{
1919
"caption": "Agile: Delete Sprint",
2020
"command": "delete_sprint"
21+
},
22+
{
23+
"caption": "Agile: Configure Jira",
24+
"command": "configure_jira"
2125
}
2226
]

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ Basic Flow
99

1010
Shortcuts
1111
----------
12-
- ctrl+cmd+s - save story
13-
- crtl+cmd+o - open story
14-
- shift+alt+p - all remaining CRUD commands
12+
- ctrl+super+s - save story
13+
- crtl+super+o - open story
14+
- shift+super+p - all remaining commands available under 'Agile' prefix
15+
16+
### Jira Support
17+
Agile can automatically open the jira ticket associated with your story if 2 criteria are met
18+
- configure a root url via shift+super+p -> 'Agile: Configure Jira'
19+
- You must name your jira story identically to its jira url slug. ie) https://example.jira.com/browse/my-story would need to be saved as 'my-story'
1520

1621
### TODO:
1722
configure jira root url

StoryManager.py

+49-10
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,41 @@
44

55

66
SPRINTS_PATH = sublime.packages_path() + '/Agile/sprints/'
7+
PREFS_PATH = sublime.packages_path() + '/Agile/preferences.json'
78

89
def open_url(url):
910
sublime.active_window().run_command('open_url', {"url": url})
1011

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+
1136
def open_sprint_folders(origin):
1237
SPRINTS_PATH = sublime.packages_path() + '/Agile/sprints/'
1338
sprint_folders = []
1439
sprint_titles = []
1540

16-
if not os.path.exists(SPRINTS_PATH):
17-
os.makedirs(SPRINTS_PATH)
41+
ensure_path(SPRINTS_PATH, True)
1842

1943
# get existing sprint folders
2044
sprint_folders = os.listdir(SPRINTS_PATH)
@@ -58,7 +82,7 @@ def select_story(origin, sprint_path, index):
5882
origin.window.show_quick_panel(story_titles, origin.story_selected)
5983

6084
# return paths to reference by index after selection
61-
return story_paths
85+
return story_titles, story_paths
6286

6387

6488

@@ -112,14 +136,14 @@ def save_story(self, story_title):
112136
# display sprint folders via quick panel
113137
# display stories associated w/ a sprint
114138
class OpenStoryCommand(sublime_plugin.WindowCommand):
115-
SPRINTS_PATH = sublime.packages_path() + '/Agile/sprints/'
116139

117140
def run(self):
141+
self.prefs = load_prefs()
118142
self.sprint_folders = open_sprint_folders(self)
119143

120144
def sprint_selected(self, index):
121145
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)
123147

124148
# open the story json file
125149
# iterate the groups, if any
@@ -128,13 +152,14 @@ def story_selected(self, index):
128152
w = self.window
129153
if index != -1:
130154
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)
134159

135160
with open(self.sprint_path + '/' + self.story_path, 'rb') as json_file:
136161
json_data = json.load(json_file)
137-
print json_data
162+
138163
# create the view groups
139164
num_groups = len(json_data['groups'])
140165
if num_groups > 1:
@@ -179,7 +204,7 @@ def run(self):
179204

180205
def sprint_selected(self, index):
181206
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)
183208

184209
def story_selected(self, index):
185210
if index != -1:
@@ -237,3 +262,17 @@ def you_sure_brah(self, index):
237262
else:
238263
return
239264

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

Comments
 (0)