lita-claims 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b0044d0d1c66f9d0e5420a8d51cda79bbd03dc4
4
- data.tar.gz: 9e4156919f937a95262e078c2e9f8b2bdf46ca2c
3
+ metadata.gz: 35767028326bf769d2068db64f74df55a8769a09
4
+ data.tar.gz: 96b80f9a5ff1045f76975b8bb781b99d70d193cd
5
5
  SHA512:
6
- metadata.gz: e27603ccaba2610838a5c47088513152c6eddba1fe7db65cc100df2e8c35dbad902aa34ba0fe2a38169c706fd4af853037a64249cd5a2788afbeace3694edebb
7
- data.tar.gz: 5472a5aaeb0f0fc72b744e8474316beac5bc20dd38df3c69812c6fc9bdd443d37fbd1cadc6b62cac0b40b6aa2f69bc9160ca765de8b29aee8adbd3a6c13e9bf9
6
+ metadata.gz: f4f64bfc9b06be68629ed6a4e498afb3172037341da3a3245291a036424b91bdd878808b9a65b4670b40e38a5f377d3e67a148ad59d6677006e792c29f1c761e
7
+ data.tar.gz: 9554a58ab329527c02dcb2ec891c532713451bcf495dbcf96add536252db42e11e283d128872332ac896fe7f25fb5e208286991a122241e4795ea4a91a71f305
@@ -18,6 +18,33 @@ module Lita
18
18
  "unclaim PROPERTY" => "To remove your claim from a property by the name PROPERTY"
19
19
  })
20
20
 
21
+ route(/^force\sunclaim\s(#{PROPERTY_OR_ENVIRONMENT.source})(?:\s(#{PROPERTY_OR_ENVIRONMENT.source}))?/i, :force_destroy, command: true, help: {
22
+ "force unclaim PROPERTY" => "To remove a claim by someone else from a property by the name PROPERTY"
23
+ })
24
+
25
+ http.get "/available/:property/:requester(/:environment)", :available
26
+
27
+ def available(request, response)
28
+ property = request.env['router.params'][:property]
29
+ environment = request.env['router.params'][:environment]
30
+ environment_string = " (#{environment})" if environment
31
+ requester = request.env['router.params'][:requester]
32
+ claimer = Claim.read(property, environment)
33
+ if Claim.exists?(property, environment) && claimer != requester
34
+ # forbidden
35
+ response.status = 403
36
+ response.headers["Content-Type"] = "application/json"
37
+ response.body = {claimer: claimer}
38
+ target = Source.new(room: '#devs')
39
+ robot.send_message(target, "#{requester} tried deploying #{property}#{environment_string} but it has been claimed by #{claimer}.")
40
+ else
41
+ # OK
42
+ response.status = 200
43
+ response.headers["Content-Type"] = "application/json"
44
+ response.body = {}
45
+ end
46
+ end
47
+
21
48
  def create(response)
22
49
  claimer = response.message.source.user.name
23
50
  property, environment = response.matches.first
@@ -56,13 +83,26 @@ module Lita
56
83
  Claim.destroy(property, environment)
57
84
  reply = "#{property}#{environment_string} is no longer claimed."
58
85
  else
59
- reply = "#{property}#{environment_string} is currently claimed by #{claimer}. Use the --force flag when you are sure to unclaim the property."
86
+ reply = "#{property}#{environment_string} is currently claimed by #{claimer}. Use the `force unclaim` command when you are sure to unclaim the property."
60
87
  end
61
88
  else
62
89
  reply = "#{property}#{environment_string} has not yet been claimed."
63
90
  end
64
91
  response.reply(reply)
65
92
  end
93
+
94
+ def force_destroy(response)
95
+ property, environment = response.matches.first
96
+ environment ||= 'default'
97
+ environment_string = " (#{environment})" if environment != 'default'
98
+ if property && Claim.exists?(property, environment)
99
+ Claim.destroy(property, environment)
100
+ reply = "#{property}#{environment_string} is no longer claimed."
101
+ else
102
+ reply = "#{property}#{environment_string} has not yet been claimed."
103
+ end
104
+ response.reply(reply)
105
+ end
66
106
  end
67
107
 
68
108
  Lita.register_handler(Claims)
@@ -1,21 +1,22 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-claims"
3
- spec.version = "0.0.2"
3
+ spec.version = "0.0.3"
4
4
  spec.authors = ["Hannes Fostie"]
5
5
  spec.email = ["hannes@maloik.co"]
