Class: Bl::CLI
- Inherits:
-
Thor
- Object
- Thor
- Bl::CLI
- Defined in:
- lib/bl.rb
Constant Summary collapse
- @@config =
YAML.load_file(File.join(Dir.home, CONFIG_FILE))
Class Method Summary collapse
Instance Method Summary collapse
- #add(subject) ⇒ Object
- #categories ⇒ Object
- #close(key) ⇒ Object
- #config ⇒ Object
- #count ⇒ Object
- #init ⇒ Object
- #list ⇒ Object
- #priorities ⇒ Object
- #projects ⇒ Object
- #resolutions ⇒ Object
- #search ⇒ Object
- #show(key) ⇒ Object
- #statuses ⇒ Object
- #types ⇒ Object
- #users ⇒ Object
- #version ⇒ Object
Class Method Details
.client ⇒ Object
183 184 185 186 187 188 |
# File 'lib/bl.rb', line 183 def self.client BacklogKit::Client.new( space_id: @@config[:space_id], api_key: @@config[:api_key] ) end |
Instance Method Details
#add(subject) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/bl.rb', line 114 def add(subject) = { projectId: @@config[:issue][:default_project_id].to_i, summary: subject, issueTypeId: @@config[:issue][:default_issue_type_id].to_i, priorityId: @@config[:issue][:default_priority_id].to_i } Bl::CLI.client.post( "issues", .merge() ) end |
#categories ⇒ Object
149 150 151 152 153 |
# File 'lib/bl.rb', line 149 def categories categories = Bl::CLI.client.get("projects/#{@@config[:project_key]}/categories").body.each do |c| puts [c.id, c.name].join("\t") end end |
#close(key) ⇒ Object
128 129 130 131 132 |
# File 'lib/bl.rb', line 128 def close(key) Bl::CLI.client.patch("issues/#{key}", statusId: 4) issue = Bl::CLI.client.get("issues/#{key}") puts "issue closed: #{issue.body.issueKey}\t#{issue.body.summary}" end |
#config ⇒ Object
19 20 21 |
# File 'lib/bl.rb', line 19 def config puts @@config end |
#count ⇒ Object
46 47 48 |
# File 'lib/bl.rb', line 46 def count puts Bl::CLI.client.get('issues/count').body.count end |
#init ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bl.rb', line 24 def init filename = File.join(Dir.home, CONFIG_FILE) if File.exists?(filename) puts "#{filename} exits." else config = { space_id: '', api_key: '', project_key: '', issue: { default_project_id: '', default_issue_type_id: '', default_priority_id: '' } } f = File.new(filename, 'w') f.write(config.to_yaml) puts "#{filename} generated." end end |
#list ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bl.rb', line 53 def list opts = {} if [:all] else opts[:statusId] = [1, 2, 3] end issues = Bl::CLI.client.get('issues', opts.merge()).body issues.each do |i| puts [ i.issueType.name, i.issueKey, i.summary, i.priority.name, i.created, i.dueDate, i.updated, i.createdUser.name, i.assignee&.name, i.status.name ].join("\t") end end |
#priorities ⇒ Object
163 164 165 166 167 |
# File 'lib/bl.rb', line 163 def priorities priorities = Bl::CLI.client.get("priorities").body.each do |p| puts [p.id, p.name].join("\t") end end |
#projects ⇒ Object
135 136 137 138 139 |
# File 'lib/bl.rb', line 135 def projects projects = Bl::CLI.client.get('projects').body.each do |p| puts [p.id, p.projectKey, p.name].join("\t") end end |
#resolutions ⇒ Object
170 171 172 173 174 |
# File 'lib/bl.rb', line 170 def resolutions resolutions = Bl::CLI.client.get("resolutions").body.each do |r| puts [r.id, r.name].join("\t") end end |
#search ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/bl.rb', line 80 def search issues = Bl::CLI.client.get('issues', .to_h).body.each do |i| puts [ i.issueType.name, i.issueKey, i.summary, i.priority.name, i.created, i.dueDate, i.updated, i.createdUser.name, i.assignee&.name, i.status.name ].join("\t") end end |
#show(key) ⇒ Object
98 99 100 101 102 |
# File 'lib/bl.rb', line 98 def show(key) i = Bl::CLI.client.get("issues/#{key}") str = i.body.pretty_inspect puts str end |
#statuses ⇒ Object
156 157 158 159 160 |
# File 'lib/bl.rb', line 156 def statuses statuses = Bl::CLI.client.get("statuses").body.each do |s| puts [s.id, s.name].join("\t") end end |
#types ⇒ Object
142 143 144 145 146 |
# File 'lib/bl.rb', line 142 def types types = Bl::CLI.client.get("projects/#{@@config[:project_key]}/issueTypes").body.each do |t| puts [t.id, t.name].join("\t") end end |
#users ⇒ Object
177 178 179 180 181 |
# File 'lib/bl.rb', line 177 def users users = Bl::CLI.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
14 15 16 |
# File 'lib/bl.rb', line 14 def version puts Bl::VERSION end |