lita-deploygate 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +4 -14
- data/.travis.yml +4 -4
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/lib/lita/handlers/deploygate.rb +47 -76
- data/lita-deploygate.gemspec +7 -7
- data/locales/en.yml +17 -0
- data/spec/lita/handlers/deploygate_spec.rb +36 -53
- data/spec/spec_helper.rb +2 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38bbbee6ec20f8cce043f2d1c759d30261d86a28
|
4
|
+
data.tar.gz: e74f13293333bd906f036842e15595d2a6a08428
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f302790c5949e94eeff407e35b8275035a8e18e2e2dfe801874aec617192c582730593d0bcf8a4586c723055f98c317e6e6b55f8868a92cf3b7182fd7cb62b8
|
7
|
+
data.tar.gz: b3999b0c146778044f4a29a018ecfc9bc31d85768fd17362efa108ef86d1753dc4dd2c6dd3d53585a5d9a59f5ff9d3610237aa45548e8849fe6d7d0a24e3d1ac
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,17 +1,7 @@
|
|
1
|
-
ClassLength:
|
2
|
-
Max: 400
|
3
|
-
|
4
|
-
CyclomaticComplexity:
|
5
|
-
Max: 10
|
6
|
-
|
7
1
|
Documentation:
|
8
|
-
|
2
|
+
Exclude:
|
3
|
+
- lib/lita/handlers/deploygate.rb
|
9
4
|
|
10
5
|
FileName:
|
11
|
-
|
12
|
-
|
13
|
-
LineLength:
|
14
|
-
Max: 105
|
15
|
-
|
16
|
-
MethodLength:
|
17
|
-
Max: 30
|
6
|
+
Exclude:
|
7
|
+
- lib/lita-deploygate.rb
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[![Code Climate](https://img.shields.io/codeclimate/github/esigler/lita-deploygate.svg)](https://codeclimate.com/github/esigler/lita-deploygate)
|
8
8
|
[![Gemnasium](https://img.shields.io/gemnasium/esigler/lita-deploygate.svg)](https://gemnasium.com/esigler/lita-deploygate)
|
9
9
|
|
10
|
-
|
10
|
+
A [Deploygate](http://deploygate.com) plugin for [Lita](https://github.com/jimmycuadra/lita).
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
data/Rakefile
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
module Lita
|
2
2
|
module Handlers
|
3
3
|
class Deploygate < Handler
|
4
|
+
config :user_name, required: true
|
5
|
+
config :api_key, required: true
|
6
|
+
config :app_names
|
7
|
+
|
4
8
|
route(
|
5
9
|
/^(deploygate|dg)\sadd\s(\S+)\s(\S+)$/,
|
6
10
|
:add,
|
7
11
|
command: true,
|
8
12
|
help: {
|
9
|
-
'
|
10
|
-
'Add <username or email> to <short name>'
|
13
|
+
t('help.add_key') => t('help.add_value')
|
11
14
|
}
|
12
15
|
)
|
13
16
|
|
@@ -16,8 +19,7 @@ module Lita
|
|
16
19
|
:remove,
|
17
20
|
command: true,
|
18
21
|
help: {
|
19
|
-
'
|
20
|
-
'Remove <username or email> from <short name>'
|
22
|
+
t('help.remove_key') => t('help.remove_value')
|
21
23
|
}
|
22
24
|
)
|
23
25
|
|
@@ -26,74 +28,53 @@ module Lita
|
|
26
28
|
:list,
|
27
29
|
command: true,
|
28
30
|
help: {
|
29
|
-
'
|
30
|
-
'List all users associated with <short name>'
|
31
|
+
t('help.list_key') => t('help.list_value')
|
31
32
|
}
|
32
33
|
)
|
33
34
|
|
34
|
-
def self.default_config(config)
|
35
|
-
config.user_name = nil
|
36
|
-
config.api_key = nil
|
37
|
-
config.default_app_id = nil
|
38
|
-
end
|
39
|
-
|
40
35
|
def add(response)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
result = api_request('post',
|
45
|
-
"/#{app_path(short_name)}/members",
|
46
|
-
'users' => "[#{user_identifier}]")
|
47
|
-
if result
|
48
|
-
response.reply("#{short_name}: #{user_identifier} added")
|
49
|
-
else
|
50
|
-
response.reply('There was an error making the request to DeployGate')
|
51
|
-
end
|
52
|
-
else
|
53
|
-
response.reply("#{short_name}: unknown application name")
|
54
|
-
end
|
36
|
+
app = response.matches[0][2]
|
37
|
+
user = response.matches[0][1]
|
38
|
+
response.reply(change(app, 'post', 'add.success', user))
|
55
39
|
end
|
56
40
|
|
57
41
|
def remove(response)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
result = api_request('delete',
|
62
|
-
"/#{app_path(short_name)}/members",
|
63
|
-
'users' => "[#{user_identifier}]")
|
64
|
-
if result
|
65
|
-
response.reply("#{short_name}: #{user_identifier} removed")
|
66
|
-
else
|
67
|
-
response.reply('There was an error making the request to DeployGate')
|
68
|
-
end
|
69
|
-
else
|
70
|
-
response.reply("#{short_name}: unknown application name")
|
71
|
-
end
|
42
|
+
app = response.matches[0][2]
|
43
|
+
user = response.matches[0][1]
|
44
|
+
response.reply(change(app, 'delete', 'remove.success', user))
|
72
45
|
end
|
73
46
|
|
47
|
+
# rubocop:disable Metrics/AbcSize
|
74
48
|
def list(response)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
response.reply("#{short_name}: #{user['name']}, role: #{user['role']}")
|
83
|
-
end
|
84
|
-
else
|
85
|
-
response.reply("#{short_name}: No users")
|
86
|
-
end
|
87
|
-
else
|
88
|
-
response.reply('There was an error making the request to DeployGate')
|
89
|
-
end
|
90
|
-
else
|
91
|
-
response.reply("#{short_name}: unknown application name")
|
49
|
+
app = response.matches[0][1]
|
50
|
+
users = members(app)
|
51
|
+
return response.reply(users) unless users.is_a? Array
|
52
|
+
return response.reply(t('list.none', app: app)) unless users.count > 0
|
53
|
+
users.each do |user|
|
54
|
+
response.reply(t('list.user', app: app, user: user['name'],
|
55
|
+
role: user['role']))
|
92
56
|
end
|
93
57
|
end
|
58
|
+
# rubocop:enable Metrics/AbcSize
|
94
59
|
|
95
60
|
private
|
96
61
|
|
62
|
+
def change(app, method, success_key, user)
|
63
|
+
return t('error.unknown_app', app: app) unless valid_app_name?(app)
|
64
|
+
result = api_request(method,
|
65
|
+
"/#{app_path(app)}/members",
|
66
|
+
'users' => "[#{user}]")
|
67
|
+
return t('error.request') unless result
|
68
|
+
t(success_key, app: app, user: user)
|
69
|
+
end
|
70
|
+
|
71
|
+
def members(app)
|
72
|
+
return t('error.unknown_app', app: app) unless valid_app_name?(app)
|
73
|
+
result = api_request('get', "/#{app_path(app)}/members")
|
74
|
+
return t('error.request') unless result
|
75
|
+
result['results']['users']
|
76
|
+
end
|
77
|
+
|
97
78
|
def valid_app_name?(name)
|
98
79
|
Lita.config.handlers.deploygate.app_names.key?(name)
|
99
80
|
end
|
@@ -102,33 +83,23 @@ module Lita
|
|
102
83
|
Lita.config.handlers.deploygate.app_names[name]
|
103
84
|
end
|
104
85
|
|
86
|
+
# rubocop:disable Metrics/AbcSize
|
105
87
|
def api_request(method, component, args = {})
|
106
|
-
|
107
|
-
|
108
|
-
Lita.logger.error('Missing API key or Page ID for Deploygate')
|
109
|
-
fail 'Missing config'
|
110
|
-
end
|
111
|
-
|
112
|
-
url = "https://deploygate.com/api/users/" \
|
113
|
-
"#{Lita.config.handlers.deploygate.user_name}" \
|
114
|
-
"#{component}"
|
115
|
-
|
116
|
-
args['token'] = Lita.config.handlers.deploygate.api_key
|
88
|
+
url = "https://deploygate.com/api/users/#{config.user_name}#{component}"
|
89
|
+
args['token'] = config.api_key
|
117
90
|
|
118
91
|
http_response = http.send(method) do |req|
|
119
92
|
req.url url, args
|
120
93
|
end
|
121
94
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
else
|
126
|
-
Lita.logger.error("HTTP #{method} for #{url} with #{args} " \
|
127
|
-
"returned #{http_response.status}")
|
128
|
-
Lita.logger.error(http_response.body)
|
129
|
-
nil
|
95
|
+
unless http_response.status == 200 || http_response.status == 201
|
96
|
+
log.error("#{method}:#{component}:#{args}:#{http_response.status}")
|
97
|
+
return nil
|
130
98
|
end
|
99
|
+
|
100
|
+
MultiJson.load(http_response.body)
|
131
101
|
end
|
102
|
+
# rubocop:enable Metrics/AbcSize
|
132
103
|
end
|
133
104
|
|
134
105
|
Lita.register_handler(Deploygate)
|
data/lita-deploygate.gemspec
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'lita-deploygate'
|
3
|
-
spec.version = '0.1.
|
3
|
+
spec.version = '0.1.1'
|
4
4
|
spec.authors = ['Eric Sigler']
|
5
5
|
spec.email = ['me@esigler.com']
|
6
|
-
spec.description =
|
7
|
-
spec.summary =
|
6
|
+
spec.description = 'A Deploygate plugin for Lita'
|
7
|
+
spec.summary = 'A Deploygate plugin for Lita'
|
8
8
|
spec.homepage = 'http://github.com/esigler/lita-deploygate'
|
9
9
|
spec.license = 'MIT'
|
10
10
|
spec.metadata = { 'lita_plugin_type' => 'handler' }
|
11
11
|
|
12
|
-
spec.files = `git ls-files`.split(
|
13
|
-
spec.executables = spec.files.grep(%r{^bin
|
14
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)
|
12
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin\/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)\/})
|
15
15
|
spec.require_paths = ['lib']
|
16
16
|
|
17
|
-
spec.add_runtime_dependency 'lita', '>=
|
17
|
+
spec.add_runtime_dependency 'lita', '>= 4.0'
|
18
18
|
spec.add_runtime_dependency 'multi_json'
|
19
19
|
|
20
20
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
data/locales/en.yml
CHANGED
@@ -2,3 +2,20 @@ en:
|
|
2
2
|
lita:
|
3
3
|
handlers:
|
4
4
|
deploygate:
|
5
|
+
add:
|
6
|
+
success: "%{app}: %{user} added"
|
7
|
+
error:
|
8
|
+
request: There was an error making the request to DeployGate
|
9
|
+
unknown_app: "%{app}: unknown application name"
|
10
|
+
help:
|
11
|
+
add_key: deploygate add <username or email> <short name>
|
12
|
+
add_value: Add <username or email> to <short name>
|
13
|
+
list_key: deploygate list <short name>
|
14
|
+
list_value: List all users associated with <short name>
|
15
|
+
remove_key: deploygate remove <username or email> <short name>
|
16
|
+
remove_value: Remove <username or email> from <short name>
|
17
|
+
list:
|
18
|
+
none: "%{app}: No users"
|
19
|
+
user: "%{app}: %{user}, role: %{role}"
|
20
|
+
remove:
|
21
|
+
success: "%{app}: %{user} removed"
|
@@ -17,33 +17,21 @@ describe Lita::Handlers::Deploygate, lita_handler: true do
|
|
17
17
|
File.read('spec/files/members_remove.json')
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
it { routes_command('deploygate list abc123').to(:list) }
|
25
|
-
it { routes_command('dg add username abc123').to(:add) }
|
26
|
-
it { routes_command('dg remove username abc123').to(:remove) }
|
27
|
-
it { routes_command('dg list abc123').to(:list) }
|
28
|
-
|
29
|
-
describe '.default_config' do
|
30
|
-
it 'sets user_name to nil' do
|
31
|
-
expect(Lita.config.handlers.deploygate.user_name).to be_nil
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'sets api_key to nil' do
|
35
|
-
expect(Lita.config.handlers.deploygate.api_key).to be_nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'sets app_names to nil' do
|
39
|
-
expect(Lita.config.handlers.deploygate.app_names).to be_nil
|
40
|
-
end
|
20
|
+
def grab_request(method, status, body)
|
21
|
+
response = double('Faraday::Response', status: status, body: body)
|
22
|
+
expect_any_instance_of(Faraday::Connection).to \
|
23
|
+
receive(method.to_sym).and_return(response)
|
41
24
|
end
|
42
25
|
|
43
|
-
|
44
|
-
it
|
45
|
-
|
46
|
-
|
26
|
+
%w(deploygate dg).each do |name|
|
27
|
+
it do
|
28
|
+
is_expected.to route_command("#{name} add username abc123").to(:add)
|
29
|
+
is_expected.to route_command("#{name} add foo@example.com abc123")
|
30
|
+
.to(:add)
|
31
|
+
is_expected.to route_command("#{name} remove username abc123").to(:remove)
|
32
|
+
is_expected.to route_command("#{name} remove foo@example.com abc123")
|
33
|
+
.to(:remove)
|
34
|
+
is_expected.to route_command("#{name} list abc123").to(:list)
|
47
35
|
end
|
48
36
|
end
|
49
37
|
|
@@ -51,90 +39,85 @@ describe Lita::Handlers::Deploygate, lita_handler: true do
|
|
51
39
|
before do
|
52
40
|
Lita.config.handlers.deploygate.user_name = 'foo'
|
53
41
|
Lita.config.handlers.deploygate.api_key = 'bar'
|
54
|
-
Lita.config.handlers.deploygate.app_names = { 'abc123' =>
|
42
|
+
Lita.config.handlers.deploygate.app_names = { 'abc123' =>
|
43
|
+
'path/to/places' }
|
55
44
|
end
|
56
45
|
|
57
46
|
describe '#add' do
|
58
47
|
it 'shows an ack when a username is added' do
|
59
|
-
|
60
|
-
expect_any_instance_of(Faraday::Connection).to receive(:post).once.and_return(response)
|
48
|
+
grab_request('post', 200, members_add)
|
61
49
|
send_command('deploygate add username abc123')
|
62
50
|
expect(replies.last).to eq('abc123: username added')
|
63
51
|
end
|
64
52
|
|
65
53
|
it 'shows an ack when an email is added' do
|
66
|
-
|
67
|
-
expect_any_instance_of(Faraday::Connection).to receive(:post).once.and_return(response)
|
54
|
+
grab_request('post', 200, members_add)
|
68
55
|
send_command('deploygate add foo@example.com abc123')
|
69
56
|
expect(replies.last).to eq('abc123: foo@example.com added')
|
70
57
|
end
|
71
58
|
|
72
|
-
it 'shows a warning if the
|
59
|
+
it 'shows a warning if the app name does not exist' do
|
73
60
|
send_command('deploygate add username doesnotexist')
|
74
61
|
expect(replies.last).to eq('doesnotexist: unknown application name')
|
75
62
|
end
|
76
63
|
|
77
|
-
it 'shows an error if there was an issue
|
78
|
-
|
79
|
-
expect_any_instance_of(Faraday::Connection).to receive(:post).once.and_return(response)
|
64
|
+
it 'shows an error if there was an issue with the request' do
|
65
|
+
grab_request('post', 500, nil)
|
80
66
|
send_command('deploygate add username abc123')
|
81
|
-
expect(replies.last).to eq('There was an error making the request
|
67
|
+
expect(replies.last).to eq('There was an error making the request ' \
|
68
|
+
'to DeployGate')
|
82
69
|
end
|
83
70
|
end
|
84
71
|
|
85
72
|
describe '#remove' do
|
86
73
|
it 'shows an ack when a username is removed' do
|
87
|
-
|
88
|
-
expect_any_instance_of(Faraday::Connection).to receive(:delete).once.and_return(response)
|
74
|
+
grab_request('delete', 200, members_remove)
|
89
75
|
send_command('deploygate remove username abc123')
|
90
76
|
expect(replies.last).to eq('abc123: username removed')
|
91
77
|
end
|
92
78
|
|
93
79
|
it 'shows an ack when an email is removed' do
|
94
|
-
|
95
|
-
expect_any_instance_of(Faraday::Connection).to receive(:delete).once.and_return(response)
|
80
|
+
grab_request('delete', 200, members_remove)
|
96
81
|
send_command('deploygate remove foo@example.com abc123')
|
97
82
|
expect(replies.last).to eq('abc123: foo@example.com removed')
|
98
83
|
end
|
99
84
|
|
100
|
-
it 'shows a warning if the
|
85
|
+
it 'shows a warning if the app name does not exist' do
|
101
86
|
send_command('deploygate remove username doesnotexist')
|
102
87
|
expect(replies.last).to eq('doesnotexist: unknown application name')
|
103
88
|
end
|
104
89
|
|
105
|
-
it 'shows an error if there was an issue
|
106
|
-
|
107
|
-
expect_any_instance_of(Faraday::Connection).to receive(:delete).once.and_return(response)
|
90
|
+
it 'shows an error if there was an issue with the request' do
|
91
|
+
grab_request('delete', 500, nil)
|
108
92
|
send_command('deploygate remove username abc123')
|
109
|
-
expect(replies.last).to eq('There was an error making the request
|
93
|
+
expect(replies.last).to eq('There was an error making the request ' \
|
94
|
+
'to DeployGate')
|
110
95
|
end
|
111
96
|
end
|
112
97
|
|
113
98
|
describe '#list' do
|
114
99
|
it 'shows a list of users when there are any' do
|
115
|
-
|
116
|
-
expect_any_instance_of(Faraday::Connection).to receive(:get).once.and_return(response)
|
100
|
+
grab_request('get', 200, members_full)
|
117
101
|
send_command('deploygate list abc123')
|
118
102
|
expect(replies.last).to eq('abc123: username, role: 1')
|
119
103
|
end
|
120
104
|
|
121
105
|
it 'shows an empty list of users when there arent any' do
|
122
|
-
|
123
|
-
expect_any_instance_of(Faraday::Connection).to receive(:get).once.and_return(response)
|
106
|
+
grab_request('get', 200, members_empty)
|
124
107
|
send_command('deploygate list abc123')
|
125
108
|
expect(replies.last).to eq('abc123: No users')
|
126
109
|
end
|
127
110
|
|
128
|
-
it 'shows a warning if the
|
111
|
+
it 'shows a warning if the app name does not exist' do
|
129
112
|
send_command('deploygate list doesnotexist')
|
130
113
|
expect(replies.last).to eq('doesnotexist: unknown application name')
|
131
114
|
end
|
132
115
|
|
133
|
-
it 'shows an error if there was an issue
|
134
|
-
|
135
|
-
expect_any_instance_of(Faraday::Connection).to receive(:get).once.and_return(response)
|
116
|
+
it 'shows an error if there was an issue with the request' do
|
117
|
+
grab_request('get', 500, nil)
|
136
118
|
send_command('deploygate list abc123')
|
137
|
-
expect(replies.last).to eq('There was an error making the request
|
119
|
+
expect(replies.last).to eq('There was an error making the request ' \
|
120
|
+
'to DeployGate')
|
138
121
|
end
|
139
122
|
end
|
140
123
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-deploygate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Sigler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: multi_json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
description:
|
125
|
+
description: A Deploygate plugin for Lita
|
126
126
|
email:
|
127
127
|
- me@esigler.com
|
128
128
|
executables: []
|
@@ -168,10 +168,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.4.5
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
|
-
summary:
|
174
|
+
summary: A Deploygate plugin for Lita
|
175
175
|
test_files:
|
176
176
|
- spec/files/members_add.json
|
177
177
|
- spec/files/members_empty.json
|