lita 2.2.1 → 2.3.0

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: ffbba6c703174e7a6984339b41e1b6b3ce01e617
4
- data.tar.gz: 5d30f8db3d352fd2dacf9e3fb752d434ab6230d4
3
+ metadata.gz: 413787eadeaaa5e58440f591d404423c90e7b95d
4
+ data.tar.gz: 4114e0ac515a2068a361e4f6fdfcd0103ed27e8a
5
5
  SHA512:
6
- metadata.gz: e5d699a894adf21dd032822f4b3e03b1271e4f49d1330abe1cef0a99d4af9f710aa2934277474ae6a72700b16fc48abee34777f6ca9bec34fc19a7fb6c421009
7
- data.tar.gz: 62e5a1586f950a4385d40c0cab802d7e9eef5dd07900657ef8640dc59ad9c4a9a3972b402c327f6cff2c83be9ad933ce2f4adc7ef4a5699093fb3b9ffcb2870d
6
+ metadata.gz: 58c0d8117141c1809f73422a581bc7a11693eca37f02234abddb913fc70ce631a5026320a4fdfc09f1ec772eb0501301c656fcf750d7a35a23e85415b7ce8d8d
7
+ data.tar.gz: bfb5bc4df0cc27e9d242e30beca7e6ae7683f3655dc29dc7ed575fde39c40e62a0a6b3b84746c826fdf5b48e65e5b1de3ac09fe9bc5ba19eb6e48d4bd23ad108
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .idea
19
+
data/README.md CHANGED
@@ -20,6 +20,7 @@ Automate your business and have fun with your very own robot companion.
20
20
  * Support for outgoing HTTP requests
21
21
  * Group-based authorization
22
22
  * Configurable logging
23
+ * Generators for creating new plugins
23
24
 
24
25
  ## Why?
25
26
 
@@ -137,6 +138,8 @@ Lita ships with one adapter for use directly in the shell. Simply type text at t
137
138
 
138
139
  An adapter is a packaged as a RubyGem. The adapter is a class that inherits from `Lita::Adapter`, implements a few required methods, and is registered by calling `Lita.register_adapter(:symbol_that_identifies_the_adapter, TheAdapterClass)`.
139
140
 
141
+ To generate a starting template for a new adapter gem, run `lita adapter NAME`, where NAME is the name of the new gem.
142
+
140
143
  ### Example
141
144
 
142
145
  Here is a bare bones example of an adapter for the fictious chat service, FancyChat.
@@ -180,6 +183,8 @@ For more detailed examples, check out the built in shell adapter, [lita-hipchat]
180
183
 
181
184
  A handler is packaged as a RubyGem. A handler is a class that inherits from `Lita::Handler` and is registered by calling `Lita.register_handler(TheHandlerClass)`. There are two components to a handler: route definitions, and the methods that implement those routes. There are both chat routes and HTTP routes available to handlers.
182
185
 
186
+ To generate a starting template for a new handler gem, run `lita handler NAME`, where NAME is the name of the new gem.
187
+
183
188
  ### Chat routes
184
189
 
185
190
  To define a route, use the class method `route`:
data/lib/lita.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "forwardable"
2
2
  require "logger"
3
+ require "rbconfig"
3
4
  require "set"
4
5
  require "shellwords"
5
6
 
@@ -12,9 +12,14 @@ module Lita
12
12
 
13
13
  loop do
14
14
  print "#{robot.name} > "
15
- input = $stdin.gets.chomp.strip
15
+ input = $stdin.gets
16
+ if input.nil?
17
+ puts
18
+ break
19
+ end
20
+ input = input.chomp.strip
16
21
  break if input == "exit" || input == "quit"
17
- robot.receive(build_message(robot, input, source))
22
+ robot.receive(build_message(input, source))
18
23
  end
19
24
  end
20
25
 
@@ -24,6 +29,11 @@ module Lita
24
29
  # @param strings [Array<String>] An array of strings to output.
25
30
  # @return [void]
26
31
  def send_messages(target, strings)
32
+ strings = Array(strings)
33
+ strings.reject! { |string| string.empty? }
34
+ unless RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ || !$stdout.tty?
35
+ strings.map! { |string| "\e[32m#{string}\e[0m" }
36
+ end
27
37
  puts strings
28
38
  end
29
39
 
@@ -35,7 +45,7 @@ module Lita
35
45
 
36
46
  private
37
47
 
38
- def build_message(robot, input, source)
48
+ def build_message(input, source)
39
49
  message = Message.new(robot, input, source)
40
50
  message.command! if Lita.config.adapter.private_chat
41
51
  message
