Class: Bl::CLI
Constant Summary
collapse
- ISSUES_PARAMS =
{
projectId: :array,
issueTypeId: :array,
categoryId: :array,
versionId: :array,
milestoneId: :array,
statusId: :array,
priorityId: :array,
assigneeId: :array,
createdUserId: :array,
resolutionId: :array,
parentChild: :numeric,
attachment: :boolean,
sharedFile: :boolean,
sort: :string,
order: :string,
offset: :numeric,
count: :numeric,
createdSince: :string,
createUntil: :string,
updatedSince: :string,
updatedUntil: :string,
startDateSince: :string,
startDateUntil: :string,
dueDateSince: :string,
dueDateUntil: :string,
id: :array,
parentIssueId: :array,
keyword: :string
}
- ISSUE_BASE_ATTRIBUTES =
{
summary: :string,
description: :string,
statusId: :numeric,
resolutionId: :numeric,
dueDate: :string,
issueTypeId: :numeric,
categoryId: :array,
versionId: :array,
milestoneId: :array,
priorityId: :numeric,
assigneeId: :numeric
}
- ACTIVITY_TYPES =
{
1 => 'Issue Created',
2 => 'Issue Updated',
3 => 'Issue Commented',
4 => 'Issue Deleted',
5 => 'Wiki Created',
6 => 'Wiki Updated',
7 => 'Wiki Deleted',
8 => 'File Added',
9 => 'File Updated',
10 => 'File Deleted',
11 => 'SVN Committed',
12 => 'Git Pushed',
13 => 'Git Repository Created',
14 => 'Issue Multi Updated',
15 => 'Project User Added',
16 => 'Project User Deleted',
17 => 'Comment Notification Added',
18 => 'Pull Request Added',
19 => 'Pull Request Updated',
20 => 'Comment Added on Pull Request'
}
Instance Method Summary
collapse
Methods included from Formatting
colorize_priority, colorize_status, colorize_type, print_issue
client
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
75
76
77
78
|
# File 'lib/bl/cli.rb', line 75
def initialize(*)
@config = Bl::Config.instance
super
end
|
Instance Method Details
#activities ⇒ Object
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/bl/cli.rb', line 251
def activities
client.get('/space/activities').body.each do |a|
puts [
ACTIVITY_TYPES[a.type],
a.content.inspect,
a.createdUser.name,
a.created
].join("\t")
end
end
|
#add(*subjects) ⇒ Object
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/bl/cli.rb', line 175
def add(*subjects)
subjects.each do |s|
issue_default_options = @config[:issue][:default]
res = client.post(
'issues',
issue_default_options.merge({summary: s}).merge(options)
)
puts "issue added: #{res.body.issueKey}\t#{res.body.summary}"
end
end
|
#browse(key) ⇒ Object
168
169
170
171
|
# File 'lib/bl/cli.rb', line 168
def browse(key)
url = 'https://' + @config[:space_id] + '.backlog.jp/view/' + key
system("open #{url}")
end
|
#close(*keys) ⇒ Object
197
198
199
200
201
202
|
# File 'lib/bl/cli.rb', line 197
def close(*keys)
keys.each do |k|
res = client.patch("issues/#{k}", statusId: 4)
puts "issue closed: #{res.body.issueKey}\t#{res.body.summary}"
end
end
|
#config ⇒ Object
86
87
88
|
# File 'lib/bl/cli.rb', line 86
def config
p @config
end
|
#count ⇒ Object
111
112
113
|
# File 'lib/bl/cli.rb', line 111
def count
puts client.get('issues/count', options.to_h).body.count
end
|
#doctor ⇒ Object
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
# File 'lib/bl/cli.rb', line 270
def doctor
unassigned_issues = client.get('issues', assigneeId: [-1]).body
overdue_issues = client.get(
'issues',
statusId: [1, 2, 3],
dueDateUntil: Date.today.to_s,
).body
unless unassigned_issues.empty?
puts 'warning: unassigned issues found.'
puts 'issues:'
unassigned_issues.map {|i| print_issue(i)}
end
unless overdue_issues.empty?
puts 'warning: overdue issues found.'
puts 'issues:'
overdue_issues.map {|i| print_issue(i)}
end
end
|
#edit(key) ⇒ Object
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/bl/cli.rb', line 205
def edit(key)
issue_description = client.get("issues/#{key}").body.description
file = Tempfile.new
file.puts(issue_description)
file.close
begin
file.open
system("$EDITOR #{file.path}")
new_content = file.read
client.patch("issues/#{key}", description: new_content)
puts "issue #{key} updated."
ensure
file.close
file.unlink
end
end
|
#init ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/bl/cli.rb', line 91
def init
filename = File.join(Dir.home, Bl::CONFIG_FILE)
if File.exist?(filename)
puts "#{filename} exits."
else
config = Bl::Config.instance.default_config
f = File.new(filename, 'w')
f.write(config.to_yaml)
puts "#{filename} generated."
end
end
|
#list ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/bl/cli.rb', line 122
def list
opts = {}
opts[:statusId] = [1, 2, 3] unless options[:all]
opts[:assigneeId] = [-1] if options[:unassigned]
if options[:today]
today = Date.today
opts[:dueDateSince] = today.to_s
opts[:dueDateUntil] = today.next.to_s
end
opts[:dueDateUntil] = Date.today.to_s if options[:overdue]
if options[:priority]
opts[:sort] = "priority"
opts[:order] = "asc"
end
opts[:categoryId] = [-1] if options[:nocategory]
client.get('issues', opts).body.map {|i| print_issue(i)}
end
|
#notifications ⇒ Object
263
264
265
266
267
|
# File 'lib/bl/cli.rb', line 263
def notifications
client.get('notifications').body.each do |n|
puts n.pretty_inspect
end
end
|
#priorities ⇒ Object
230
231
232
233
234
|
# File 'lib/bl/cli.rb', line 230
def priorities
client.get('priorities').body.each do |p|
puts [p.id, colorize_priority(p.id, p.name)].join("\t")
end
end
|
#resolutions ⇒ Object
237
238
239
240
241
|
# File 'lib/bl/cli.rb', line 237
def resolutions
client.get('resolutions').body.each do |r|
puts [r.id, r.name].join("\t")
end
end
|
#search ⇒ Object
142
143
144
|
# File 'lib/bl/cli.rb', line 142
def search
client.get('issues', options.to_h).body.map {|i| print_issue(i)}
end
|
#show(key) ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/bl/cli.rb', line 147
def show(key)
body = client.get("issues/#{key}").body
puts "type: #{body.issueType.name}"
puts "key: #{body.issueKey}"
puts "created: #{body.created}"
puts "due date: #{body.dueDate}"
puts "summary: #{body.summary}"
puts "priority: #{body.priority.name}"
puts "category: #{body.category}"
puts "resolution: #{body.resolution}"
puts "version: #{body.versions}"
puts "status: #{body.status.name}"
puts "milestone: #{body.milestone}"
puts "assignee: #{body.assignee.name}"
puts "created user: #{body.createdUser.name}"
puts '--'
puts "description:"
puts body.description
end
|
#space ⇒ Object
104
105
106
107
|
# File 'lib/bl/cli.rb', line 104
def space
res = client.get('space').body
puts res.inspect
end
|
#statuses ⇒ Object
223
224
225
226
227
|
# File 'lib/bl/cli.rb', line 223
def statuses
client.get('statuses').body.each do |s|
puts [s.id, colorize_status(s.id, s.name)].join("\t")
end
end
|
#update(*keys) ⇒ Object
189
190
191
192
193
194
|
# File 'lib/bl/cli.rb', line 189
def update(*keys)
keys.each do |k|
res = client.patch("issues/#{k}", options.to_h)
puts "issue updated: #{res.body.issueKey}\t#{res.body.summary}"
end
end
|
#users ⇒ Object
244
245
246
247
248
|
# File 'lib/bl/cli.rb', line 244
def users
client.get('users').body.each do |u|
puts [u.id, u.userId, u.name, u.roleType, u.lang, u.mailAddress].join("\t")
end
end
|
#version ⇒ Object
81
82
83
|
# File 'lib/bl/cli.rb', line 81
def version
puts Bl::VERSION
end
|