Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit abbd54f

Browse files
committed
Add chat and HTTP routes to handler
1 parent 9d2727a commit abbd54f

File tree

4 files changed

+125
-19
lines changed

4 files changed

+125
-19
lines changed

lib/lita/handlers/janky.rb

+63
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,69 @@
11
module Lita
22
module Handlers
33
class Janky < Handler
4+
5+
route(/ci\??$/i, :help, command: true, help: {
6+
'ci' => 'shows the help'
7+
})
8+
9+
route(/ci build ([-_\.0-9a-zA-Z]+)(\/([-_\+\.a-zA-z0-9\/]+))?/i, :build, command: true, help: {
10+
'ci build REPO' => 'builds master branch for a given repo',
11+
'ci build REPO/BRANCH' => 'builds given branch for a given repo',
12+
'ci build REPO/SHA' => 'builds given SHA for a given repo'
13+
})
14+
15+
route(/ci setup ([\.\-\/_a-z0-9]+)(\s([\.\-_a-z0-9]+)(\s([\.\-_a-z0-9]+))?)?/i, :setup, command: true, help: {
16+
'ci setup USER/REPO' => 'sets up a Jenkins job and webhook for a repository',
17+
'ci setup USER/REPO NAME' => 'sets up a Jenkins job and webhook for a repository with given name',
18+
'ci setup USER/REPO NAME TEMPLATE' => 'sets up a Jenkins job and webhook for a repository with given name and given template'
19+
})
20+
21+
route(/ci toggle ([-_\.0-9a-zA-Z]+)/i, :toggle, command: true, help: {
22+
'ci toggle REPO' => 'enable/disable automatic builds for a given repo',
23+
})
24+
25+
route(/ci set room ([-_0-9a-zA-Z\.]+) (.*)$/i, :room, command: true, help: {
26+
'ci set room REPO ROOM' => 'sets room where notifications are sent',
27+
})
28+
29+
route(/ci (set) context ([-_0-9a-zA-Z\.]+) (.*)$/i, :context, command: true, help: {
30+
'ci set context REPO CONTEXT' => 'sets context for a given repo'
31+
})
32+
33+
route(/ci (unset) context ([-_0-9a-zA-Z\.]+)$/i, :context, command: true, help: {
34+
'ci unset context REPO' => 'unsets context for a given repo'
35+
})
36+
37+
route(/ci rooms$/i, :rooms, command: true, help: {
38+
'ci rooms' => 'lists available rooms to send notifications'
39+
})
40+
41+
route(/ci builds ([0-9]+) ?(building)?$/i, :builds, command: true, help: {
42+
'ci builds LIMIT' => 'shows last builds',
43+
'ci builds LIMIT building' => 'shows last builds in building status'
44+
})
45+
46+
route(/ci status( (\*\/[-_\+\.a-zA-z0-9\/]+))?$/i, :status, command: true, help: {
47+
'ci status' => 'shows last build status for each repo',
48+
'ci status */REPO' => 'shows last build status for given repo'
49+
})
50+
51+
route(/ci status (-v )?([-_\.0-9a-zA-Z]+)(\/([-_\+\.a-zA-z0-9\/]+))?/i, :repo_status, command: true, help: {
52+
'ci status REPO' => 'shows last build status for a given repo',
53+
'ci status REPO/BRANCH' => 'shows last build status for a given repo and branch',
54+
'ci status REPO/SHA' => 'shows last build status for a given repo and sha',
55+
'ci status -v REPO' => 'shows last five build status for a given repo'
56+
})
57+
58+
route(/ci show ([-_\.0-9a-zA-Z]+)/i, :show, command: true, help: {
59+
'ci show REPO' => 'shows configuration for a configured repo'
60+
})
61+
62+
route(/ci delete ([-_\.0-9a-zA-Z]+)/i, :delete, command: true, help: {
63+
'ci delete REPO' => 'deletes a given repo'
64+
})
65+
66+
http.post '/janky', :post_message
467
end
568

669
Lita.register_handler(Janky)

