bl 0.6.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ module Bl
2
+ module Commands
3
+ class PullRequest < Command
4
+ def initialize(*)
5
+ @config = Bl::Config.instance
6
+ @url = "projects/#{@config[:project_key]}/git/repositories"
7
+ super
8
+ end
9
+
10
+ desc 'count ID', 'count pull requests'
11
+ def count(id)
12
+ res = request(:get, "#{@url}/#{id}/pullRequests/count")
13
+ puts res.body.count
14
+ end
15
+
16
+ desc 'list ID', 'list pull requests'
17
+ def list(id)
18
+ res = request(:get, "#{@url}/#{id}/pullRequests")
19
+ print_response(res, :pull_request)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ module Bl
2
+ module Commands
3
+ class Recent < Command
4
+ def initialize(*)
5
+ @config = Bl::Config.instance
6
+ super
7
+ end
8
+
9
+ desc 'issues COUNT', 'list recently viewed issues'
10
+ def issues(count = nil)
11
+ res = request(:get, 'users/myself/recentlyViewedIssues', count: count)
12
+ res.body.each do |i|
13
+ # TODO: print as table
14
+ puts [i.issue.issueKey, i.issue.summary].join("\t")
15
+ end
16
+ end
17
+
18
+ desc 'wikis COUNT', 'list recently viewed wikis'
19
+ def wikis(count = nil)
20
+ res = request(:get, 'users/myself/recentlyViewedWikis', count: count)
21
+ res.body.each do |w|
22
+ # TODO: print as table
23
+ puts [w.page.id, w.page.name].join("\t")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,66 @@
1
+ module Bl
2
+ module Commands
3
+ class Space < Command
4
+ def initialize(*)
5
+ @config = Bl::Config.instance
6
+ super
7
+ end
8
+
9
+ desc 'info', 'show space info'
10
+ def info
11
+ res = request(:get, 'space')
12
+ puts formatter.render(res.body, fields: SPACE_FIELDS)
13
+ end
14
+
15
+ # TODO:
16
+ # desc 'activities', 'show space activities'
17
+ # def activities
18
+ # request(:get, 'space/activities').body.each do |a|
19
+ # p a.pretty_inspect
20
+ # end
21
+ # end
22
+
23
+ desc 'image', 'get space image file'
24
+ def image
25
+ body = request(:get, 'space/image').body
26
+ ::File.open(body.filename, 'wb') { |f| f.write(body.content) }
27
+ puts "#{body.filename} generated."
28
+ end
29
+
30
+ desc 'get-notification', 'get space notification'
31
+ def get_notification
32
+ res = request(:get, 'space/notification')
33
+ print_space_notification(res)
34
+ end
35
+
36
+ desc 'update-notification CONTENT', 'update space notification'
37
+ def update_notification(content)
38
+ res = client.put('space/notification', content: content)
39
+ puts 'space notification updated'
40
+ print_space_notification(res)
41
+ end
42
+
43
+ desc 'disk-usage', 'get space disk usage'
44
+ def disk_usage
45
+ res = request(:get, 'space/diskUsage')
46
+ print_space_disk_usage(res)
47
+ end
48
+
49
+ private
50
+
51
+ def print_space_notification(res)
52
+ puts formatter.render(res.body, fields: SPACE_NOTIFICATION_FIELDS)
53
+ end
54
+
55
+ def print_space_disk_usage(res)
56
+ puts 'summary:'
57
+ puts formatter.render(res.body, fields: SPACE_DISK_USAGE)
58
+ puts 'details:'
59
+ puts formatter.render(
60
+ res.body.details,
61
+ fields: SPACE_DISK_USAGE_DETAILS_FIELDS
62
+ )
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,57 @@
1
+ module Bl
2
+ module Commands
3
+ class Type < Command
4
+ def initialize(*)
5
+ @config = Bl::Config.instance
6
+ @url = "projects/#{@config[:project_key]}/issueTypes"
7
+ super
8
+ end
9
+
10
+ desc 'list', 'list issue types'
11
+ def list
12
+ res = request(:get, @url)
13
+ puts 'types:'
14
+ print_response(res, :type)
15
+ end
16
+
17
+ desc 'add [NAME...]', 'add types'
18
+ option :color, type: :string, required: true
19
+ def add(*names)
20
+ names.each do |name|
21
+ res = request(:post, @url, name: name, color: options[:color])
22
+ puts 'type added'
23
+ print_response(res, :type)
24
+ end
25
+ end
26
+
27
+ desc 'update [ID...]', 'update types'
28
+ option :name, type: :string
29
+ option :color, color: :color
30
+ def update(*ids)
31
+ ids.each do |id|
32
+ res = request(:patch, "#{@url}/#{id}", delete_class_options(options))
33
+ puts 'type updated'
34
+ print_response(res, :type)
35
+ end
36
+ end
37
+
38
+ desc 'delete [ID...]', 'delete types'
39
+ option :substituteIssueTypeId, type: :numeric, required: true
40
+ def delete(*ids)
41
+ ids.each do |id|
42
+ res = request(:delete, "#{@url}/#{id}", delete_class_options(options))
43
+ puts 'type deleted'
44
+ print_response(res, :type)
45
+ end
46
+ end
47
+
48
+ desc 'colors', 'list available colors'
49
+ def colors
50
+ puts 'colors:'
51
+ TYPE_COLORS.each do |color|
52
+ puts Paint[color, '#ffffff', color]
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,90 @@
1
+ module Bl
2
+ module Commands
3
+ class User < Command
4
+ def initialize(*)
5
+ @config = Bl::Config.instance
6
+ @url = 'users'
7
+ super
8
+ end
9
+
10
+ desc 'list', 'list users'
11
+ def list
12
+ res = request(:get, 'users')
13
+ print_response(res, :user)
14
+ end
15
+
16
+ desc 'show USER_ID', ''
17
+ def show(id)
18
+ res = request(:get, "#{@url}/#{id}")
19
+ puts formatter.render(res.body, fields: USER_FIELDS)
20
+ end
21
+
22
+ desc 'add USER_ID PASSWORD NAME MAIL_ADDRESS ROLE_TYPE', ''
23
+ def add(id, pass, name, mail_address, role_type)
24
+ res = request(
25
+ :post,
26
+ @url,
27
+ userId: id,
28
+ password: pass,
29
+ name: name,
30
+ mailAddress: mail_address,
31
+ roleType: role_type
32
+ )
33
+ puts 'user added'
34
+ print_response(res, :user)
35
+ end
36
+
37
+ desc 'update USER_ID', ''
38
+ options USER_PARAMS
39
+ def update(id)
40
+ res = request(:patch, "#{@url}/#{id}", delete_class_options(options.to_h))
41
+ puts 'user updated:'
42
+ print_response(res, :user)
43
+ end
44
+
45
+ desc 'delete', ''
46
+ def delete(id)
47
+ res = request(:delete, "#{@url}/#{id}")
48
+ puts 'user deleted'
49
+ print_response(res, :user)
50
+ end
51
+
52
+ desc 'myself', ''
53
+ def myself
54
+ res = request(:get, "#{@url}/myself")
55
+ print_response(res, :user)
56
+ end
57
+
58
+ desc 'icon ID', ''
59
+ def icon(id)
60
+ # res = request(:get, "#{@url}/#{id}/icon")
61
+ # TODO fix nil error
62
+ end
63
+
64
+ # TODO:
65
+ # desc 'activities USER_ID', "list user's activities"
66
+ # options activityTypeId: :array, minId: :numeric, maxId: :numeric, count: :numeric, order: :string
67
+ # def activities(user_id)
68
+ # res = request(:get, "/users/#{user_id}/activities")
69
+ # res.body.map { |a| print_activity(a) }
70
+ # end
71
+
72
+ desc 'stars [USER_ID...]', ''
73
+ options minId: :numeric, maxId: :numeric, count: :numeric, order: :string
74
+ def stars(*user_ids)
75
+ user_ids.each do |user_id|
76
+ res = request(:get, "/users/#{user_id}/stars", options.to_h)
77
+ res.body.map { |s| p s }
78
+ end
79
+ end
80
+
81
+ desc 'stars-count [USER_ID...]', "count user's stars"
82
+ options since: :string, until: :string
83
+ def stars_count(*user_ids)
84
+ user_ids.each do |user_id|
85
+ p request(:get, "/users/#{user_id}/stars/count", options.to_h).body.count
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,67 @@
1
+ module Bl
2
+ module Commands
3
+ class Watching < Command
4
+ def initialize(*)
5
+ @config = Bl::Config.instance
6
+ @url = 'watchings'
7
+ super
8
+ end
9
+
10
+ desc 'list USER_ID', ''
11
+ options WATCHINGS_PARAMS
12
+ def list(id)
13
+ res = request(:get, "/users/#{id}/#{@url}", delete_class_options(options.to_h))
14
+ res.body.map { |t| print_watch_target(t) }
15
+ end
16
+
17
+ desc 'count USER_ID', ''
18
+ options resourceAlreadyRead: :boolean, alreadyRead: :boolean
19
+ def count(id)
20
+ res = request(:get, "/users/#{id}/#{@url}/count")
21
+ puts res.body.count
22
+ end
23
+
24
+ desc 'show WATCHING_ID', ''
25
+ def show(id)
26
+ res = request(:get, "watchings/#{id}")
27
+ print_watch_target(res.body)
28
+ end
29
+
30
+ desc 'add', ''
31
+ options issueIdOrKey: :required, note: :string
32
+ def add
33
+ res = request(:post, 'watchings', options.to_h)
34
+ puts 'watch added'
35
+ print_watch_target(res.body)
36
+ end
37
+
38
+ desc 'update WATCHING_ID', ''
39
+ option note: :string
40
+ def update(id)
41
+ # TODO fix conflict with issue update command
42
+ # res = request(:patch, "watchings/#{id}", option.to_h)
43
+ # puts 'watch updated'
44
+ # print_watch_target(res.body)
45
+ end
46
+
47
+ desc 'delete WATCHING_ID', ''
48
+ def delete(id)
49
+ res = request(:delete, "watchings/#{id}")
50
+ puts 'watch deleted'
51
+ print_watch_target(res.body)
52
+ end
53
+
54
+ desc 'mark-as-read WATCHING_ID', ''
55
+ def mark_as_read(id)
56
+ res = request(:post, "watchings/#{id}/markAsRead")
57
+ puts 'watch mark as read'
58
+ end
59
+
60
+ desc 'mark-as-checked USER_ID', ''
61
+ def mark_as_checked(id)
62
+ res = request(:post, "/users/#{id}/watchings/markAsChecked")
63
+ puts 'watch mark as checked'
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,52 @@
1
+ module Bl
2
+ module Commands
3
+ class Webhook < Command
4
+ def initialize(*)
5
+ @config = Bl::Config.instance
6
+ @url = "projects/#{@config[:project_key]}/webhooks"
7
+ super
8
+ end
9
+
10
+ desc 'list', ''
11
+ def list
12
+ res = request(:get, @url)
13
+ print_response(res)
14
+ end
15
+
16
+ desc 'show WEBHOOK_ID', ''
17
+ def show(id)
18
+ res = request(:get, "#{@url}/#{id}")
19
+ print_response(res)
20
+ end
21
+
22
+ desc 'add', ''
23
+ options WEBHOOK_PARAMS
24
+ def add
25
+ res = request(:post, @url, options.to_h)
26
+ puts 'webhook added'
27
+ print_response(res)
28
+ end
29
+
30
+ desc 'update WEBHOOK_ID', ''
31
+ options WEBHOOK_PARAMS
32
+ def update(id)
33
+ res = request(:patch, "#{@url}/#{id}", options.to_h)
34
+ puts 'webhook updated'
35
+ print_response(res)
36
+ end
37
+
38
+ desc 'delete WEBHOOK_ID', ''
39
+ def delete(id)
40
+ res = request(:delete, "#{@url}/#{id}")
41
+ puts 'webhook deleted'
42
+ print_response(res)
43
+ end
44
+
45
+ private
46
+
47
+ def print_response(res)
48
+ puts formatter.render(res.body, fields: WEBHOOK_FIELDS)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,79 @@
1
+ module Bl
2
+ module Commands
3
+ class Wiki < Command
4
+ def initialize(*)
5
+ @config = Bl::Config.instance
6
+ @url = 'wikis'
7
+ super
8
+ end
9
+
10
+ desc 'add NAME', 'add wiki'
11
+ option :projectId, type: :numeric, required: true
12
+ option :content, type: :string, required: true
13
+ def add(name)
14
+ res = request(
15
+ :post,
16
+ @url,
17
+ projectId: options[:projectId],
18
+ name: name,
19
+ content: options[:content]
20
+ )
21
+ puts 'wiki added:'
22
+ print_response(res, :wiki)
23
+ end
24
+
25
+ desc 'count', 'count wiki'
26
+ option :projectIdOrKey, type: :numeric, required: true
27
+ def count
28
+ res = request(:get, "#{@url}/count", projectIdOrKey: options[:projectIdOrKey])
29
+ puts 'wiki count'
30
+ puts res.body.count
31
+ end
32
+
33
+ desc 'delete ID', 'delete wiki'
34
+ def delete(id)
35
+ res = request(:delete, "#{@url}/#{id}")
36
+ puts 'wiki deleted'
37
+ print_response(res, :wiki)
38
+ end
39
+
40
+ desc 'list', 'list wikis'
41
+ def list
42
+ res = request(:get, @url, projectIdOrKey: @config[:project_key])
43
+ print_response(res, :wiki)
44
+ end
45
+
46
+ desc 'show ID', "show a wiki's content"
47
+ def show(id)
48
+ res = request(:get, "#{@url}/#{id}")
49
+ puts formatter.render(res.body, fields: WIKI_FIELDS.push(:content), vertical: true)
50
+ end
51
+
52
+ desc 'tags', 'show wiki tags'
53
+ option :projectIdOrKey, type: :numeric, required: true
54
+ def tags
55
+ res = request(:get, "#{@url}/tags", projectIdOrKey: options[:projectIdOrKey])
56
+ puts 'wiki tags:'
57
+ print_response(res, :named)
58
+ end
59
+
60
+ desc 'edit ID', 'edit a wiki by $EDITOR'
61
+ def edit(id)
62
+ wiki_content = request(:get, "#{@url}/#{id}").body.content
63
+ file = Tempfile.new
64
+ file.puts(wiki_content)
65
+ file.close
66
+ begin
67
+ file.open
68
+ system("$EDITOR #{file.path}")
69
+ new_content = file.read
70
+ request(:patch, "#{@url}/#{id}", content: new_content)
71
+ puts "wiki #{id} updated."
72
+ ensure
73
+ file.close
74
+ file.unlink
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end