11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# File 'lib/jeera/commands/issues.rb', line 11
def self.define_tasks(thor)
thor.class_eval do
desc :list, 'List issues for a project'
def list(user = nil, project = nil)
response = issues_call(user, project)
parse_and_print_table(:issues, response)
end
desc :stories, 'Story issues'
def stories(user = nil, project = nil)
jql :type, 'story'
response = issues_call(user, project)
parse_and_print_table(:issues, response)
end
desc :bugs, 'Bug issues'
def bugs(user = nil, project = nil)
jql :type, 'bugs'
response = issues_call(user, project)
parse_and_print_table(:issues, response)
end
desc :active, 'Issues in progress'
def active(user = nil, project = nil)
jql :active
response = issues_call(user, project)
parse_and_print_table(:issues, response)
end
desc :show, 'Details about an issue'
def show(issue_key)
response = Jeera.client.get(issue_endpoint(issue_key))
issue = issue_obj(response.body.with_indifferent_access)
= issue[:comments]
= ( && ! .empty?) ? () : ''
say ["\n", (issue), issue[:description], "\n", ].join("\n")
end
desc :go, 'Opens issue page in browser'
def go(issue_key)
`open #{browse_issue_url(issue_key)}`
end
desc :issue, 'Create new issue'
def issue(summary)
params = { fields: {
summary: summary,
issuetype: { name: (options[:type] || 'story') },
project: { key: (options[:project] || current_project) },
} }
params[:fields][:assignee] = { name: options[:user] } if options[:user]
response = Jeera.client.post('issue', params)
if success_response? response
success_message "Issue #{response.body['key']} created. - #{summary}"
else
error_message "Unable to create this issue"
end
end
desc :assign, 'Assign bug to user'
def assign(issue_key, user)
params = { fields: { assignee: { name: user } } }
response = Jeera.client.post(issue_endpoint(issue_key), params)
if success_response? response
success_message "Issue #{response.body['key']} assigned to #{user}"
else
error_message "Assign who to what now?"
end
end
desc :fix, 'Mark issue as resolved'
def fix(issue_key)
params = { fields: { status: { name: 'Fixed' } } }
response = Jeera.client.put(issue_endpoint(issue_key), params)
if success_response? response
success_message "The fix is in. Issue #{response.body['key']} resolved."
else
error_message "No can do. Issue #{issue_key} is still broken."
end
end
desc :start, 'Mark issue as in progress'
def start(issue_key)
params = { fields: { status: { name: 'In Progress' } } }
response = Jeera.client.put(issue_endpoint(issue_key), params)
if success_response? response
success_message "Glad to hear you're on the case."
else
error_message "Your enthusiasm is appreciated. Just not right now."
end
end
desc :stop, 'Stop progress on an issue'
def stop(issue_key)
params = { fields: { status: { name: '' } } }
response = Jeera.client.put(issue_endpoint(issue_key), params)
if success_response? response
success_message "The fix is in. Issue #{response.body['key']} resolved."
else
error_message "No way. You can't quit now, #{Jeera.config.default_user}!"
end
end
desc :close, 'Close issue'
def close(issue_key)
params = { fields: { status: { name: 'Closed' } } }
response = Jeera.client.post(issue_endpoint(issue_key), params)
if success_response? response
success_message "Issue #{response.body['key']} closed"
else
error_message "Could not close"
end
end
private
no_commands do
def issues_call(user = nil, project = nil)
user ||= current_user; project ||= current_project;
jql :user, user
jql :open
jql :default_sort
Jeera.client.get('search', jql_output)
end
def issues_obj(hash)
f = hash[:fields]
obj = {
key: hash['key'],
priority: f[:priority] ? f[:priority][:name] : '-',
summary: f[:summary].scan(/.{1,120}\b[\.),!"']*|.{1,120}/).join("\n"),
type: f[:issuetype][:name],
created: Time.parse(f[:created]).strftime('%b %d'),
status: f[:status] ? f[:status][:name] : 'Open',
}
obj[:priority] = print_priority(obj[:priority])
obj[:status] = print_status(obj[:status])
obj.values
rescue => err
error_message(err)
end
def issue_obj(hash)
f = hash[:fields]
obj = {
key: hash['key'],
priority: f[:priority] ? f[:priority][:name] : '-',
summary: f[:summary],
description: f[:description],
type: f[:issuetype][:name],
created: Time.parse(f[:created]).strftime('%b %d'),
status: f[:status] ? f[:status][:name] : 'Open',
assignee: f[:assignee][:displayName],
reporter: f[:reporter][:displayName],
comments: f[:comment],
labels: f[:labels],
}
obj[:priority] = print_priority(obj[:priority])
obj[:status] = print_status(obj[:status])
obj
rescue => err
error_message(err)
end
def (issue_hash)
info = [issue_hash[:key], issue_hash[:type], print_priority(issue_hash[:priority]), print_status(issue_hash[:status])]
[info.join(' | '), issue_hash[:summary], hr].join("\n")
end
def ()
return set_color('No comments', :cyan) unless [:total] > 0
sec = ['Comments', hr]
[:comments].each do |cmt|
sec << (cmt)
end
sec.join("\n")
end
def ()
time = Time.parse([:updated]).strftime('%b %d %H:%m')
author = set_color(" -- #{[:author][:name]}", :cyan)
byline = "#{author} | #{time}\n"
[[:body], byline].join("\n")
end
def issue_endpoint(issue_key)
"issue/#{issue_project_key(issue_key)}"
end
def issue_project_key(issue_key)
issue_key.split('-').length > 1 ? issue_key : [current_project, issue_key].join('-')
end
def browse_issue_url(issue_key)
"https://#{Jeera.config.jira_subdomain}.jira.com/browse/#{issue_project_key(issue_key)}"
end
end
end
end
|