Class: Bl::CLI
Instance Method Summary
collapse
Methods included from Printer
print_response, printable_issues
client, formatter, request
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
3
4
5
6
|
# File 'lib/bl/cli.rb', line 3
def initialize(*)
@config = Bl::Config.instance
super
end
|
Instance Method Details
#browse(key) ⇒ Object
79
80
81
82
|
# File 'lib/bl/cli.rb', line 79
def browse(key)
url = 'https://' + @config[:space_id] + '.backlog.jp/view/' + key
system("open #{url}")
end
|
#config ⇒ Object
14
15
16
|
# File 'lib/bl/cli.rb', line 14
def config
p @config
end
|
#init ⇒ Object
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
|
# File 'lib/bl/cli.rb', line 19
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')
puts 'please input space name: '
space_id = STDIN.gets.chomp
puts 'plese input api key: '
api_key = STDIN.gets.chomp
config[:space_id] = space_id.to_s
config[:api_key] = api_key.to_s
client = BacklogKit::Client.new(
space_id: space_id,
api_key: api_key
)
res = client.get('projects')
project_key = res.body[0].projectKey
config[:project_key] = project_key
config[:issue][:default][:projectId] = res.body[0].id
res = client.get("projects/#{project_key}/issueTypes")
config[:issue][:default][:issueTypeId] = res.body[0].id
res = client.get('priorities')
config[:issue][:default][:priorityId] = res.body[1].id
f.write(config.to_yaml)
puts "#{filename} generated."
end
end
|
#priorities ⇒ Object
91
92
93
94
|
# File 'lib/bl/cli.rb', line 91
def priorities
res = request(:get, 'priorities')
print_response(res, :named)
end
|
#resolutions ⇒ Object
97
98
99
100
|
# File 'lib/bl/cli.rb', line 97
def resolutions
res = request(:get, 'resolutions')
print_response(res, :named)
end
|
#roles ⇒ Object
103
104
105
|
# File 'lib/bl/cli.rb', line 103
def roles
puts formatter.render(ROLES, fields: %i(id name))
end
|
#show(key) ⇒ Object
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
|
# File 'lib/bl/cli.rb', line 50
def show(key)
res = request(:get, "issues/#{key}")
body = printable_issues(res.body)
additional_fileds = %w(
description
category
resolution
versions
milestone
createdUser
)
fields = ISSUE_FIELDS.concat(additional_fileds)
puts formatter.render(body, fields: fields, vertical: true)
puts '--'
puts 'attachments:'
body[0].attachments.each do |file|
puts ['-', file.id, file.name, file.size].join("\t")
puts "\tview url: https://#{@config[:space_id]}.backlog.jp/ViewAttachment.action?attachmentId=#{file.id}"
puts "\tdownload url: https://#{@config[:space_id]}.backlog.jp/downloadAttachment/#{file.id}/#{file.name}"
end
puts 'shared files:'
body[0].sharedFiles.each do |file|
puts ['-', file.id, file.name, file.size].join("\t")
puts "\tfile url: https://#{@config[:space_id]}.backlog.jp/ViewSharedFile.action?projectKey=#{@config[:project_key]}&sharedFileId=#{file.id}"
end
end
|
#statuses ⇒ Object
85
86
87
88
|
# File 'lib/bl/cli.rb', line 85
def statuses
res = request(:get, 'statuses')
print_response(res, :named)
end
|
#version ⇒ Object
9
10
11
|
# File 'lib/bl/cli.rb', line 9
def version
puts Bl.gem_version
end
|