data/lib/lita/cli.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "thor"
2
2
 
3
3
  require "lita/daemon"
4
+ require "lita/version"
4
5
 
5
6
  module Lita
6
7
  # The command line interface for Lita.
@@ -8,46 +9,50 @@ module Lita
8
9
  include Thor::Actions
9
10
 
10
11
  def self.source_root
11
- File.expand_path("../../..", __FILE__)
12
+ File.expand_path("../../../templates", __FILE__)
12
13
  end
13
14
 
14
15
  default_task :start
15
16
 
16
- class_option :config,
17
+ desc "start", "Starts Lita"
18
+ option :config,
17
19
  aliases: "-c",
18
20
  banner: "PATH",
19
21
  default: File.expand_path("lita_config.rb", Dir.pwd),
20
22
  desc: "Path to the configuration file to use"
21
-
22
- class_option :daemonize,
23
+ option :daemonize,
23
24
  aliases: "-d",
24
25
  default: false,
25
26
  desc: "Run Lita as a daemon",
26
27
  type: :boolean
27
-
28
- class_option :log_file,
28
+ option :log_file,
29
29
  aliases: "-l",
30
30
  banner: "PATH",
31
31
  default: Process.euid == 0 ?
32
32
  "/var/log/lita.log" : File.expand_path("lita.log", ENV["HOME"]),
33
33
  desc: "Path where the log file should be written when daemonized"
34
-
35
- class_option :pid_file,
34
+ option :pid_file,
36
35
  aliases: "-p",
37
36
  banner: "PATH",
38
37
  default: Process.euid == 0 ?
39
38
  "/var/run/lita.pid" : File.expand_path("lita.pid", ENV["HOME"]),
40
39
  desc: "Path where the PID file should be written when daemonized"
41
-
42
- class_option :kill,
40
+ option :kill,
43
41
  aliases: "-k",
44
42
  default: false,
45
43
  desc: "Kill existing Lita processes when starting the daemon",
46
44
  type: :boolean
47
-
48
- desc "start", "Starts Lita"
49
45
  def start
50
- Bundler.require
46
+ begin
47
+ Bundler.require
48
+ rescue Bundler::GemfileNotFound
49
+ no_gemfile_warning = <<-WARN.chomp
50
+ The default command "start" must be run inside a Lita project. Try running \
51
+ `lita new` to generate a new Lita project or `lita help` to see all commands.
52
+ WARN
53
+ say no_gemfile_warning, :red
54
+ abort
55
+ end
51
56
 
52
57
  if options[:daemonize]
