bl 0.5.11 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f561d7d01920939ff153cd28a4732f1a1c9103c
4
- data.tar.gz: e29a1f79d225eb012ed4fd1a2a423519b6717bbe
3
+ metadata.gz: 4d76c1fa3d3501015e87be05a03ff5b6fe694ad9
4
+ data.tar.gz: bd1d24d7fd6740ce1275aa2fcb269a43ea1f00bf
5
5
  SHA512:
6
- metadata.gz: 9aed15e68ccda4de5c0c9aee00a0729a516385fb0059195b14d01e1f24385b6c1ead803f857dbd029db0d365eb9cb40dbb1758bf11ab7ac6a12e811e26db558d
7
- data.tar.gz: ca472cc27a71fa58d5b88971713b33e89f519854ef7517a0454aa84ac2801532b90c089ad1a32ae150eca7b20d1e712c9931a1f17b911cca27934b592eb308d0
6
+ metadata.gz: cabd93779373d7a938b5d1c0be3bb1fee721a425af260417ed176eadbc663370e514e0f7e3663a18890375694d4537f55402bd80c51d54a66a48390ff3170311
7
+ data.tar.gz: 4f2121b52394a1a77b6457b3a51e80dc2b8b7d838e1983c5dd1101f4e2f239c4bf6f6719311f1e1ea7ecac64e7b4b72f09d349f8001b5e9845244fe18865706a
data/lib/bl.rb CHANGED
@@ -4,9 +4,11 @@ require 'backlog_kit'
4
4
  require 'paint'
5
5
  require 'thor'
6
6
  require 'bl/version'
7
+ require 'bl/constants'
7
8
  require 'bl/config'
8
9
  require 'bl/requestable'
9
10
  require 'bl/formatting'
11
+ require 'bl/printer'
10
12
  require 'bl/command'
11
13
  require 'bl/space'
12
14
  require 'bl/type'
@@ -9,14 +9,14 @@ module Bl
9
9
 
10
10
  desc 'list', 'list categories'
11
11
  def list
12
- res = client.get(@url)
12
+ res = request(:get, @url)
13
13
  print_response(res)
14
14
  end
15
15
 
16
16
  desc 'add [NAME...]', 'add categories'
17
17
  def add(*names)
18
18
  names.each do |name|
19
- res = client.post(@url, name: name)
19
+ res = request(:post, @url, name: name)
20
20
  puts 'category added'
21
21
  print_response(res)
22
22
  end
@@ -26,7 +26,7 @@ module Bl
26
26
  option :name, type: :string
27
27
  def update(*ids)
28
28
  ids.each do |id|
29
- res = client.patch("#{@url}/#{id}", delete_class_options(options))
29
+ res = request(:patch, "#{@url}/#{id}", delete_class_options(options))
30
30
  puts 'category updated'
31
31
  print_response(res)
32
32
  end
@@ -35,7 +35,7 @@ module Bl
35
35
  desc 'delete [ID...]', 'delete categories'
36
36
  def delete(*ids)
37
37
  ids.each do |id|
38
- res = client.delete("#{@url}/#{id}")
38
+ res = request(:delete, "#{@url}/#{id}")
39
39
  puts 'category deleted'
40
40
  print_response(res)
41
41
  end
@@ -35,13 +35,13 @@ module Bl
35
35
  space_id: space_id,
36
36
  api_key: api_key
37
37
  )
38
- res = client.get('projects')
38
+ res = request(:get, 'projects')
39
39
  project_key = res.body[0].projectKey
40
40
  config[:project_key] = project_key
41
41
  config[:issue][:default][:projectId] = res.body[0].id
42
- res = client.get("projects/#{project_key}/issueTypes")
42
+ res = request(:get, "projects/#{project_key}/issueTypes")
43
43
  config[:issue][:default][:issueTypeId] = res.body[0].id
44
- res = client.get('priorities')
44
+ res = request(:get, 'priorities')
45
45
  config[:issue][:default][:priorityId] = res.body[1].id
46
46
  f.write(config.to_yaml)
47
47
  puts "#{filename} generated."
@@ -51,7 +51,7 @@ module Bl
51
51
  desc 'count', 'count issues'
52
52
  options ISSUES_PARAMS
53
53
  def count
54
- puts client.get('issues/count', delete_class_options(options.to_h)).body.count
54
+ puts request(:get, 'issues/count', delete_class_options(options.to_h)).body.count
55
55
  end
56
56
 
57
57
  desc 'list', 'list issues by typical ways'
@@ -76,20 +76,20 @@ module Bl
76
76
  opts[:order] = "asc"
77
77
  end
78
78
  opts[:categoryId] = [-1] if options[:nocategory]
79
- res = client.get('issues', opts)
80
- print_issue_response(printable_issues(res.body))
79
+ res = request(:get, 'issues', opts)
80
+ print_response(res, :issue)
81
81
  end
82
82
 
83
83
  desc 'search', 'search issues'
84
84
  options ISSUES_PARAMS
85
85
  def search
86
- res = client.get('issues', delete_class_options(options.to_h))
87
- print_issue_response(printable_issues(res.body))
86
+ res = request(:get, 'issues', delete_class_options(options.to_h))
87
+ print_response(res, :issue)
88
88
  end
89
89
 
90
90
  desc 'show KEY', "show an issue's details"
91
91
  def show(key)
92
- res = client.get("issues/#{key}")
92
+ res = request(:get, "issues/#{key}")
93
93
  body = printable_issues(res.body)
