bl 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bl/cli.rb +231 -0
  3. data/lib/bl/version.rb +1 -1
  4. data/lib/bl.rb +1 -214
  5. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4849acf6c4e7e7b614fa57e7bb68c219737dda0
4
- data.tar.gz: cb738cbabe30720d90087352a0e002ebc1a21b2c
3
+ metadata.gz: 05929705cfeb4bb0b2d8081fe236ff73d00a55d4
4
+ data.tar.gz: 514ae353673887ab472968aebe17ea2dc8aba93a
5
5
  SHA512:
6
- metadata.gz: 11df83881fe18fa616880a4c37c15dc4c9c03c3e4caf84557e9e6c81be474e637b9412df0ccd1b71a0b3b23c305d9472389232eb729295891a564185d4602888
7
- data.tar.gz: 1ca37ce7e5f1a4e5571faa981bc5c2b73dd6e924dbe2aa3ea1122b194b2a41e4308eff0408df73654973d4ea502e343986fafb8cd760ebb444dfb430ab937052
6
+ metadata.gz: 9e6e414c940720b6b2f5d5f257fedc5c8732d9535a9ca9e440c765fbf315280480b2bc619263d306c722ffa669d2c4d856b13e854268a8bef4a5390af9d9e37c
7
+ data.tar.gz: 076459e8c629cda6d62f827e3b63058d516837a2b05016e3d4393c78dc0686531150f7e37cedd83e8d44d097af643f224d2eb46f4d685f1214c2c3f7b780bbf8
data/lib/bl/cli.rb ADDED
@@ -0,0 +1,231 @@
1
+ module Bl
2
+ CONFIG_FILE = '.bl.yml'
3
+
4
+ class CLI < Thor
5
+ def initialize(*)
6
+ @config = YAML.load_file(File.join(Dir.home, Bl::CONFIG_FILE))
7
+ @client = BacklogKit::Client.new(
8
+ space_id: @config[:space_id],
9
+ api_key: @config[:api_key]
10
+ )
11
+ super
12
+ end
13
+
14
+ desc 'version', 'show version'
15
+ def version
16
+ puts Bl::VERSION
17
+ end
18
+
19
+ desc 'config', 'show config'
20
+ def config
21
+ puts @config
22
+ end
23
+
24
+ desc 'init', 'initialize a default config file'
25
+ def init
26
+ filename = File.join(Dir.home, Bl::CONFIG_FILE)
27
+ if File.exist?(filename)
28
+ puts "#{filename} exits."
29
+ else
30
+ config = {
31
+ space_id: '',
32
+ api_key: '',
33
+ project_key: '',
34
+ issue: {
35
+ default_project_id: '',
36
+ default_issue_type_id: '',
37
+ default_priority_id: ''
38
+ }
39
+ }
40
+ f = File.new(filename, 'w')
41
+ f.write(config.to_yaml)
42
+ puts "#{filename} generated."
43
+ end
44
+ end
45
+
46
+ desc 'count', 'count issues'
47
+ def count
48
+ puts @client.get('issues/count').body.count
49
+ end
50
+
51
+ desc 'list', 'list issues'
52
+ option :all, type: :boolean
53
+ option :assigneeId, type: :array
54
+ def list
55
+ opts = {}
56
+ if options[:all]
57
+ else
58
+ opts[:statusId] = [1, 2, 3]
59
+ end
60
+ @client.get('issues', opts.merge(options)).body.each do |i|
61
+ puts [
62
+ i.issueType.name,
63
+ i.issueKey,
64
+ i.summary,
65
+ i.priority.name,
66
+ i.created,
67
+ i.dueDate,
68
+ i.updated,
69
+ i.createdUser.name,
70
+ i.assignee&.name,
71
+ i.status.name
72
+ ].join("\t")
73
+ end
74
+ end
75
+
76
+ desc 'search', 'search issues'
77
+ option :keyword
78
+ option :categoryId, type: :array
79
+ option :assigneeId, type: :array
80
+ def search
81
+ @client.get('issues', options.to_h).body.each do |i|
82
+ puts [
83
+ i.issueType.name,
84
+ i.issueKey,
85
+ i.summary,
86
+ i.priority.name,
87
+ i.created,
88
+ i.dueDate,
89
+ i.updated,
90
+ i.createdUser.name,
91
+ i.assignee&.name,
92
+ i.status.name
93
+ ].join("\t")
94
+ end
95
+ end
96
+
97
+ desc 'show KEY', "show an issue's details"
98
+ def show(key)
99
+ i = @client.get("issues/#{key}")
100
+ str = i.body.pretty_inspect
101
+ puts str
102
+ end
103
+
104
+ desc 'browse KEY', 'browse an issue'
105
+ def browse(key)
106
+ url = 'https://' + @config[:space_id] + '.backlog.jp/view/' + key
107
+ system("open #{url}")
108
+ end
109
+
110
+ desc 'add *SUBJECTS', 'add issues'
111
+ option :description, type: :string
112
+ option :issueTypeId, type: :numeric
113
+ option :categoryId, type: :array
114
+ option :versionId, type: :array
115
+ option :milestoneId, type: :array
116
+ option :priorityId, type: :numeric
117
+ # TODO: status
118
+ # TODO: resolution
119
+ option :assigneeId, type: :numeric
120
+ def add(*subjects)
121
+ subjects.each do |s|
122
+ base_options = {
123
+ projectId: @config[:issue][:default_project_id].to_i,
124
+ summary: s,
125
+ issueTypeId: @config[:issue][:default_issue_type_id].to_i,
126
+ priorityId: @config[:issue][:default_priority_id].to_i
127
+ }
128
+ res = @client.post(
129
+ 'issues',
130
+ base_options.merge(options)
131
+ )
132
+ puts "issue added: #{res.body.issueKey}\t#{res.body.summary}"
133
+ end
134
+ end
135
+
136
+ desc 'update KEY', 'update an issue'
137
+ option :summary, type: :string
138
+ option :description, type: :string
139
+ option :issueTypeId, type: :numeric
140
+ option :categoryId, type: :array
141
+ option :versionId, type: :array
142
+ option :milestoneId, type: :array
143
+ option :priorityId, type: :numeric
144
+ # TODO: status
145
+ # TODO: resolution
146
+ option :assigneeId, type: :numeric
147
+ def update(key)
148
+ res = @client.patch("issues/#{key}", options.to_h)
149
+ puts "issue updated: #{res.body.issueKey}\t#{res.body.summary}"
150
+ end
151
+
152
+ desc 'close *KEYS', 'close issues'
153
+ def close(*keys)
154
+ keys.each do |k|
155
+ res = @client.patch("issues/#{k}", statusId: 4)
156
+ puts "issue closed: #{res.body.issueKey}\t#{res.body.summary}"
157
+ end
158
+ end
159
+
160
+ desc 'projects', 'list projects'
161
+ def projects
162
+ @client.get('projects').body.each do |p|
163
+ puts [p.id, p.projectKey, p.name].join("\t")
164
+ end
165
+ end
166
+
167
+ desc 'types', 'list issue types'
168
+ def types
169
+ @client.get("projects/#{@config[:project_key]}/issueTypes").body.each do |t|
170
+ puts [t.id, t.name].join("\t")
171
+ end
172
+ end
173
+
174
+ desc 'milestones', 'list milestones'
175
+ def milestones
176
+ @client.get("projects/#{@config[:project_key]}/versions").body.each do |v|
177
+ puts [
178
+ v.id,
179
+ v.projectId,
180
+ v.name,
181
+ v.description,
182
+ v.startDate,
183
+ v.releaseDueDate,
184
+ v.archived
185
+ ].join("\t")
186
+ end
187
+ end
188
+
189
+ desc 'categories', 'list issue categories'
190
+ def categories
191
+ @client.get("projects/#{@config[:project_key]}/categories").body.each do |c|
192
+ puts [c.id, c.name].join("\t")
193
+ end
194
+ end
195
+
196
+ desc 'statuses', 'list statuses'
197
+ def statuses
198
+ @client.get('statuses').body.each do |s|
199
+ puts [s.id, s.name].join("\t")
200
+ end
201
+ end
202
+
203
+ desc 'priorities', 'list priorities'
204
+ def priorities
205
+ @client.get('priorities').body.each do |p|
206
+ puts [p.id, p.name].join("\t")
207
+ end
208
+ end
209
+
210
+ desc 'resolutions', 'list resolutions'
211
+ def resolutions
212
+ @client.get('resolutions').body.each do |r|
213
+ puts [r.id, r.name].join("\t")
214
+ end
215
+ end
216
+
217
+ desc 'users', 'list space users'
218
+ def users
219
+ @client.get('users').body.each do |u|
220
+ puts [u.id, u.userId, u.name, u.roleType, u.lang, u.mailAddress].join("\t")
221
+ end
222
+ end
223
+
224
+ desc 'activities', 'list activities'
225
+ def activities
226
+ @client.get('/space/activities').body.each do |a|
227
+ puts a.pretty_inspect
228
+ end
229
+ end
230
+ end
231
+ end
data/lib/bl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bl
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/bl.rb CHANGED
@@ -3,219 +3,6 @@ require 'backlog_kit'
3
3
  require 'bl/version'