53
58
  Daemon.new(
@@ -62,7 +67,108 @@ module Lita
62
67
 
63
68
  desc "new NAME", "Generates a new Lita project (default name: lita)"
64
69
  def new(name = "lita")
65
- directory "skeleton", name
70
+ directory "robot", name
71
+ end
72
+
73
+ desc "adapter NAME", "Generates a new Lita adapter"
74
+ def adapter(name)
75
+ generate_templates(generate_config(name, "adapter"))
76
+ end
77
+
78
+ desc "handler NAME", "Generates a new Lita handler"
79
+ def handler(name)
80
+ generate_templates(generate_config(name, "handler"))
81
+ end
82
+
83
+ desc "version", "Outputs the current version of Lita"
84
+ def version
85
+ puts VERSION
86
+ end
87
+ map %w(-v --version) => :version
88
+
89
+ private
90
+
91
+ def generate_config(name, plugin_type)
92
+ name, gem_name = normalize_names(name)
93
+ constant_name = name.split(/_/).map { |p| p.capitalize }.join
94
+ namespace = "#{plugin_type}s"
95
+ constant_namespace = namespace.capitalize
96
+ spec_type = plugin_type == "handler" ? "lita_handler" : "lita"
97
+ required_lita_version = Lita::VERSION.split(/\./)[0...-1].join(".")
98
+
99
+ {
100
+ name: name,
101
+ gem_name: gem_name,
102
+ constant_name: constant_name,
103
+ plugin_type: plugin_type,
104
+ namespace: namespace,
105
+ constant_namespace: constant_namespace,
106
+ spec_type: spec_type,
107
+ required_lita_version: required_lita_version
108
+ }.merge(generate_user_config).merge(optional_content)
109
+ end
110
+
111
+ def generate_user_config
112
+ git_user = `git config user.name`.chomp
113
+ git_user = "TODO: Write your name" if git_user.empty?
114
+ git_email = `git config user.email`.chomp
115
+ git_email = "TODO: Write your email address" if git_email.empty?
116
+
117
+ {
118
+ author: git_user,
119
+ email: git_email
120
+ }
121
+ end
122
+
123
+ def generate_templates(config)
124
+ name = config[:name]
125
+ gem_name = config[:gem_name]
126
+ namespace = config[:namespace]
127
+ travis = config[:travis]
128
+
129
+ target = File.join(Dir.pwd, gem_name)
130
+
131
+ template(
132
+ "plugin/lib/lita/plugin_type/plugin.tt",
133
+ "#{target}/lib/lita/#{namespace}/#{name}.rb",
134
+ config
135
+ )
136
+ template("plugin/lib/plugin.tt", "#{target}/lib/#{gem_name}.rb", config)
137
+ template(
138
+ "plugin/spec/lita/plugin_type/plugin_spec.tt",
139
+ "#{target}/spec/lita/#{namespace}/#{name}_spec.rb",
140
+ config
141
+ )
142
+ template(
143
+ "plugin/spec/spec_helper.tt",
144
+ "#{target}/spec/spec_helper.rb",
145
+ config
146
+ )
147
+ copy_file("plugin/Gemfile", "#{target}/Gemfile")
148
+ template("plugin/gemspec.tt", "#{target}/#{gem_name}.gemspec", config)
149
+ copy_file("plugin/gitignore", "#{target}/.gitignore")
150
+ copy_file("plugin/travis.yml", "#{target}/.travis.yml") if travis
151
+ template("plugin/LICENSE.tt", "#{target}/LICENSE", config)
152
+ copy_file("plugin/Rakefile", "#{target}/Rakefile")
153
+ template("plugin/README.tt", "#{target}/README.md", config)
154
+ end
155
+
156
+ def normalize_names(name)
157
+ name = name.downcase.sub(/^lita[_-]/, "")
158
+ gem_name = "lita-#{name}"
159
+ name = name.tr("-", "_")
160
+ [name, gem_name]
161
+ end
162
+
163
+ def optional_content
164
+ coveralls_question = <<-Q.chomp
165
+ Do you want to generate code coverage information with SimpleCov \
166
+ and Coveralls.io?
167
+ Q
168
+ {
169
+ travis: yes?("Do you want to test your plugin on Travis CI?"),
170
+ coveralls: yes?(coveralls_question)
171
+ }
66
172
  end
67
173
  end
68
174
  end
data/lib/lita/handler.rb CHANGED
@@ -102,15 +102,15 @@ module Lita
102
102
 
103
103
  # Determines whether or not an incoming messages should trigger a route.
104
104
  def route_applies?(route, message, robot)
105
- # Message must match the pattern
106
- return unless route.pattern === message.body
107
-
108
105
  # Message must be a command if the route requires a command
109
106
  return if route.command? && !message.command?
110
107
 
111
108
  # Messages from self should be ignored to prevent infinite loops
112
109
  return if message.user.name == robot.name
113
110
 
111
+ # Message must match the pattern
112
+ return unless route.pattern === message.body
113
+
114
114
  # User must be in auth group if route is restricted
115
115
  return unless authorized?(message.user, route.required_groups)
116
116
 
data/lib/lita/response.rb CHANGED
@@ -18,7 +18,7 @@ module Lita
18
18
  # @see Lita::Message#reply
19
19
  # @!method user
20
20
  # @see Lita::Message#user
21
- def_delegators :message, :args, :reply, :user
21
+ def_delegators :message, :args, :reply, :user, :command?
22
22
 
23
23
  # @param message [Lita::Message] The incoming message.
24
24
  # @param matches [Array<String>, Array<Array<String>>] The Regexp matches.
data/lib/lita/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Lita
2
2
  # The current version of Lita.
3
- VERSION = "2.2.1"
3
+ VERSION = "2.3.0"
4
4
  end
@@ -26,9 +26,16 @@ describe Lita::Adapters::Shell do
26
26
 
27
27
  describe "#send_message" do
28
28
  it "prints its input" do
29
- expect(subject).to receive(:puts).with("bar")
29
+ expect(subject).to receive(:puts) do |messages|
30
+ expect(messages.first).to include("bar")
31
+ end
30
32
  subject.send_messages(double("target"), "bar")
31
33
  end
34
+
35
+ it "doesn't output empty messages" do
36
+ expect(subject).to receive(:puts).with([])
37
+ subject.send_messages(double("target"), "")
38
+ end
32
39
  end
33
40
 
34
41
  describe "#shut_down" do
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Response do
4
+ subject { described_class.new(message) }
5
+
6
+ let(:message) { double("Lita::Message").as_null_object }
7
+
8
+ [:args, :reply, :user, :command?].each do |method|
9
+ it "delegates :#{method} to #message" do
10
+ expect(message).to receive(method)
11
+ subject.public_send(method)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,19 @@
1
+ Copyright (c) <%= Time.now.year %> <%= config[:author] %>
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.
@@ -0,0 +1,23 @@
1
+ # <%= config[:gem_name] %>
2
+
3
+ TODO: Add a description of the plugin.
4
+
5
+ ## Installation
6
+
7
+ Add <%= config[:gem_name] %> to your Lita instance's Gemfile:
8
+
9
+ ``` ruby
10
+ gem "<%= config[:gem_name] %>"
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)
@@ -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,25 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "<%= config[:gem_name] %>"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["<%= config[:author] %>"]
5
+ spec.email = ["<%= config[:email] %>"]
6
+ spec.description = %q{TODO: Add a description}
7
+ spec.summary = %q{TODO: Add a summary}
8
+ spec.homepage = "TODO: Add a homepage"
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", "~> <%= config[:required_lita_version] %>"
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "rspec", ">= 2.14"
21
+ <%- if config[:coveralls] -%>
22
+ spec.add_development_dependency "simplecov"
23
+ spec.add_development_dependency "coveralls"
24
+ <%- end -%>
25
+ end
@@ -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
@@ -0,0 +1,14 @@
1
+ require "lita"
2
+
3
+ module Lita
4
+ module <%= config[:constant_namespace] %>
5
+ class <%= config[:constant_name] %> < <%= config[:plugin_type].capitalize %>
6
+ end
7
+
8
+ <%- if config[:plugin_type] == "adapter" -%>
9
+ Lita.register_adapter(:<%= config[:name] %>, <%= config[:constant_name] %>)
10
+ <%- else -%>
11
+ Lita.register_handler(<%= config[:constant_name] %>)
12
+ <%- end -%>
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ require "lita/<%= config[:namespace] %>/<%= config[:name] %>"
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::<%= config[:constant_namespace] %>::<%= config[:constant_name] %>, <%= config[:spec_type] %>: true do
4
+ end
@@ -0,0 +1,12 @@
1
+ <%- if config[:coveralls] -%>
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
+ <%- end -%>
11
+ require "<%= config[:gem_name] %>"
12
+ require "lita/rspec"
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Cuadra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-17 00:00:00.000000000 Z
11
+ date: 2013-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -231,8 +231,6 @@ files:
231
231
  - lib/lita/util.rb
232
232
  - lib/lita/version.rb
233
233
  - lita.gemspec
234
- - skeleton/Gemfile
235
- - skeleton/lita_config.rb
236
234
  - spec/lita/adapter_spec.rb
237
235
  - spec/lita/adapters/shell_spec.rb
238
236
  - spec/lita/authorization_spec.rb
@@ -243,6 +241,7 @@ files:
243
241
  - spec/lita/handlers/web_spec.rb
244
242
  - spec/lita/logger_spec.rb
245
243
  - spec/lita/message_spec.rb
244
+ - spec/lita/response_spec.rb
246
245
  - spec/lita/robot_spec.rb
247
246
  - spec/lita/rspec_spec.rb
248
247
  - spec/lita/source_spec.rb
@@ -250,6 +249,19 @@ files:
250
249
  - spec/lita/util_spec.rb
251
250
  - spec/lita_spec.rb
252
251
  - spec/spec_helper.rb
252
+ - templates/plugin/Gemfile
253
+ - templates/plugin/LICENSE.tt
254
+ - templates/plugin/README.tt
255
+ - templates/plugin/Rakefile
256
+ - templates/plugin/gemspec.tt
257
+ - templates/plugin/gitignore
258
+ - templates/plugin/lib/lita/plugin_type/plugin.tt
259
+ - templates/plugin/lib/plugin.tt
260
+ - templates/plugin/spec/lita/plugin_type/plugin_spec.tt
261
+ - templates/plugin/spec/spec_helper.tt
262
+ - templates/plugin/travis.yml
263
+ - templates/robot/Gemfile
264
+ - templates/robot/lita_config.rb
253
265
  homepage: https://github.com/jimmycuadra/lita
254
266
  licenses:
255
267
  - MIT
@@ -285,6 +297,7 @@ test_files:
285
297
  - spec/lita/handlers/web_spec.rb
286
298
  - spec/lita/logger_spec.rb
287
299
  - spec/lita/message_spec.rb
300
+ - spec/lita/response_spec.rb
288
301
  - spec/lita/robot_spec.rb
289
302
  - spec/lita/rspec_spec.rb
290
303
  - spec/lita/source_spec.rb