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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 477a51d7644b360d5cf0dbf25f20745ad017d3bd
4
- data.tar.gz: 9a2003bfed68731cc1820ce86d2fd73deacb9bc1
3
+ metadata.gz: 38bbbee6ec20f8cce043f2d1c759d30261d86a28
4
+ data.tar.gz: e74f13293333bd906f036842e15595d2a6a08428
5
5
  SHA512:
6
- metadata.gz: a6b32a9bdcd887642b0a541e96953700a2f1390837ceef6dab775e0c3da1723b782550fea380d0dbeb0342d2fb5441108b1ad0827a1a7a6ddd10a05514e31613
7
- data.tar.gz: 3bd7e9f3086be31a0428b8b7a6c6bd493b7c12c7b0ad3c7ce5885a16a34237933a660575e4747b84af842e1e7c8613c8ed8b6ac5eadae51fb507c0cde62b9348
6
+ metadata.gz: 8f302790c5949e94eeff407e35b8275035a8e18e2e2dfe801874aec617192c582730593d0bcf8a4586c723055f98c317e6e6b55f8868a92cf3b7182fd7cb62b8
7
+ data.tar.gz: b3999b0c146778044f4a29a018ecfc9bc31d85768fd17362efa108ef86d1753dc4dd2c6dd3d53585a5d9a59f5ff9d3610237aa45548e8849fe6d7d0a24e3d1ac
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.swp
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
@@ -1,17 +1,7 @@
1
- ClassLength:
2
- Max: 400
3
-
4
- CyclomaticComplexity:
5
- Max: 10
6
-
7
1
  Documentation:
8
- Enabled: false
2
+ Exclude:
3
+ - lib/lita/handlers/deploygate.rb
9
4
 
10
5
  FileName:
11
- Enabled: false
12
-
13
- LineLength:
14
- Max: 105
15
-
16
- MethodLength:
17
- Max: 30
6
+ Exclude:
7
+ - lib/lita-deploygate.rb
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- script: bundle exec rake
5
- before_install:
6
- - gem update --system
3
+ - 2.1
4
+ - 2.2
7
5
  services:
8
6
  - redis-server
7
+ sudo: false
8
+ cache: bundler
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
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
- DeployGate (http://deploygate.com) handler for inviting and removing application collaborators.
10
+ A [Deploygate](http://deploygate.com) plugin for [Lita](https://github.com/jimmycuadra/lita).
11
11
 
12
12
  ## Installation
13
13
 
data/Rakefile CHANGED
@@ -3,6 +3,6 @@ require 'rspec/core/rake_task'
3
3
  require 'rubocop/rake_task'
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
- Rubocop::RakeTask.new(:rubocop)
6
+ RuboCop::RakeTask.new(:rubocop)
7
7
 
8
- task default: [ :spec, :rubocop ]
8
+ task default: [:spec, :rubocop]
@@ -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
- 'deploygate add <username or email> <short name>' =>
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
- 'deploygate remove <username or email> <short name>' =>
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
- 'deploygate list <short name>' =>
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
- short_name = response.matches[0][2]
42
- user_identifier = response.matches[0][1]
43
- if valid_app_name?(short_name)
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
- short_name = response.matches[0][2]
59
- user_identifier = response.matches[0][1]
60
- if valid_app_name?(short_name)
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
- short_name = response.matches[0][1]
76
- if valid_app_name?(short_name)
77
- result = api_request('get', "/#{app_path(short_name)}/members")
78
- if result
79
- users = result['results']['users']
80
- if users.count > 0
81
- users.each do |user|
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
- if Lita.config.handlers.deploygate.user_name.nil? ||
107
- Lita.config.handlers.deploygate.api_key.nil?
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
- if http_response.status == 200 ||
123
- http_response.status == 201
124
- MultiJson.load(http_response.body)
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)
@@ -1,20 +1,20 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-deploygate'
3
- spec.version = '0.1.0'
3
+ spec.version = '0.1.1'
4
4
  spec.authors = ['Eric Sigler']
5
5
  spec.email = ['me@esigler.com']
6
- spec.description = %q{Add, remove members to Deploygate releases}
7
- spec.summary = %q{Add, remove members to Deploygate releases}
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/}) { |f| File.basename(f) }
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', '>= 3.1'
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'
@@ -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
- it { routes_command('deploygate add username abc123').to(:add) }
21
- it { routes_command('deploygate add foo@example.com abc123').to(:add) }
22
- it { routes_command('deploygate remove username abc123').to(:remove) }
23
- it { routes_command('deploygate remove foo@example.com abc123').to(:remove) }
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
- describe 'without valid config' do
44
- it 'errors out on any command' do
45
- Lita.config.handlers.deploygate.app_names = { 'abc123' => 'path/to/places' }
46
- expect { send_command('dg list abc123') }.to raise_error('Missing config')
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' => 'path/to/places' }
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
- response = double('Faraday::Response', status: 200, body: members_add)
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
- response = double('Faraday::Response', status: 200, body: members_add)
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 short name does not exist when adding someone' do
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 adding someone' do
78
- response = double('Faraday::Response', status: 500, body: nil)
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 to DeployGate')
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
- response = double('Faraday::Response', status: 200, body: members_remove)
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
- response = double('Faraday::Response', status: 200, body: members_remove)
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 short name does not exist when removing someone' do
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 removing someone' do
106
- response = double('Faraday::Response', status: 500, body: nil)
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 to DeployGate')
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
- response = double('Faraday::Response', status: 200, body: members_full)
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
- response = double('Faraday::Response', status: 200, body: members_empty)
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 short name does not exist when listing' do
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 listing users' do
134
- response = double('Faraday::Response', status: 500, body: nil)
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 to DeployGate')
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
@@ -8,3 +8,5 @@ SimpleCov.start { add_filter '/spec/' }
8
8
 
9
9
  require 'lita-deploygate'
10
10
  require 'lita/rspec'
11
+
12
+ Lita.version_3_compatibility_mode = false
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.0
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: 2014-04-12 00:00:00.000000000 Z
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: '3.1'
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: '3.1'
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: Add, remove members to Deploygate releases
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.2.1
171
+ rubygems_version: 2.4.5
172
172
  signing_key:
173
173
  specification_version: 4
174
- summary: Add, remove members to Deploygate releases
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