94
94
  additional_fileds = %w(
95
95
  description
@@ -127,7 +127,7 @@ module Bl
127
127
  def add(*subjects)
128
128
  subjects.each do |s|
129
129
  issue_default_options = @config[:issue][:default]
130
- res = client.post(
130
+ res = request(:post,
131
131
  'issues',
132
132
  issue_default_options.merge({summary: s}).merge(delete_class_options(options.to_h))
133
133
  )
@@ -141,7 +141,7 @@ module Bl
141
141
  option :comment, type: :string
142
142
  def update(*keys)
143
143
  keys.each do |k|
144
- res = client.patch("issues/#{k}", delete_class_options(options.to_h))
144
+ res = request(:patch, "issues/#{k}", delete_class_options(options.to_h))
145
145
  puts 'issue updated'
146
146
  print_issue_response(printable_issues(res.body))
147
147
  end
@@ -150,7 +150,7 @@ module Bl
150
150
  desc 'close [KEY...]', 'close issues'
151
151
  def close(*keys)
152
152
  keys.each do |k|
153
- res = client.patch("issues/#{k}", statusId: 4)
153
+ res = request(:patch, "issues/#{k}", statusId: 4)
154
154
  puts '🎉 issue closed'
155
155
  print_issue_response(printable_issues(res.body))
156
156
  end
@@ -158,7 +158,7 @@ module Bl
158
158
 
159
159
  desc 'edit KEY', "edit issues' description by $EDITOR"
160
160
  def edit(key)
161
- issue_description = client.get("issues/#{key}").body.description
161
+ issue_description = request(:get, "issues/#{key}").body.description
162
162
  file = Tempfile.new
163
163
  file.puts(issue_description)
164
164
  file.close
@@ -166,7 +166,7 @@ module Bl
166
166
  file.open
167
167
  system("$EDITOR #{file.path}")
168
168
  new_content = file.read
169
- client.patch("issues/#{key}", description: new_content)
169
+ request(:patch, "issues/#{key}", description: new_content)
170
170
  puts "issue #{key} updated."
171
171
  ensure
172
172
  file.close
@@ -176,20 +176,20 @@ module Bl
176
176
 
177
177
  desc 'statuses', 'list statuses'
178
178
  def statuses
179
- res = client.get('statuses')
180
- puts formatter.render(res.body, fields: %i(id name))
179
+ res = request(:get, 'statuses')
180
+ print_response(res, :named)
181
181
  end
182
182
 
183
183
  desc 'priorities', 'list priorities'
184
184
  def priorities
185
- res = client.get('priorities')
186
- puts formatter.render(res.body, fields: %i(id name))
185
+ res = request(:get, 'priorities')
186
+ print_response(res, :named)
187
187
  end
188
188
 
189
189
  desc 'resolutions', 'list resolutions'
190
190
  def resolutions
191
- res = client.get('resolutions')
192
- puts formatter.render(res.body, fields: %i(id name))
191
+ res = request(:get, 'resolutions')
192
+ print_response(res, :named)
193
193
  end
194
194
 
195
195
  desc 'roles', 'list roles'
@@ -239,23 +239,5 @@ module Bl
239
239
  desc 'wiki SUBCOMMAND ...ARGS', 'manage wikis'
240
240
  subcommand 'wiki', Wiki
241
241
 
242
- private
243
-
244
- def print_issue_response(res)
245
- puts formatter.render(res, fields: ISSUE_FIELDS)
246
- end
247
-
248
- def printable_issues(ary)
249
- ary = Array(ary)
250
- ary.each do |v|
251
- v.issueType = v.issueType.name
252
- v.assignee = v.assignee.name if v.assignee
253
- v.status = v.status.name
254
- v.priority = v.priority.name
255
- v.created = format_datetime(v.created)
256
- v.updated = format_datetime(v.updated)
257
- end
258
- ary
259
- end
260
242
  end
261
243
  end
@@ -2,204 +2,9 @@ module Bl
2
2
  class Command < Thor
3
3
  include Bl::Requestable
4
4
  include Bl::Formatting
5
+ include Bl::Printer
5
6
  class_option :format, type: :string, default: 'table', desc: 'set output format'
6
7
 
7
- ACTIVITY_TYPES = {
8
- 1 => 'Issue Created',
9
- 2 => 'Issue Updated',
10
- 3 => 'Issue Commented',
11
- 4 => 'Issue Deleted',
12
- 5 => 'Wiki Created',
13
- 6 => 'Wiki Updated',
14
- 7 => 'Wiki Deleted',
15
- 8 => 'File Added',
16
- 9 => 'File Updated',
17
- 10 => 'File Deleted',
18
- 11 => 'SVN Committed',
19
- 12 => 'Git Pushed',
20
- 13 => 'Git Repository Created',
21
- 14 => 'Issue Multi Updated',
22
- 15 => 'Project User Added',
23
- 16 => 'Project User Deleted',
24
- 17 => 'Comment Notification Added',
25
- 18 => 'Pull Request Added',
26
- 19 => 'Pull Request Updated',
27
- 20 => 'Comment Added on Pull Request'
28
- }
29
- CATEGORY_FIELDS = %i(id name displayOrder)
30
- FILE_FIELDS = %i(id type dir name size created updated)
31
- GIT_REPO_FIELDS = %i(
32
- id
33
- projectId
34
- name
35
- sshUrl
36
- pushedAt
37
- created
38
- updated
39
- )
40
- ISSUE_BASE_ATTRIBUTES = {
41
- summary: :string,
42
- parentIssueId: :numeric,
43
- description: :string,
44
- statusId: :numeric,
45
- resolutionId: :numeric,
46
- dueDate: :string,
47
- issueTypeId: :numeric,
48
- categoryId: :array,
49
- versionId: :array,
50
- milestoneId: :array,
51
- priorityId: :numeric,
52
- assigneeId: :numeric
53
- }
54
- ISSUE_FIELDS = %i(
55
- issueType
56
- issueKey
57
- summary
58
- assignee
59
- status
60
- priority
61
- startDate
62
- dueDate
63
- created
64
- updated
65
- )
66
- ISSUES_PARAMS = {
67
- projectId: :array,
68
- issueTypeId: :array,
69
- categoryId: :array,
70
- versionId: :array,
71
- milestoneId: :array,
72
- statusId: :array,
73
- priorityId: :array,
74
- assigneeId: :array,
75
- createdUserId: :array,
76
- resolutionId: :array,
77
- parentChild: :numeric,
78
- attachment: :boolean,
79
- sharedFile: :boolean,
80
- sort: :string,
81
- order: :string,
82
- offset: :numeric,
83
- count: :numeric,
84
- createdSince: :string,
85
- createUntil: :string,
86
- updatedSince: :string,
87
- updatedUntil: :string,
88
- startDateSince: :string,
89
- startDateUntil: :string,
90
- dueDateSince: :string,
91
- dueDateUntil: :string,
92
- id: :array,
93
- parentIssueId: :array,
94
- keyword: :string
95
- }
96
- MILESTONE_FIELDS = %i(id projectId name description startDate releaseDueDate archived)
97
- MILESTONE_PARAMS = {
98
- description: :string,
99
- startDate: :string,
100
- releaseDueDate: :string
101
- }
102
- PROJECT_FIELDS = %i(
103
- id
104
- projectKey
105
- name
106
- chartEnabled
107
- subtaskingEnabled
108
- projectLeaderCanEditProjectLeader
109
- textFormattingRule
110
- archived
111
- )
112
- PROJECT_PARAMS = {
113
- name: :string,
114
- key: :string,
115
- chartEnabled: :boolean,
116
- projectLeaderCanEditProjectLeader: :boolean,
117
- subtaskingEnabled: :boolean,
118
- textFormattingRule: :boolean
119
- }
120
- ROLES = [
121
- {id: 1, name: 'Administrator'},
122
- {id: 2, name: 'Normal User'},
123
- {id: 3, name: 'Reporter'},
124
- {id: 4, name: 'Viewer'},
125
- {id: 5, name: 'Guest Reporter'},
126
- {id: 6, name: 'Guest Viewer'}
127
- ]
128
- SPACE_DISK_USAGE = %i(
129
- capacity
130
- issue
131
- wiki
132
- file
133
- subversion
134
- git
135
- )
136
- SPACE_DISK_USAGE_DETAILS_FIELDS = %i(
137
- projectId
138
- issue
139
- wiki
140
- file
141
- subversion
142
- git
143
- )
144
- SPACE_FIELDS = %i(
145
- spaceKey
146
- name
147
- ownerId
148
- lang
149
- timezone
150
- reportSendTime
151
- textFormattingRule
152
- created
153
- updated
154
- )
155
- SPACE_NOTIFICATION_FIELDS = %i(
156
- content
157
- updated
158
- )
159
- TYPE_COLORS = %w(
160
- #e30000
161
- #934981
162
- #814fbc
163
- #007e9a
164
- #ff3265
165
- #666665
166
- #990000
167
- #2779ca
168
- #7ea800
169
- #ff9200
170
- )
171
- USER_FIELDS = %i(
172
- id
173
- userId
174
- name
175
- roleType
176
- lang
177
- mailAddress
178
- )
179
- USER_PARAMS = {
180
- password: :string,
181
- name: :string,
182
- mailAddress: :string,
183
- roleType: :numeric
184
- }
185
- WATCHINGS_PARAMS = {
186
- order: :string,
187
- sort: :string,
188
- count: :numeric,
189
- offset: :numeric,
190
- resourceAlreadyRead: :boolean,
191
- issueId: :array
192
- }
193
- WEBHOOK_FIELDS = %i(id name description created updated)
194
- WEBHOOK_PARAMS = {
195
- name: :string,
196
- description: :string,
197
- hookUrl: :string,
198
- allEvent: :boolean,
199
- activityTypeIds: :array
200
- }
201
- WIKI_FIELDS = %i(id projectId name created updated)
202
-
203
8
  protected
204
9
 
205
10
  def delete_class_options(h)
@@ -209,7 +14,11 @@ module Bl
209
14
  end
210
15
 
211
16
  def format_datetime(str)
212
- DateTime.parse(str).strftime('%Y-%m-%d %H:%M')
17
+ DateTime.parse(str).strftime('%Y-%m-%d %H:%M') if str
18
+ end
19
+
20
+ def format_date(str)
21
+ Date.parse(str).strftime('%Y-%m-%d') if str
213
22
  end
214
23
  end
215
24
  end
@@ -0,0 +1,197 @@
1
+ module Bl
2
+ ACTIVITY_TYPES = {
3
+ 1 => 'Issue Created',
4
+ 2 => 'Issue Updated',
5
+ 3 => 'Issue Commented',
6
+ 4 => 'Issue Deleted',
7
+ 5 => 'Wiki Created',
8
+ 6 => 'Wiki Updated',
9
+ 7 => 'Wiki Deleted',
10
+ 8 => 'File Added',
11
+ 9 => 'File Updated',
12
+ 10 => 'File Deleted',
13
+ 11 => 'SVN Committed',
14
+ 12 => 'Git Pushed',
15
+ 13 => 'Git Repository Created',
16
+ 14 => 'Issue Multi Updated',
17
+ 15 => 'Project User Added',
18
+ 16 => 'Project User Deleted',
19
+ 17 => 'Comment Notification Added',
20
+ 18 => 'Pull Request Added',
21
+ 19 => 'Pull Request Updated',
22
+ 20 => 'Comment Added on Pull Request'
23
+ }
24
+ CATEGORY_FIELDS = %i(id name displayOrder)
25
+ FILE_FIELDS = %i(id type dir name size created updated)
26
+ GIT_REPO_FIELDS = %i(
27
+ id
28
+ projectId
29
+ name
30
+ sshUrl
31
+ pushedAt
32
+ created
33
+ updated
34
+ )
35
+ ISSUE_BASE_ATTRIBUTES = {
36
+ summary: :string,
37
+ parentIssueId: :numeric,
38
+ description: :string,
39
+ statusId: :numeric,
40
+ resolutionId: :numeric,
41
+ dueDate: :string,
42
+ issueTypeId: :numeric,
43
+ categoryId: :array,
44
+ versionId: :array,
45
+ milestoneId: :array,
46
+ priorityId: :numeric,
47
+ assigneeId: :numeric
48
+ }
49
+ ISSUE_FIELDS = %i(
50
+ issueType
51
+ issueKey
52
+ summary
53
+ assignee
54
+ status
55
+ priority
56
+ startDate
57
+ dueDate
58
+ created
59
+ updated
60
+ )
61
+ ISSUES_PARAMS = {
62
+ projectId: :array,
63
+ issueTypeId: :array,
64
+ categoryId: :array,
65
+ versionId: :array,
66
+ milestoneId: :array,
67
+ statusId: :array,
68
+ priorityId: :array,
69
+ assigneeId: :array,
70
+ createdUserId: :array,
71
+ resolutionId: :array,
72
+ parentChild: :numeric,
73
+ attachment: :boolean,
74
+ sharedFile: :boolean,
75
+ sort: :string,
76
+ order: :string,
77
+ offset: :numeric,
78
+ count: :numeric,
79
+ createdSince: :string,
80
+ createUntil: :string,
81
+ updatedSince: :string,
82
+ updatedUntil: :string,
83
+ startDateSince: :string,
84
+ startDateUntil: :string,
85
+ dueDateSince: :string,
86
+ dueDateUntil: :string,
87
+ id: :array,
88
+ parentIssueId: :array,
89
+ keyword: :string
90
+ }
91
+ MILESTONE_FIELDS = %i(id projectId name description startDate releaseDueDate archived)
92
+ MILESTONE_PARAMS = {
93
+ description: :string,
94
+ startDate: :string,
95
+ releaseDueDate: :string
96
+ }
97
+ PROJECT_FIELDS = %i(
98
+ id
99
+ projectKey
100
+ name
101
+ chartEnabled
102
+ subtaskingEnabled
103
+ projectLeaderCanEditProjectLeader
104
+ textFormattingRule
105
+ archived
106
+ )
107
+ PROJECT_PARAMS = {
108
+ name: :string,
109
+ key: :string,
110
+ chartEnabled: :boolean,
111
+ projectLeaderCanEditProjectLeader: :boolean,
112
+ subtaskingEnabled: :boolean,
113
+ textFormattingRule: :boolean
114
+ }
115
+ ROLES = [
116
+ {id: 1, name: 'Administrator'},
117
+ {id: 2, name: 'Normal User'},
118
+ {id: 3, name: 'Reporter'},
119
+ {id: 4, name: 'Viewer'},
120
+ {id: 5, name: 'Guest Reporter'},
121
+ {id: 6, name: 'Guest Viewer'}
122
+ ]
123
+ SPACE_DISK_USAGE = %i(
124
+ capacity
125
+ issue
126
+ wiki
127
+ file
128
+ subversion
129
+ git
130
+ )
131
+ SPACE_DISK_USAGE_DETAILS_FIELDS = %i(
132
+ projectId
133
+ issue
134
+ wiki
135
+ file
136
+ subversion
137
+ git
138
+ )
139
+ SPACE_FIELDS = %i(
140
+ spaceKey
141
+ name
142
+ ownerId
143
+ lang
144
+ timezone
145
+ reportSendTime
146
+ textFormattingRule
147
+ created
148
+ updated
149
+ )
150
+ SPACE_NOTIFICATION_FIELDS = %i(
151
+ content
152
+ updated
153
+ )
154
+ TYPE_COLORS = %w(
155
+ #e30000
156
+ #934981
157
+ #814fbc
158
+ #007e9a
159
+ #ff3265
160
+ #666665
161
+ #990000
162
+ #2779ca
163
+ #7ea800
164
+ #ff9200
165
+ )
166
+ USER_FIELDS = %i(
167
+ id
168
+ userId
169
+ name
170
+ roleType
171
+ lang
172
+ mailAddress
173
+ )
174
+ USER_PARAMS = {
175
+ password: :string,
176
+ name: :string,
177
+ mailAddress: :string,
178
+ roleType: :numeric
179
+ }
180
+ WATCHINGS_PARAMS = {
181
+ order: :string,
182
+ sort: :string,
183
+ count: :numeric,
184
+ offset: :numeric,
185
+ resourceAlreadyRead: :boolean,
186
+ issueId: :array
187
+ }
188
+ WEBHOOK_FIELDS = %i(id name description created updated)
189
+ WEBHOOK_PARAMS = {
190
+ name: :string,
191
+ description: :string,
192
+ hookUrl: :string,
193
+ allEvent: :boolean,
194
+ activityTypeIds: :array
195
+ }
196
+ WIKI_FIELDS = %i(id projectId name created updated)
197
+ end
@@ -8,14 +8,14 @@ module Bl
8
8
 
9
9
  desc 'list PATH', 'list files on PATH'
10
10
  def list(path = '')
11
- res = client.get("#{@url}/files/metadata/#{path}")
11
+ res = request(:get, "#{@url}/files/metadata/#{path}")
12
12
  print_response(res)
13
13
  end
14
14
 
15
15
  desc 'get [ID...]', 'get files'
16
16
  def get(*ids)
17
17
  ids.each do |id|
18
- res = client.get("#{@url}/files/#{id}")
18
+ res = request(:get, "#{@url}/files/#{id}")
19
19
  f = ::File.new(res.body.filename, 'w')
20
20
  f.write(res.body.content)
21
21
  f.close
@@ -9,13 +9,13 @@ module Bl
9
9
 
10
10
  desc 'list', 'list git repositories'
11
11
  def list
12
- res = client.get(@url)
12
+ res = request(:get, @url)
13
13
  print_response(res)
14
14
  end
15
15
 
16
16
  desc 'show ID', 'show a git repository'
17
17
  def show(id)
18
- res = client.get("#{@url}/#{id}")
18
+ res = request(:get, "#{@url}/#{id}")
19
19
  puts formatter.render(res.body, fields: GIT_REPO_FIELDS, vertical: true)
20
20
  end
21
21
 
@@ -10,20 +10,20 @@ module Bl
10
10
  desc 'list', ''
11
11
  options order: :string, offset: :numeric, count: :numeric
12
12
  def list
13
- res = client.get(@url, options.to_h)
13
+ res = request(:get, @url, options.to_h)
14
14
  puts formatter.render(res.body, fields: %i(id name))
15
15
  end
16
16
 
17
17
  desc 'show GROUP_ID', ''
18
18
  def show(id)
19
- res = client.get("#{@url}/#{id}")
19
+ res = request(:get, "#{@url}/#{id}")
20
20
  puts formatter.render(res.body.members, fields: USER_FIELDS)
21
21
  end
22
22
 
23
23
  desc 'add GROUP_NAME', ''
24
24
  options members: :array
25
25
  def add(name)
26
- res = client.post(@url, {name: name}.merge(delete_class_options(options)))
26
+ res = request(:post, @url, {name: name}.merge(delete_class_options(options)))
27
27
  puts 'group added'
28
28
  print_group_and_members(res.body)
29
29
  end
@@ -31,14 +31,14 @@ module Bl
31
31
  desc 'update GROUP_ID', ''
32
32
  options name: :string, members: :array
33
33
  def update(id)
34
- res = client.patch("#{@url}/#{id}", delete_class_options(options.to_h))
34
+ res = request(:patch, "#{@url}/#{id}", delete_class_options(options.to_h))
35
35
  puts 'group updated'
36
36
  print_group_and_members(res.body)
37
37
  end
38
38
 
39
39
  desc 'delete GROUP_ID', ''
40
40
  def delete(id)
41
- res = client.delete("#{@url}/#{id}")
41
+ res = request(:delete, "#{@url}/#{id}")
42
42
  puts 'group deleted'
43
43
  print_group_and_members(res.body)
44
44
  end
@@ -10,7 +10,7 @@ module Bl
10
10
  desc 'list', 'list milestones'
11
11
  option :all
12
12
  def list
13
- res = client.get(@url)
13
+ res = request(:get, @url)
14
14
  if options[:all]
15
15
  else
16
16
  res.body.select! { |m| m.archived == false } unless options[:all]
@@ -22,7 +22,7 @@ module Bl
22
22
  options MILESTONE_PARAMS
23
23
  def add(*names)
24
24
  names.each do |name|
25
- res = client.post(
25
+ res = request(:post,
26
26
  @url,
27
27
  name: name,
28
28
  description: options[:description],
@@ -39,7 +39,7 @@ module Bl
39
39
  options MILESTONE_PARAMS
40
40
  def update(*ids)
41
41
  ids.each do |id|
42
- res = client.patch("#{@url}/#{id}", delete_class_options(options))
42
+ res = request(:patch, "#{@url}/#{id}", delete_class_options(options))
43
43
  puts 'milestone updated'
44
44
  print_response(res)
45
45
  end
@@ -48,7 +48,7 @@ module Bl
48
48
  desc 'delete [ID...]', 'delete milestones'
49
49
  def delete(*ids)
50
50
  ids.each do |id|
51
- res = client.delete("#{@url}/#{id}")
51
+ res = request(:delete, "#{@url}/#{id}")
52
52
  puts 'milestone deleted'
53
53
  print_response(res)
54
54
  end
@@ -10,27 +10,27 @@ module Bl
10
10
  desc 'list', ''
11
11
  options minId: :numeric, maxId: :numeric, count: :numeric, order: :string
12
12
  def list
13
- res = client.get(@url, options.to_h)
13
+ res = request(:get, @url, options.to_h)
14
14
  res.body.map { |n| puts n.pretty_inspect }
15
15
  end
16
16
 
17
17
  desc 'count', ''
18
18
  options alreadyRead: :boolean, resourceAlreadyRead: :boolean
19
19
  def count
20
- # puts client.get("#{@url}/count").body.count
20
+ # puts request(:get, "#{@url}/count").body.count
21
21
  # TODO fix nil error
22
22
  end
23
23
 
24
24
  desc 'mark-as-read', ''
25
25
  def mark_as_read
26
- res = client.post("#{@url}/markAsRead")
26
+ res = request(:post, "#{@url}/markAsRead")
27
27
  puts 'notifications mark as readed'
28
28
  puts res.body.count
29
29
  end
30
30
 
31
31
  desc 'read NOTIFICATIONS_ID', ''
32
32
  def read(id)
33
- res = client.post("#{@url}/#{id}/markAsRead")
33
+ res = request(:post, "#{@url}/#{id}/markAsRead")
34
34
  puts "notifications #{id} readed"
35
35
  puts res.pretty_inspect
36
36
  end
@@ -0,0 +1,31 @@
1
+ module Bl
2
+ module Printer
3
+ module_function
4
+
5
+ def print_response(res, resource)
6
+ case resource
7
+ when :issue
8
+ puts formatter.render(printable_issues(res.body), fields: ISSUE_FIELDS)
9
+ when :named
10
+ puts formatter.render(res.body, fields: %i(id name))
11
+ else
12
+ raise 'invalid resource error'
13
+ end
14
+ end
15
+
16
+ def printable_issues(ary)
17
+ ary = Array(ary)
18
+ ary.each do |v|
19
+ v.issueType = v.issueType.name
20
+ v.assignee = v.assignee.name if v.assignee
21
+ v.status = v.status.name
22
+ v.priority = v.priority.name
23
+ v.startDate = format_date(v.startDate)
24
+ v.dueDate = format_date(v.dueDate)
25
+ v.created = format_datetime(v.created)
26
+ v.updated = format_datetime(v.updated)
27
+ end
28
+ ary
29
+ end
30
+ end
31
+ end
@@ -8,7 +8,7 @@ module Bl
8
8
 
9
9
  desc 'activities ID', 'show project activities'
10
10
  def activities(id)
11
- res = client.get("#{@url}/#{id}/activities")
11
+ res = request(:get, "#{@url}/#{id}/activities")
12
12
  res.body.each do |a|
13
13
  p a.pretty_inspect
14
14
  end
@@ -16,18 +16,16 @@ module Bl
16
16
 
17
17
  desc 'list', 'list projects'
18
18
  def list
19
- res = client.get(@url)
19
+ res = request(:get, @url)
20
20
  print_response(res)
21
21
  end
22
22
 
23
23
  desc 'show', 'show project'
24
24
  def show(id)
25
- begin
26
- res = client.get("#{@url}/#{id}")
27
- print_response(res)
28
- rescue => e
29
- puts e.message
30
- end
25
+ res = request(:get, "#{@url}/#{id}")
26
+ print_response(res)
27
+ rescue => e
28
+ puts e.message
31
29
  end
32
30
 
33
31
  desc 'add', 'add project'
@@ -37,7 +35,7 @@ module Bl
37
35
  option :subtaskingEnabled, type: :boolean, default: false
38
36
  option :textFormattingRule, type: :string, default: 'markdown'
39
37
  def add(name)
40
- res = client.post(@url, {name: name}.merge(delete_class_options(options.to_h)))
38
+ res = request(:post, @url, {name: name}.merge(delete_class_options(options.to_h)))
41
39
  puts 'project added'
42
40
  print_response(res)
43
41
  end
@@ -45,14 +43,14 @@ module Bl
45
43
  desc 'update', 'update project'
46
44
  options PROJECT_PARAMS
47
45
  def update(id)
48
- res = client.patch("#{@url}/#{id}", delete_class_options(options.to_h))
46
+ res = request(:patch, "#{@url}/#{id}", delete_class_options(options.to_h))
49
47
  puts 'project updated'
50
48
  print_response(res)
51
49
  end
52
50
 
53
51
  desc 'delete', 'delete project'
54
52
  def delete(id)
55
- res = client.delete("#{@url}/#{id}")
53
+ res = request(:delete, "#{@url}/#{id}")
56
54
  puts 'project deleted'
57
55
  print_response(res)
58
56
  end
@@ -78,14 +76,14 @@ module Bl
78
76
  closed_issues_count = count_issues(id, statusId: [4])
79
77
  puts "#{closed_issues_count} / #{all_issues_count}"
80
78
  puts '--milestone--'
81
- versions = client.get("projects/#{@config[:project_key]}/versions").body
79
+ versions = request(:get, "projects/#{@config[:project_key]}/versions").body
82
80
  versions.each do |version|
83
81
  all_issues_count = count_issues(id, milestoneId: [version.id])
84
82
  closed_issues_count = count_issues(id, milestoneId: [version.id], statusId: [4])
85
83
  puts "#{version.name}: #{closed_issues_count} / #{all_issues_count}"
86
84
  end
87
85
  puts '--category--'
88
- categories = client.get("projects/#{@config[:project_key]}/categories").body
86
+ categories = request(:get, "projects/#{@config[:project_key]}/categories").body
89
87
  categories.each do |category|
90
88
  all_issues_count = count_issues(id, categoryId: [category.id])
91
89
  closed_issues_count = count_issues(id, categoryId: [category.id], statusId: [4])
@@ -95,13 +93,13 @@ module Bl
95
93
 
96
94
  desc 'users ID', 'show project users'
97
95
  def users(id)
98
- res = client.get("#{@url}/#{id}/users")
96
+ res = request(:get, "#{@url}/#{id}/users")
99
97
  puts formatter.render(res.body, fields: USER_FIELDS)
100
98
  end
101
99
 
102
100
  desc 'image ID', 'get project image file'
103
101
  def image(id)
104
- res = client.get("#{@url}/#{id}/image")
102
+ res = request(:get, "#{@url}/#{id}/image")
105
103
  ::File.open(res.body.filename, 'wb') { |f| f.write(res.body.content) }
106
104
  puts "#{res.body.filename} generated"
107
105
  end
@@ -112,7 +110,7 @@ module Bl
112
110
  args = {
113
111
  projectId: [project_id],
114
112
  }.merge(args)
115
- client.get(
113
+ request(:get,
116
114
  'issues/count',
117
115
  args
118
116
  ).body.count
@@ -8,20 +8,16 @@ module Bl
8
8
 
9
9
  desc 'issues COUNT', 'list recently viewed issues'
10
10
  def issues(count = nil)
11
- client.get(
12
- 'users/myself/recentlyViewedIssues',
13
- count: count
14
- ).body.each do |i|
11
+ res = request(:get, 'users/myself/recentlyViewedIssues', count: count)
12
+ res.body.each do |i|
15
13
  puts [i.issue.issueKey, i.issue.summary].join("\t")
16
14
  end
17
15
  end
18
16
 
19
17
  desc 'wikis COUNT', 'list recently viewed wikis'
20
18
  def wikis(count = nil)
21
- client.get(
22
- 'users/myself/recentlyViewedWikis',
23
- count: count
24
- ).body.each do |w|
19
+ res = request(:get, 'users/myself/recentlyViewedWikis', count: count)
20
+ res.body.each do |w|
25
21
  puts [w.page.id, w.page.name].join("\t")
26
22
  end
27
23
  end
@@ -12,5 +12,22 @@ module Bl
12
12
  def formatter
13
13
  @formatter ||= Formatter.new(format: options[:format])
14
14
  end
15
+
16
+ def request(method, url, opts = nil)
17
+ case method
18
+ when :get
19
+ client.get(url, opts.to_h)
20
+ when :post
21
+ client.post(url, opts.to_h)
22
+ when :patch
23
+ client.patch(url, opts.to_h)
24
+ when :delete
25
+ client.delete(url, opts.to_h)
26
+ else
27
+ raise 'invalid method error'
28
+ end
29
+ rescue => e
30
+ puts e.message
31
+ end
15
32
  end
16
33
  end
@@ -8,27 +8,27 @@ module Bl
8
8
 
9
9
  desc 'info', 'show space info'
10
10
  def info
11
- res = client.get('space')
11
+ res = request(:get, 'space')
12
12
  puts formatter.render(res.body, fields: SPACE_FIELDS)
13
13
  end
14
14
 
15
15
  desc 'activities', 'show space activities'
16
16
  def activities
17
- client.get('space/activities').body.each do |a|
17
+ request(:get, 'space/activities').body.each do |a|
18
18
  p a.pretty_inspect
19
19
  end
20
20
  end
21
21
 
22
22
  desc 'image', 'get space image file'
23
23
  def image
24
- body = client.get('space/image').body
24
+ body = request(:get, 'space/image').body
25
25
  ::File.open(body.filename, "wb") {|f| f.write(body.content)}
26
26
  puts "#{body.filename} generated."
27
27
  end
28
28
 
29
29
  desc 'get-notification', 'get space notification'
30
30
  def get_notification
31
- res = client.get('space/notification')
31
+ res = request(:get, 'space/notification')
32
32
  print_space_notification(res)
33
33
  end
34
34
 
@@ -41,7 +41,7 @@ module Bl
41
41
 
42
42
  desc 'disk-usage', 'get space disk usage'
43
43
  def disk_usage
44
- res = client.get('space/diskUsage')
44
+ res = request(:get, 'space/diskUsage')
45
45
  print_space_disk_usage(res)
46
46
  end
47
47
 
@@ -9,7 +9,7 @@ module Bl
9
9
 
10
10
  desc 'list', 'list issue types'
11
11
  def list
12
- res = client.get(@url)
12
+ res = request(:get, @url)
13
13
  print_response(res)
14
14
  end
15
15
 
@@ -17,7 +17,7 @@ module Bl
17
17
  option :color, type: :string, required: true
18
18
  def add(*names)
19
19
  names.each do |name|
20
- res = client.post(@url, name: name, color: options[:color])
20
+ res = request(:post, @url, name: name, color: options[:color])
21
21
  puts 'type added'
22
22
  print_response(res)
23
23
  end
@@ -28,7 +28,7 @@ module Bl
28
28
  option :color, color: :color
29
29
  def update(*ids)
30
30
  ids.each do |id|
31
- res = client.patch("#{@url}/#{id}", options)
31
+ res = request(:patch, "#{@url}/#{id}", delete_class_options(options))
32
32
  puts 'type updated'
33
33
  print_response(res)
34
34
  end
@@ -38,7 +38,7 @@ module Bl
38
38
  option :substituteIssueTypeId, type: :numeric, required: true
39
39
  def delete(*ids)
40
40
  ids.each do |id|
41
- res = client.delete("#{@url}/#{id}", options)
41
+ res = request(:delete, "#{@url}/#{id}", delete_class_options(options))
42
42
  puts 'type deleted'
43
43
  print_response
44
44
  end
@@ -9,19 +9,19 @@ module Bl
9
9
 
10
10
  desc 'list', 'list users'
11
11
  def list
12
- res = client.get('users')
12
+ res = request(:get, 'users')
13
13
  print_response(res)
14
14
  end
15
15
 
16
16
  desc 'show USER_ID', ''
17
17
  def show(id)
18
- res = client.get("#{@url}/#{id}")
18
+ res = request(:get, "#{@url}/#{id}")
19
19
  puts formatter.render(res.body, fields: USER_FIELDS)
20
20
  end
21
21
 
22
22
  desc 'add USER_ID PASSWORD NAME MAIL_ADDRESS ROLE_TYPE', ''
23
23
  def add(id, pass, name, mail_address, role_type)
24
- res = client.post("#{@url}", userId: id, password: pass, name: name, mailAddress: mail_address, roleType: role_type)
24
+ res = request(:post, "#{@url}", userId: id, password: pass, name: name, mailAddress: mail_address, roleType: role_type)
25
25
  puts 'user added'
26
26
  print_response(res)
27
27
  end
@@ -29,34 +29,34 @@ module Bl
29
29
  desc 'update USER_ID', ''
30
30
  options USER_PARAMS
31
31
  def update(id)
32
- res = client.patch("#{@url}/#{id}", delete_class_options(options.to_h))
32
+ res = request(:patch, "#{@url}/#{id}", delete_class_options(options.to_h))
33
33
  puts 'user updated:'
34
34
  print_response(res)
35
35
  end
36
36
 
37
37
  desc 'delete', ''
38
38
  def delete(id)
39
- res = client.delete("#{@url}/#{id}")
39
+ res = request(:delete, "#{@url}/#{id}")
40
40
  puts 'user deleted'
41
41
  print_response(res)
42
42
  end
43
43
 
44
44
  desc 'myself', ''
45
45
  def myself
46
- res = client.get("#{@url}/myself")
46
+ res = request(:get, "#{@url}/myself")
47
47
  print_response(res)
48
48
  end
49
49
 
50
50
  desc 'icon ID', ''
51
51
  def icon(id)
52
- # res = client.get("#{@url}/#{id}/icon")
52
+ # res = request(:get, "#{@url}/#{id}/icon")
53
53
  # TODO fix nil error
54
54
  end
55
55
 
56
56
  desc 'activities USER_ID', "list user's activities"
57
57
  options activityTypeId: :array, minId: :numeric, maxId: :numeric, count: :numeric, order: :string
58
58
  def activities(user_id)
59
- res = client.get("/users/#{user_id}/activities")
59
+ res = request(:get, "/users/#{user_id}/activities")
60
60
  res.body.map { |a| print_activity(a) }
61
61
  end
62
62
 
@@ -64,7 +64,7 @@ module Bl
64
64
  options minId: :numeric, maxId: :numeric, count: :numeric, order: :string
65
65
  def stars(*user_ids)
66
66
  user_ids.each do |user_id|
67
- res = client.get("/users/#{user_id}/stars", options.to_h)
67
+ res = request(:get, "/users/#{user_id}/stars", options.to_h)
68
68
  res.body.map { |s| p s }
69
69
  end
70
70
  end
@@ -73,7 +73,7 @@ module Bl
73
73
  options since: :string, until: :string
74
74
  def stars_count(*user_ids)
75
75
  user_ids.each do |user_id|
76
- p client.get("/users/#{user_id}/stars/count", options.to_h).body.count
76
+ p request(:get, "/users/#{user_id}/stars/count", options.to_h).body.count
77
77
  end
78
78
  end
79
79
 
@@ -1,3 +1,3 @@
1
1
  module Bl
2
- VERSION = '0.5.11'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
@@ -10,27 +10,27 @@ module Bl
10
10
  desc 'list USER_ID', ''
11
11
  options WATCHINGS_PARAMS
12
12
  def list(id)
13
- res = client.get("/users/#{id}/#{@url}", delete_class_options(options.to_h))
13
+ res = request(:get, "/users/#{id}/#{@url}", delete_class_options(options.to_h))
14
14
  res.body.map { |t| print_watch_target(t) }
15
15
  end
16
16
 
17
17
  desc 'count USER_ID', ''
18
18
  options resourceAlreadyRead: :boolean, alreadyRead: :boolean
19
19
  def count(id)
20
- res = client.get("/users/#{id}/#{@url}/count")
20
+ res = request(:get, "/users/#{id}/#{@url}/count")
21
21
  puts res.body.count
22
22
  end
23
23
 
24
24
  desc 'show WATCHING_ID', ''
25
25
  def show(id)
26
- res = client.get("watchings/#{id}")
26
+ res = request(:get, "watchings/#{id}")
27
27
  print_watch_target(res.body)
28
28
  end
29
29
 
30
30
  desc 'add', ''
31
31
  options issueIdOrKey: :required, note: :string
32
32
  def add
33
- res = client.post('watchings', options.to_h)
33
+ res = request(:post, 'watchings', options.to_h)
34
34
  puts 'watch added'
35
35
  print_watch_target(res.body)
36
36
  end
@@ -39,27 +39,27 @@ module Bl
39
39
  option note: :string
40
40
  def update(id)
41
41
  # TODO fix conflict with issue update command
42
- # res = client.patch("watchings/#{id}", option.to_h)
42
+ # res = request(:patch, "watchings/#{id}", option.to_h)
43
43
  # puts 'watch updated'
44
44
  # print_watch_target(res.body)
45
45
  end
46
46
 
47
47
  desc 'delete WATCHING_ID', ''
48
48
  def delete(id)
49
- res = client.delete("watchings/#{id}")
49
+ res = request(:delete, "watchings/#{id}")
50
50
  puts 'watch deleted'
51
51
  print_watch_target(res.body)
52
52
  end
53
53
 
54
54
  desc 'mark-as-read WATCHING_ID', ''
55
55
  def mark_as_read(id)
56
- res = client.post("watchings/#{id}/markAsRead")
56
+ res = request(:post, "watchings/#{id}/markAsRead")
57
57
  puts 'watch mark as read'
58
58
  end
59
59
 
60
60
  desc 'mark-as-checked USER_ID', ''
61
61
  def mark_as_checked(id)
62
- res = client.post("/users/#{id}/watchings/markAsChecked")
62
+ res = request(:post, "/users/#{id}/watchings/markAsChecked")
63
63
  puts 'watch mark as checked'
64
64
  end
65
65
 
@@ -9,20 +9,20 @@ module Bl
9
9
 
10
10
  desc 'list', ''
11
11
  def list
12
- res = client.get(@url)
12
+ res = request(:get, @url)
13
13
  print_response(res)
14
14
  end
15
15
 
16
16
  desc 'show WEBHOOK_ID', ''
17
17
  def show(id)
18
- res = client.get("#{@url}/#{id}")
18
+ res = request(:get, "#{@url}/#{id}")
19
19
  print_response(res)
20
20
  end
21
21
 
22
22
  desc 'add', ''
23
23
  options WEBHOOK_PARAMS
24
24
  def add
25
- res = client.post(@url, options.to_h)
25
+ res = request(:post, @url, options.to_h)
26
26
  puts 'webhook added'
27
27
  print_response(res)
28
28
  end
@@ -30,14 +30,14 @@ module Bl
30
30
  desc 'update WEBHOOK_ID', ''
31
31
  options WEBHOOK_PARAMS
32
32
  def update(id)
33
- res = client.patch("#{@url}/#{id}", options.to_h)
33
+ res = request(:patch, "#{@url}/#{id}", options.to_h)
34
34
  puts 'webhook updated'
35
35
  print_response(res)
36
36
  end
37
37
 
38
38
  desc 'delete WEBHOOK_ID', ''
39
39
  def delete(id)
40
- res = client.delete("#{@url}/#{id}")
40
+ res = request(:delete, "#{@url}/#{id}")
41
41
  puts 'webhook deleted'
42
42
  print_response(res)
43
43
  end
@@ -9,13 +9,13 @@ module Bl
9
9
 
10
10
  desc 'list', 'list wikis'
11
11
  def list
12
- res = client.get(@url, projectIdOrKey: @config[:project_key])
12
+ res = request(:get, @url, projectIdOrKey: @config[:project_key])
13
13
  puts formatter.render(res.body, fields: WIKI_FIELDS)
14
14
  end
15
15
 
16
16
  desc 'show ID', "show a wiki's content"
17
17
  def show(id)
18
- body = client.get("#{@url}/#{id}").body
18
+ body = request(:get, "#{@url}/#{id}").body
19
19
  puts "id: #{body.id}"
20
20
  puts "projectId: #{body.projectId}"
21
21
  puts "name: #{body.name}"
@@ -27,7 +27,7 @@ module Bl
27
27
 
28
28
  desc 'edit ID', 'edit a wiki by $EDITOR'
29
29
  def edit(id)
30
- wiki_content = client.get("#{@url}/#{id}").body.content
30
+ wiki_content = request(:get, "#{@url}/#{id}").body.content
31
31
  file = Tempfile.new
32
32
  file.puts(wiki_content)
33
33
  file.close
@@ -35,7 +35,7 @@ module Bl
35
35
  file.open
36
36
  system("$EDITOR #{file.path}")
37
37
  new_content = file.read
38
- client.patch("#{@url}/#{id}", content: new_content)
38
+ request(:patch, "#{@url}/#{id}", content: new_content)
39
39
  puts "wiki #{id} updated."
40
40
  ensure
41
41
  file.close
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - saki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-09 00:00:00.000000000 Z
11
+ date: 2017-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -182,6 +182,7 @@ files:
182
182
  - lib/bl/cli.rb
183
183
  - lib/bl/command.rb
184
184
  - lib/bl/config.rb
185
+ - lib/bl/constants.rb
185
186
  - lib/bl/file.rb
186
187
  - lib/bl/formatter.rb
187
188
  - lib/bl/formatting.rb
@@ -189,6 +190,7 @@ files:
189
190
  - lib/bl/groups.rb
190
191
  - lib/bl/milestone.rb
191
192
  - lib/bl/notifications.rb
193
+ - lib/bl/printer.rb
192
194
  - lib/bl/project.rb
193
195
  - lib/bl/recent.rb
194
196
  - lib/bl/requestable.rb