lita-envy 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fefb7d9332f5bba20cfcf815f152d9c08543d13e
4
+ data.tar.gz: 79bb292a9a52240e40f50a213a867a95680df83a
5
+ SHA512:
6
+ metadata.gz: 9ff2ddd4e7d3eff8bb6b905cbecd05a34dcb877d7a880dd4d427070ae4f8de869689ff74c7a5933131d58a566887009dab7ae3640973d2bb07f119ad8a6d2b6d
7
+ data.tar.gz: bea1f158534a2d257cd8ede909fb9d4b76e332b8b37ddef3639a995c8e9949dcef4aca1599cc684b51ccd525b2a7f843ca9ccb0ef3ea785e74eb278ba32dcadf
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # lita-envy
2
+
3
+ [![Build Status](https://travis-ci.org/ingoweiss/lita-envy.png?branch=master)](https://travis-ci.org/ingoweiss/lita-envy)
4
+ [![Coverage Status](https://coveralls.io/repos/ingoweiss/lita-envy/badge.png)](https://coveralls.io/r/ingoweiss/lita-envy)
5
+
6
+ Record and retrieve information about environment usage
7
+
8
+ ## Installation
9
+
10
+ Add lita-envy to your Lita instance's Gemfile:
11
+
12
+ ``` ruby
13
+ gem "lita-envy"
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ``` bash
19
+ @bot started using env ENV123
20
+ @bot stopped using env ENV123
21
+ ```
22
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,66 @@
1
+ module Lita
2
+ module Handlers
3
+ class Envy < Handler
4
+
5
+ route /\Astarted using env ([A-Za-z0-9_]+)\Z/, :start_using_environment, help: { "started using env [ENV ID]" => "Mark environment as in use by you"}, command: true
6
+ route /\Astopped using env ([A-Za-z0-9_]+)\Z/, :stop_using_environment, help: { "stopped using env [ENV ID]" => "Mark environment as available"}, command: true
7
+ route /\Aenvironments\Z/, :list_environments, help: { "environments" => "List environments"}, command: true
8
+ route /\Aremove env ([A-Za-z0-9_]+)\Z/, :remove_environment, help: { "remove env [ENV ID]" => "Remove environment"}, command: true
9
+ route /\Awrestle env ([A-Za-z0-9_]+) from (.*)\Z/, :wrestle_environment_from_user, help: { "wrestle env [ENV ID] from [USER]" => "Mark environment as in use by you, even though it is currently in use by another user"}, command: true
10
+
11
+ def start_using_environment(response)
12
+ env_id = response.matches.first.first
13
+ current_user = redis.hget(['environments', env_id].join(':'), 'user')
14
+ if current_user.nil?
15
+ redis.hset(['environments', env_id].join(':'), 'user', response.user.name)
16
+ response.reply('ok')
17
+ elsif current_user == response.user.name
18
+ response.reply("You are already using #{env_id}")
19
+ else
20
+ response.reply("Sorry, #{env_id} is currently in use by #{current_user}")
21
+ end
22
+ end
23
+
24
+ def stop_using_environment(response)
25
+ env_id = response.matches.first.first
26
+ redis.hset(['environments', env_id].join(':'), 'user', nil)
27
+ response.reply('ok')
28
+ end
29
+
30
+ def list_environments(response)
31
+ lines = []
32
+ redis.keys('environments:*').sort.each do |key|
33
+ env_id = key.split(':').last
34
+ user = redis.hget(key, 'user')
35
+ line = env_id
36
+ line += " (#{user})" unless user.empty?
37
+ lines << line
38
+ end
39
+ response.reply(lines.join("\n"))
40
+ end
41
+
42
+ def remove_environment(response)
43
+ env_id = response.matches.first.first
44
+ redis.del(['environments', env_id].join(':'))
45
+ response.reply('ok')
46
+ end
47
+
48
+ def wrestle_environment_from_user(response)
49
+ env_id, specified_user = response.matches.first
50
+ current_user = redis.hget(['environments', env_id].join(':'), 'user')
51
+ if specified_user == current_user
52
+ redis.hset(['environments', env_id].join(':'), 'user', response.user.name)
53
+ response.reply('ok')
54
+ elsif current_user.nil? or current_user.empty?
55
+ response.reply("Sorry, #{env_id} is not currently in use")
56
+ elsif current_user == response.user.name
57
+ response.reply("You are already using #{env_id}")
58
+ else
59
+ response.reply("Sorry, #{env_id} is currently in use by #{current_user}, not #{specified_user}")
60
+ end
61
+ end
62
+
63
+ Lita.register_handler(self)
64
+ end
65
+ end
66
+ end
data/lib/lita-envy.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/envy"
8
+
9
+ Lita::Handlers::Envy.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
data/lita-envy.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-envy"
3
+ spec.version = "0.1.1"
4
+ spec.authors = ["Ingo Weiss"]
5
+ spec.email = ["ingo.weiss@lab49.com"]
6
+ spec.description = "Mark environments as in use. Mark environments as available. List environments"
7
+ spec.summary = "Record and retrieve information about environment usage"
8
+ spec.homepage = "https://github.com/ingoweiss/lita-envy"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
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)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.6"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "pry-byebug"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rack-test"
23
+ spec.add_development_dependency "rspec", ">= 3.0.0"
24
+ spec.add_development_dependency "simplecov"
25
+ spec.add_development_dependency "coveralls"
26
+ spec.add_development_dependency "byebug"
27
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ envy:
@@ -0,0 +1,178 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Envy, lita_handler: true do
4
+
5
+ describe 'routing' do
6
+
7
+ it { is_expected.to route_command("started using env ENV123").to(:start_using_environment) }
8
+ it { is_expected.to route_command("stopped using env ENV123").to(:stop_using_environment) }
9
+ it { is_expected.to route_command("environments").to(:list_environments) }
10
+ it { is_expected.to route_command("remove env ENV123").to(:remove_environment) }
11
+ it { is_expected.to route_command("wrestle env ENV123 from Alicia").to(:wrestle_environment_from_user) }
12
+
13
+ end
14
+
15
+ describe 'start using environment' do
16
+
17
+ it "should mark environment as in use" do
18
+ carl = Lita::User.create(123, name: "Carl")
19
+ send_command('started using env ENV123', :as => carl)
20
+ expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
21
+ end
22
+
23
+ it "should confirm" do
24
+ send_command('started using env ENV123')
25
+ expect(replies.first).to eq("ok")
26
+ end
27
+
28
+ it "should not change the user if the environment is already in use" do
29
+ subject.redis.hset('environments:ENV123', 'user', 'Alicia')
30
+ carl = Lita::User.create(123, name: "Carl")
31
+ send_command('started using env ENV123', :as => carl)
32
+ expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Alicia")
33
+ end
34
+
35
+ it "should notify the user if the environment is already in use" do
36
+ subject.redis.hset('environments:ENV123', 'user', 'Alicia')
37
+ carl = Lita::User.create(123, name: "Carl")
38
+ send_command('started using env ENV123', :as => carl)
39
+ expect(replies.first).to eq("Sorry, ENV123 is currently in use by Alicia")
40
+ end
41
+
42
+ it "should notify the user if the environment is already marked as in use by user" do
43
+ subject.redis.hset('environments:ENV123', 'user', 'Carl')
44
+ carl = Lita::User.create(123, name: "Carl")
45
+ send_command('started using env ENV123', :as => carl)
46
+ expect(replies.first).to eq("You are already using ENV123")
47
+ end
48
+
49
+ end
50
+
51
+ describe 'stop using environment' do
52
+
53
+ it "should mark environment as available" do
54
+ subject.redis.hset('environments:ENV123', 'user', 'Alicia')
55
+ send_command('stopped using env ENV123')
56
+ expect(subject.redis.hget('environments:ENV123', 'user')).to be_empty
57
+ end
58
+
59
+ it "should confirm" do
60
+ send_command('stopped using env ENV123')
61
+ expect(replies.first).to eq("ok")
62
+ end
63
+
64
+ end
65
+
66
+ describe 'list environments' do
67
+
68
+ it "should list environments" do
69
+ subject.redis.hset('environments:ENV123', 'user', 'Alicia')
70
+ subject.redis.hset('environments:ENV234', 'user', 'Carl')
71
+ subject.redis.hset('environments:ENV345', 'user', nil)
72
+ send_command('environments')
73
+ expect(replies.first.split("\n")).to eq([
74
+ "ENV123 (Alicia)",
75
+ "ENV234 (Carl)",
76
+ "ENV345"
77
+ ])
78
+ end
79
+
80
+ end
81
+
82
+ describe 'remove environment' do
83
+
84
+ it "should remove environments" do
85
+ subject.redis.hset('environments:ENV123', 'user', 'Alicia')
86
+ send_command('remove env ENV123')
87
+ expect(subject.redis.keys).to_not include('environments:ENV123')
88
+ end
89
+
90
+ it "should confirm" do
91
+ send_command('remove env ENV123')
92
+ expect(replies.first).to eq("ok")
93
+ end
94
+
95
+ end
96
+
97
+ describe 'wrestle environment from user' do
98
+
99
+ context "when environment is currently in use by specified user" do
100
+
101
+ before(:each) do
102
+ subject.redis.hset('environments:ENV123', 'user', 'Alicia')
103
+ end
104
+
105
+ it "should mark environment as in use" do
106
+ carl = Lita::User.create(123, name: "Carl")
107
+ send_command('wrestle env ENV123 from Alicia', :as => carl)
108
+ expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
109
+ end
110
+
111
+ it "should confirm" do
112
+ send_command('wrestle env ENV123 from Alicia')
113
+ expect(replies.first).to eq("ok")
114
+ end
115
+
116
+ end
117
+
118
+ context "when environment is currently in use by a user other than the specified one" do
119
+
120
+ before(:each) do
121
+ subject.redis.hset('environments:ENV123', 'user', 'Alicia')
122
+ end
123
+
124
+ it "should not mark environment" do
125
+ carl = Lita::User.create(123, name: "Carl")
126
+ send_command('wrestle env ENV123 from Ben', :as => carl)
127
+ expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Alicia")
128
+ end
129
+
130
+ it "should notify the user" do
131
+ send_command('wrestle env ENV123 from Ben')
132
+ expect(replies.first).to eq("Sorry, ENV123 is currently in use by Alicia, not Ben")
133
+ end
134
+
135
+ end
136
+
137
+ context "when environment is not currently in use" do
138
+
139
+ before(:each) do
140
+ subject.redis.hset('environments:ENV123', 'user', nil)
141
+ end
142
+
143
+ it "should not mark environment" do
144
+ carl = Lita::User.create(123, name: "Carl")
145
+ send_command('wrestle env ENV123 from Ben', :as => carl)
146
+ expect(subject.redis.hget('environments:ENV123', 'user')).to be_empty
147
+ end
148
+
149
+ it "should notify the user" do
150
+ send_command('wrestle env ENV123 from Ben')
151
+ expect(replies.first).to eq("Sorry, ENV123 is not currently in use")
152
+ end
153
+
154
+ end
155
+
156
+ context "when environment is already marked as in use by requesting user" do
157
+
158
+ before(:each) do
159
+ subject.redis.hset('environments:ENV123', 'user', 'Carl')
160
+ end
161
+
162
+ it "should not mark environment" do
163
+ carl = Lita::User.create(123, name: "Carl")
164
+ send_command('wrestle env ENV123 from Ben', :as => carl)
165
+ expect(subject.redis.hget('environments:ENV123', 'user')).to eq('Carl')
166
+ end
167
+
168
+ it "should notify the user" do
169
+ carl = Lita::User.create(123, name: "Carl")
170
+ send_command('wrestle env ENV123 from Ben', :as => carl)
171
+ expect(replies.first).to eq("You are already using ENV123")
172
+ end
173
+
174
+ end
175
+
176
+ end
177
+
178
+ end
@@ -0,0 +1,15 @@
1
+ require 'byebug'
2
+ require "simplecov"
3
+ require "coveralls"
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start { add_filter "/spec/" }
9
+
10
+ require "lita-envy"
11
+ require "lita/rspec"
12
+
13
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
14
+ # was generated with Lita 4, the compatibility mode should be left disabled.
15
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-envy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Ingo Weiss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-01 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: '4.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '4.6'
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: pry-byebug
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: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Mark environments as in use. Mark environments as available. List environments
140
+ email:
141
+ - ingo.weiss@lab49.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - .travis.yml
148
+ - Gemfile
149
+ - README.md
150
+ - Rakefile
151
+ - lib/lita-envy.rb
152
+ - lib/lita/handlers/envy.rb
153
+ - lita-envy.gemspec
154
+ - locales/en.yml
155
+ - spec/lita/handlers/envy_spec.rb
156
+ - spec/spec_helper.rb
157
+ - templates/.gitkeep
158
+ homepage: https://github.com/ingoweiss/lita-envy
159
+ licenses:
160
+ - MIT
161
+ metadata:
162
+ lita_plugin_type: handler
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.2.2
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Record and retrieve information about environment usage
183
+ test_files:
184
+ - spec/lita/handlers/envy_spec.rb
185
+ - spec/spec_helper.rb