6
6
  spec.description = %q{A Lita.io plugin to claim 'properties'. Usecases include disabling deployments for environments when they are in use'}
7
7
  spec.summary = %q{A Lita.io plugin to claim 'properties'}
8
8
  spec.homepage = "https://github.com/hannesfostie/lita-claims"
9
9
  spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
10
11
 
11
12
  spec.files = `git ls-files`.split($/)
12
13
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
14
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
15
  spec.require_paths = ["lib"]
15
16
 
16
- spec.add_runtime_dependency "lita", "~> 2.3"
17
+ spec.add_runtime_dependency "lita", ">= 3.1"
17
18
 
18
19
  spec.add_development_dependency "bundler", "~> 1.3"
19
20
  spec.add_development_dependency "rake"
20
- spec.add_development_dependency "rspec", ">= 2.14"
21
+ spec.add_development_dependency "rspec", ">= 3.0.0.beta2"
21
22
  end
@@ -47,11 +47,11 @@ describe Claim, lita: true do
47
47
 
48
48
  describe '#exists?' do
49
49
  it 'returns true if the property exists' do
50
- expect(subject.exists?('property', 'staging')).to be_true
50
+ expect(subject.exists?('property', 'staging')).to be true
51
51
  end
52
52
 
53
53
  it 'returns false if the property does not exist' do
54
- expect(subject.exists?('property_does_not_exist')).to be_false
54
+ expect(subject.exists?('property_does_not_exist')).to be false
55
55
  end
56
56
  end
57
57
  end
@@ -10,19 +10,23 @@ describe Lita::Handlers::Claims, lita_handler: true do
10
10
 
11
11
  it { routes_command('unclaim property').to :destroy }
12
12
  it { routes_command('unclaim property environment').to :destroy }
13
+ it { routes_command('force unclaim property environment').to :force_destroy }
14
+
15
+ it { routes_http(:get, '/available/property_x/someone/staging').to(:available) }
16
+ it { routes_http(:get, '/available/property_x/someone').to(:available) }
13
17
  end
14
18
 
15
19
  describe 'creating claims' do
16
20
  it 'replies that the claim was made' do
17
21
  send_command 'claim property_x'
18
22
  expect(replies.last).to eq('property_x was claimed by Test User.')
19
- expect(Claim.exists?('property_x')).to be_true
23
+ expect(Claim.exists?('property_x')).to be true
20
24
  end
21
25
 
22
26
  it 'replies that the claim was made for a non-default environment' do
23
27
  send_command 'claim property_x environment_y'
24
28
  expect(replies.last).to eq('property_x (environment_y) was claimed by Test User.')
25
- expect(Claim.exists?('property_x', 'environment_y')).to be_true
29
+ expect(Claim.exists?('property_x', 'environment_y')).to be true
26
30
  end
27
31
 
28
32
  it 'replies that a claim could not be made because it already exists' do
@@ -67,14 +71,14 @@ describe Lita::Handlers::Claims, lita_handler: true do
67
71
  Claim.create('property_x', 'Test User')
68
72
  send_command 'unclaim property_x'
69
73
  expect(replies.last).to eq('property_x is no longer claimed.')
70
- expect(Claim.exists?('property_x')).to be_false
74
+ expect(Claim.exists?('property_x')).to be false
71
75
  end
72
76
 
73
77
  it 'removes a claim on a property for a certain environment' do
74
78
  Claim.create('property_x', 'Test User', 'env')
75
79
  send_command 'unclaim property_x env'
76
80
  expect(replies.last).to eq('property_x (env) is no longer claimed.')
77
- expect(Claim.exists?('property_x', 'env')).to be_false
81
+ expect(Claim.exists?('property_x', 'env')).to be false
78
82
  end
79
83
 
80
84
  it 'returns an error when no such claim exists' do
@@ -85,8 +89,38 @@ describe Lita::Handlers::Claims, lita_handler: true do
85
89
  it 'returns an error when the claimer is not the person removing a claim' do
86
90
  Claim.create('property_x', 'Not the test user')
87
91
  send_command 'unclaim property_x'
88
- expect(replies.last).to eq('property_x is currently claimed by Not the test user. Use the --force flag when you are sure to unclaim the property.')
89
- expect(Claim.exists?('property_x')).to be_true
92
+ expect(replies.last).to eq('property_x is currently claimed by Not the test user. Use the `force unclaim` command when you are sure to unclaim the property.')
93
+ expect(Claim.exists?('property_x')).to be true
94
+ end
95
+ end
96
+
97
+ describe 'forcing claim removal' do
98
+ it 'removes your own claim on a property' do
99
+ Claim.create('property_x', 'Test User')
100
+ send_command 'force unclaim property_x'
101
+ expect(replies.last).to eq('property_x is no longer claimed.')
102
+ expect(Claim.exists?('property_x')).to be false
103
+ end
104
+
105
+ it 'removes your own claim on a property for a certain environment' do
106
+ Claim.create('property_x', 'Test User', 'env')
107
+ send_command 'force unclaim property_x env'
108
+ expect(replies.last).to eq('property_x (env) is no longer claimed.')
109
+ expect(Claim.exists?('property_x', 'env')).to be false
110
+ end
111
+
112
+ it "removes another person's claim on a property'"do
113
+ Claim.create('property_x', 'Another User')
114
+ send_command 'force unclaim property_x'
115
+ expect(replies.last).to eq('property_x is no longer claimed.')
116
+ expect(Claim.exists?('property_x')).to be false
117
+ end
118
+
119
+ it "removes another person's claim on a property for a certain environment" do
120
+ Claim.create('property_x', 'Another User', 'env')
121
+ send_command 'force unclaim property_x env'
122
+ expect(replies.last).to eq('property_x (env) is no longer claimed.')
123
+ expect(Claim.exists?('property_x', 'env')).to be false
90
124
  end
91
125
  end
92
126
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-claims
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hannes Fostie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-30 00:00:00.000000000 Z
11
+ date: 2014-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '2.3'
19
+ version: '3.1'
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: '2.3'
26
+ version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '>='
60
60
  - !ruby/object:Gem::Version
61
- version: '2.14'
61
+ version: 3.0.0.beta2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
- version: '2.14'
68
+ version: 3.0.0.beta2
69
69
  description: A Lita.io plugin to claim 'properties'. Usecases include disabling deployments
70
70
  for environments when they are in use'
71
71
  email:
@@ -91,7 +91,8 @@ files:
91
91
  homepage: https://github.com/hannesfostie/lita-claims
92
92
  licenses:
93
93
  - MIT
94
- metadata: {}
94
+ metadata:
95
+ lita_plugin_type: handler
95
96
  post_install_message:
96
97
  rdoc_options: []
97
98
  require_paths: