lita-claims 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +23 -0
- data/Rakefile +6 -0
- data/lib/claim.rb +31 -0
- data/lib/lita-claims.rb +2 -0
- data/lib/lita/handlers/claims.rb +30 -0
- data/lita-claims.gemspec +21 -0
- data/lita_config.rb +30 -0
- data/spec/claim_spec.rb +57 -0
- data/spec/lita/handlers/claims_spec.rb +32 -0
- data/spec/spec_helper.rb +2 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 732d239f96492956b6cb2bc64e1f70f466288e11
|
4
|
+
data.tar.gz: 545d89715a2786c0899c85567f409de45158fd3c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 181fc3798c01853634389ed24b678755ad07a274c19d6238a8ec9175794c3b2c7de2c16c297f48797da0530f8365331ef0a1becbb16f98c9a51f80c7d513ec53
|
7
|
+
data.tar.gz: 3e12eeb56bcfe1844cbde5f2225dc2290ab2e32c19478799c0652f849223a61c2c31308863e3860e8c7b48c5b3507d3524141e7234ec40a81b5f9a5ad470bd66
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Hannes Fostie
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# lita-claims
|
2
|
+
|
3
|
+
TODO: Add a description of the plugin.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add lita-claims to your Lita instance's Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem "lita-claims"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Configuration
|
14
|
+
|
15
|
+
TODO: Describe any configuration attributes the plugin exposes.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
TODO: Describe the plugin's features and how to use them.
|
20
|
+
|
21
|
+
## License
|
22
|
+
|
23
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
data/lib/claim.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class Claim
|
2
|
+
REDIS_NAMESPACE = 'handlers:claims'
|
3
|
+
REDIS_KEY = 'claim'
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def all
|
7
|
+
redis.hkeys(REDIS_KEY)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(property_name, claimer, environment = 'default')
|
11
|
+
return false if self.exists?("#{property_name}_#{environment}")
|
12
|
+
redis.hset(REDIS_KEY, "#{property_name}_#{environment}", claimer)
|
13
|
+
end
|
14
|
+
|
15
|
+
def read(property_name, environment = 'default')
|
16
|
+
redis.hget(REDIS_KEY, "#{property_name}_#{environment}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def destroy(property_name, environment = 'default')
|
20
|
+
redis.hdel(REDIS_KEY, "#{property_name}_#{environment}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def exists?(property_name, environment = 'default')
|
24
|
+
redis.hexists(REDIS_KEY, "#{property_name}_#{environment}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def redis
|
28
|
+
@redis ||= Redis::Namespace.new(REDIS_NAMESPACE, redis: Lita.redis)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/lita-claims.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "lita"
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
module Lita
|
5
|
+
module Handlers
|
6
|
+
class Claims < Handler
|
7
|
+
PROPERTY_OR_ENVIRONMENT = /[\w\-]+/
|
8
|
+
|
9
|
+
route(/^claim\s(#{PROPERTY_OR_ENVIRONMENT.source})(?:\s(#{PROPERTY_OR_ENVIRONMENT.source}))?/i, :create, command: true, help: {
|
10
|
+
"claim PROPERTY" => "To claim a property by the name PROPERTY"
|
11
|
+
})
|
12
|
+
|
13
|
+
def create(response)
|
14
|
+
claimer = response.message.source.user.name
|
15
|
+
property, environment = response.matches.first
|
16
|
+
environment ||= 'default'
|
17
|
+
environment_string = " (#{environment})" if environment != 'default'
|
18
|
+
if property && Claim.create(property, claimer, environment)
|
19
|
+
reply = "#{property}#{environment_string} was claimed by #{claimer}"
|
20
|
+
else
|
21
|
+
existing_claimer = Claim.read(property, environment)
|
22
|
+
reply = "Could not claim #{property}#{environment_string} - already claimed by #{existing_claimer}"
|
23
|
+
end
|
24
|
+
response.reply(reply)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Lita.register_handler(Claims)
|
29
|
+
end
|
30
|
+
end
|
data/lita-claims.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-claims"
|
3
|
+
spec.version = "0.0.1"
|
4
|
+
spec.authors = ["Hannes Fostie"]
|
5
|
+
spec.email = ["hannes@maloik.co"]
|
6
|
+
spec.description = %q{A Lita.io plugin to claim 'properties'. Usecases include disabling deployments for environments when they are in use'}
|
7
|
+
spec.summary = %q{A Lita.io plugin to claim 'properties'}
|
8
|
+
spec.homepage = "https://github.com/hannesfostie/lita-claims"
|
9
|
+
spec.license = "MIT"
|
10
|
+
|
11
|
+
spec.files = `git ls-files`.split($/)
|
12
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_runtime_dependency "lita", "~> 2.3"
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
19
|
+
spec.add_development_dependency "rake"
|
20
|
+
spec.add_development_dependency "rspec", ">= 2.14"
|
21
|
+
end
|
data/lita_config.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Lita.configure do |config|
|
2
|
+
# The name your robot will use.
|
3
|
+
config.robot.name = "Lita"
|
4
|
+
|
5
|
+
# The severity of messages to log. Options are:
|
6
|
+
# :debug, :info, :warn, :error, :fatal
|
7
|
+
# Messages at the selected level and above will be logged.
|
8
|
+
config.robot.log_level = :info
|
9
|
+
|
10
|
+
# An array of user IDs that are considered administrators. These users
|
11
|
+
# the ability to add and remove other users from authorization groups.
|
12
|
+
# What is considered a user ID will change depending on which adapter you use.
|
13
|
+
# config.robot.admins = ["1", "2"]
|
14
|
+
|
15
|
+
# The adapter you want to connect with. Make sure you've added the
|
16
|
+
# appropriate gem to the Gemfile.
|
17
|
+
config.robot.adapter = :shell
|
18
|
+
|
19
|
+
## Example: Set options for the chosen adapter.
|
20
|
+
# config.adapter.username = "myname"
|
21
|
+
# config.adapter.password = "secret"
|
22
|
+
|
23
|
+
## Example: Set options for the Redis connection.
|
24
|
+
# config.redis.host = "127.0.0.1"
|
25
|
+
# config.redis.port = 1234
|
26
|
+
|
27
|
+
## Example: Set configuration for any loaded handlers. See the handler's
|
28
|
+
## documentation for options.
|
29
|
+
# config.handlers.some_handler.some_config_key = "value"
|
30
|
+
end
|
data/spec/claim_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Claim, lita: true do
|
4
|
+
subject { Claim }
|
5
|
+
before { subject.create("property", "hannes", "staging") }
|
6
|
+
after {
|
7
|
+
subject.all.each do |claim|
|
8
|
+
Claim.destroy(claim)
|
9
|
+
end
|
10
|
+
}
|
11
|
+
|
12
|
+
describe '#all' do
|
13
|
+
it 'returns all claims' do
|
14
|
+
expect(subject.all).to eq(["property_staging"])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#create' do
|
19
|
+
it 'sets the key as the property and the value as the claimer' do
|
20
|
+
subject.create('property', 'hannes', 'staging')
|
21
|
+
expect(subject.read('property', 'staging')).to eq('hannes')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'uses default as the environment if none is passed on' do
|
25
|
+
subject.create('property', 'hannes')
|
26
|
+
expect(subject.read('property', 'default')).to eq('hannes')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#read' do
|
31
|
+
it 'returns the claimer for the question' do
|
32
|
+
expect(subject.read('property', 'staging')).to eq('hannes')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns nil when none is present' do
|
36
|
+
expect(subject.read('does_not', 'exist')).to eq(nil)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#destroy' do
|
41
|
+
it 'updates an unclaimed property' do
|
42
|
+
subject.create('property', 'hannes')
|
43
|
+
subject.destroy('property')
|
44
|
+
expect(subject.read('property')).to be_nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#exists?' do
|
49
|
+
it 'returns true if the property exists' do
|
50
|
+
expect(subject.exists?('property', 'staging')).to be_true
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns false if the property does not exist' do
|
54
|
+
expect(subject.exists?('property_does_not_exist')).to be_false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::Claims, lita_handler: true do
|
4
|
+
describe 'routes' do
|
5
|
+
it { routes_command('claim property').to :create }
|
6
|
+
it { routes_command('claim property environment').to :create }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'creating claims' do
|
10
|
+
it 'replies that the claim was made' do
|
11
|
+
send_command 'claim property_x'
|
12
|
+
expect(replies.last).to eq('property_x was claimed by Test User')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'replies that the claim was made for a non-default environment' do
|
16
|
+
send_command 'claim property_x environment_y'
|
17
|
+
expect(replies.last).to eq('property_x (environment_y) was claimed by Test User')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'replies that a claim could not be made because it already exists' do
|
21
|
+
Claim.create('property', 'Test User')
|
22
|
+
send_command 'claim property'
|
23
|
+
expect(replies.last).to eq('Could not claim property - already claimed by Test User')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'replies that a claim could not be made for a non-default environment because it already exists' do
|
27
|
+
Claim.create('property', 'Test User', 'env')
|
28
|
+
send_command 'claim property env'
|
29
|
+
expect(replies.last).to eq('Could not claim property (env) - already claimed by Test User')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-claims
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hannes Fostie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.14'
|
69
|
+
description: A Lita.io plugin to claim 'properties'. Usecases include disabling deployments
|
70
|
+
for environments when they are in use'
|
71
|
+
email:
|
72
|
+
- hannes@maloik.co
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/claim.rb
|
84
|
+
- lib/lita-claims.rb
|
85
|
+
- lib/lita/handlers/claims.rb
|
86
|
+
- lita-claims.gemspec
|
87
|
+
- lita_config.rb
|
88
|
+
- spec/claim_spec.rb
|
89
|
+
- spec/lita/handlers/claims_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: https://github.com/hannesfostie/lita-claims
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: A Lita.io plugin to claim 'properties'
|
115
|
+
test_files:
|
116
|
+
- spec/claim_spec.rb
|
117
|
+
- spec/lita/handlers/claims_spec.rb
|
118
|
+
- spec/spec_helper.rb
|