lita-janky.gemspec

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
Gem::Specification.new do |spec|
2-
spec.name = "lita-janky"
3-
spec.version = "0.0.1"
4-
spec.authors = ["Jose Luis Salas"]
5-
spec.email = ["[email protected]"]
2+
spec.name = 'lita-janky'
3+
spec.version = '0.0.1'
4+
spec.authors = ['Jose Luis Salas']
5+
spec.email = ['[email protected]']
66
spec.description = "Lita handler for GitHub's Janky"
77
spec.summary = "Lita handler for GitHub's Janky"
8-
spec.homepage = "https://github.com/josacar/lita-janky"
9-
spec.license = "MIT"
10-
spec.metadata = { "lita_plugin_type" => "handler" }
8+
spec.homepage = 'https://github.com/josacar/lita-janky'
9+
spec.license = 'MIT'
10+
spec.metadata = { 'lita_plugin_type' => 'handler' }
1111

1212
spec.files = `git ls-files`.split($/)
1313
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
1414
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15-
spec.require_paths = ["lib"]
15+
spec.require_paths = ['lib']
1616

17-
spec.add_runtime_dependency "lita", ">= 4.3"
17+
spec.add_runtime_dependency 'lita', '>= 4.3'
18+
spec.add_runtime_dependency 'faraday', '>= 0.8.7'
1819

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"
20+
spec.add_development_dependency 'bundler', '~> 1.3'
21+
spec.add_development_dependency 'pry-byebug'
22+
spec.add_development_dependency 'rake'
23+
spec.add_development_dependency 'rack-test'
24+
spec.add_development_dependency 'rspec', '>= 3.0.0'
25+
spec.add_development_dependency 'simplecov'
26+
spec.add_development_dependency 'coveralls'
2627
end

spec/lita/handlers/janky_spec.rb

+39
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
11
require "spec_helper"
22

33
describe Lita::Handlers::Janky, lita_handler: true do
4+
it { is_expected.to route_command('Ci').to(:help) }
5+
it { is_expected.to route_command('cI?').to(:help) }
6+
7+
it { is_expected.to route_command('ci build janky').to(:build) }
8+
it { is_expected.to route_command('ci build janky/branch').to(:build) }
9+
it { is_expected.to route_command('ci build janky/a345g7f').to(:build) }
10+
11+
it { is_expected.to route_command('ci setup github/janky').to(:setup) }
12+
it { is_expected.to route_command('ci setup github/janky janky-ruby1.9.2').to(:setup) }
13+
it { is_expected.to route_command('ci setup github/janky janky-ruby1.9.2 ruby-build').to(:setup) }
14+
15+
it { is_expected.to route_command('ci toggle janky').to(:toggle) }
16+
17+
it { is_expected.to route_command('ci set room janky The Serious Room').to(:room) }
18+
it { is_expected.not_to route_command('ci set room janky').to(:room) }
19+
20+
it { is_expected.to route_command('ci set context janky ci/janky').to(:context) }
21+
22+
it { is_expected.to route_command('ci unset context janky').to(:context) }
23+
24+
it { is_expected.to route_command('ci rooms').to(:rooms) }
25+
26+
it { is_expected.to route_command('ci builds 1').to(:builds) }
27+
it { is_expected.to route_command('ci builds 1 building').to(:builds) }
28+
29+
it { is_expected.to route_command('ci status').to(:status) }
30+
it { is_expected.to route_command('ci status */master').to(:status) }
31+
it { is_expected.not_to route_command('ci status janky/master').to(:status) }
32+
33+
it { is_expected.to route_command('ci status janky').to(:repo_status) }
34+
it { is_expected.to route_command('ci status janky/master').to(:repo_status) }
35+
it { is_expected.to route_command('ci status -v janky/master').to(:repo_status) }
36+
it { is_expected.not_to route_command('ci status */master').to(:repo_status) }
37+
38+
it { is_expected.to route_command('ci show janky').to(:show) }
39+
40+
it { is_expected.to route_command('ci delete janky').to(:delete) }
41+
42+
it { is_expected.to route_http(:post, '/janky').to(:post_message) }
443
end

spec/spec_helper.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
SimpleCov::Formatter::HTMLFormatter,
55
Coveralls::SimpleCov::Formatter
66
]
7-
SimpleCov.start { add_filter "/spec/" }
7+
SimpleCov.start do
8+
add_filter '/spec/'
9+
add_filter '/vendor/'
10+
end
811

9-
require "lita-janky"
10-
require "lita/rspec"
12+
require 'lita-janky'
13+
require 'lita/rspec'
1114

1215
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
1316
# was generated with Lita 4, the compatibility mode should be left disabled.

0 commit comments

Comments
 (0)