4
4
  require 'yaml'
5
5
  require 'pp'
6
-
7
- module Bl
8
- CONFIG_FILE = '.bl.yml'
9
-
10
- class CLI < Thor
11
- @@config = YAML.load_file(File.join(Dir.home, CONFIG_FILE))
12
-
13
- desc 'version', 'show version'
14
- def version
15
- puts Bl::VERSION
16
- end
17
-
18
- desc 'config', 'show config'
19
- def config
20
- puts @@config
21
- end
22
-
23
- desc 'init', 'initialize a default config file'
24
- def init
25
- filename = File.join(Dir.home, CONFIG_FILE)
26
- if File.exist?(filename)
27
- puts "#{filename} exits."
28
- else
29
- config = {
30
- space_id: '',
31
- api_key: '',
32
- project_key: '',
33
- issue: {
34
- default_project_id: '',
35
- default_issue_type_id: '',
36
- default_priority_id: ''
37
- }
38
- }
39
- f = File.new(filename, 'w')
40
- f.write(config.to_yaml)
41
- puts "#{filename} generated."
42
- end
43
- end
44
-
45
- desc 'count', 'count issues'
46
- def count
47
- puts Bl::CLI.client.get('issues/count').body.count
48
- end
49
-
50
- desc 'list', 'list issues'
51
- option :all, type: :boolean
52
- option :assigneeId, type: :array
53
- def list
54
- opts = {}
55
- if options[:all]
56
- else
57
- opts[:statusId] = [1, 2, 3]
58
- end
59
- Bl::CLI.client.get('issues', opts.merge(options)).body.each do |i|
60
- puts [
61
- i.issueType.name,
62
- i.issueKey,
63
- i.summary,
64
- i.priority.name,
65
- i.created,
66
- i.dueDate,
67
- i.updated,
68
- i.createdUser.name,
69
- i.assignee&.name,
70
- i.status.name
71
- ].join("\t")
72
- end
73
- end
74
-
75
- desc 'search', 'search issues'
76
- option :keyword
77
- option :categoryId, type: :array
78
- option :assigneeId, type: :array
79
- def search
80
- Bl::CLI.client.get('issues', options.to_h).body.each do |i|
81
- puts [
82
- i.issueType.name,
83
- i.issueKey,
84
- i.summary,
85
- i.priority.name,
86
- i.created,
87
- i.dueDate,
88
- i.updated,
89
- i.createdUser.name,
90
- i.assignee&.name,
91
- i.status.name
92
- ].join("\t")
93
- end
94
- end
95
-
96
- desc 'show KEY', "show an issue's details"
97
- def show(key)
98
- i = Bl::CLI.client.get("issues/#{key}")
99
- str = i.body.pretty_inspect
100
- puts str
101
- end
102
-
103
- desc 'browse KEY', 'browse an issue'
104
- def browse(key)
105
- url = 'https://' + @@config[:space_id] + '.backlog.jp/view/' + key
106
- system("open #{url}")
107
- end
108
-
109
- desc 'add SUBJECT', 'add an issue'
110
- option :description, type: :string
111
- option :issueTypeId, type: :numeric
112
- option :categoryId, type: :array
113
- option :versionId, type: :array
114
- option :milestoneId, type: :array
115
- option :priorityId, type: :numeric
116
- # TODO: status
117
- # TODO: resolution
118
- option :assigneeId, type: :numeric
119
- def add(subject)
120
- base_options = {
121
- projectId: @@config[:issue][:default_project_id].to_i,
122
- summary: subject,
123
- issueTypeId: @@config[:issue][:default_issue_type_id].to_i,
124
- priorityId: @@config[:issue][:default_priority_id].to_i
125
- }
126
- res = Bl::CLI.client.post(
127
- 'issues',
128
- base_options.merge(options)
129
- )
130
- puts "issue added: #{res.body.issueKey}\t#{res.body.summary}"
131
- end
132
-
133
- desc 'update KEY', 'update an issue'
134
- option :summary, type: :string
135
- option :description, type: :string
136
- option :issueTypeId, type: :numeric
137
- option :categoryId, type: :array
138
- option :versionId, type: :array
139
- option :milestoneId, type: :array
140
- option :priorityId, type: :numeric
141
- # TODO: status
142
- # TODO: resolution
143
- option :assigneeId, type: :numeric
144
- def update(key)
145
- res = Bl::CLI.client.patch("issues/#{key}", options.to_h)
146
- puts "issue updated: #{res.body.issueKey}\t#{res.body.summary}"
147
- end
148
-
149
- desc 'close KEY', 'close an issue'
150
- def close(key)
151
- Bl::CLI.client.patch("issues/#{key}", statusId: 4)
152
- issue = Bl::CLI.client.get("issues/#{key}")
153
- puts "issue closed: #{issue.body.issueKey}\t#{issue.body.summary}"
154
- end
155
-
156
- desc 'projects', 'list projects'
157
- def projects
158
- Bl::CLI.client.get('projects').body.each do |p|
159
- puts [p.id, p.projectKey, p.name].join("\t")
160
- end
161
- end
162
-
163
- desc 'types', 'list issue types'
164
- def types
165
- Bl::CLI.client.get("projects/#{@@config[:project_key]}/issueTypes").body.each do |t|
166
- puts [t.id, t.name].join("\t")
167
- end
168
- end
169
-
170
- desc 'categories', 'list issue categories'
171
- def categories
172
- Bl::CLI.client.get("projects/#{@@config[:project_key]}/categories").body.each do |c|
173
- puts [c.id, c.name].join("\t")
174
- end
175
- end
176
-
177
- desc 'statuses', 'list statuses'
178
- def statuses
179
- Bl::CLI.client.get('statuses').body.each do |s|
180
- puts [s.id, s.name].join("\t")
181
- end
182
- end
183
-
184
- desc 'priorities', 'list priorities'
185
- def priorities
186
- Bl::CLI.client.get('priorities').body.each do |p|
187
- puts [p.id, p.name].join("\t")
188
- end
189
- end
190
-
191
- desc 'resolutions', 'list resolutions'
192
- def resolutions
193
- Bl::CLI.client.get('resolutions').body.each do |r|
194
- puts [r.id, r.name].join("\t")
195
- end
196
- end
197
-
198
- desc 'users', 'list space users'
199
- def users
200
- Bl::CLI.client.get('users').body.each do |u|
201
- puts [u.id, u.userId, u.name, u.roleType, u.lang, u.mailAddress].join("\t")
202
- end
203
- end
204
-
205
- desc 'activities', 'list activities'
206
- def activities
207
- Bl::CLI.client.get('/space/activities').body.each do |a|
208
- puts a.pretty_inspect
209
- end
210
- end
211
-
212
- def self.client
213
- BacklogKit::Client.new(
214
- space_id: @@config[:space_id],
215
- api_key: @@config[:api_key]
216
- )
217
- end
218
- end
219
- end
6
+ require 'bl/cli'
220
7
 
221
8
  Bl::CLI.start(ARGV)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - saki
@@ -127,6 +127,7 @@ files:
127
127
  - bl.gemspec
128
128
  - exe/bl
129
129
  - lib/bl.rb
130
+ - lib/bl/cli.rb
130
131
  - lib/bl/version.rb
131
132
  homepage: https://github.com/sakihet/bl
132
133
  licenses: