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

Commit 5cd344b

Browse files
committed
Initial import
1 parent a2aee00 commit 5cd344b

File tree

15 files changed

+806
-0
lines changed

15 files changed

+806
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source "https://rubygems.org"
2+
3+
group :development do
4+
gem "guard"
5+
gem "guard-rspec", require: false
6+
end
7+
8+
gemspec

Gemfile.lock

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
PATH
2+
remote: .
3+
specs:
4+
lita-heaven (0.1.0)
5+
lita (>= 4.7)
6+
octokit
7+
8+
GEM
9+
remote: https://rubygems.org/
10+
specs:
11+
addressable (2.5.2)
12+
public_suffix (>= 2.0.2, < 4.0)
13+
byebug (10.0.2)
14+
coderay (1.1.2)
15+
concurrent-ruby (1.0.5)
16+
crack (0.4.3)
17+
safe_yaml (~> 1.0.0)
18+
diff-lcs (1.3)
19+
faraday (0.15.0)
20+
multipart-post (>= 1.2, < 3)
21+
ffi (1.9.23)
22+
formatador (0.2.5)
23+
guard (2.14.2)
24+
formatador (>= 0.2.4)
25+
listen (>= 2.7, < 4.0)
26+
lumberjack (>= 1.0.12, < 2.0)
27+
nenv (~> 0.1)
28+
notiffany (~> 0.0)
29+
pry (>= 0.9.12)
30+
shellany (~> 0.0)
31+
thor (>= 0.18.1)
32+
guard-compat (1.2.1)
33+
guard-rspec (4.7.3)
34+
guard (~> 2.1)
35+
guard-compat (~> 1.1)
36+
rspec (>= 2.99.0, < 4.0)
37+
hashdiff (0.3.7)
38+
http_router (0.11.2)
39+
rack (>= 1.0.0)
40+
url_mount (~> 0.2.1)
41+
i18n (1.0.1)
42+
concurrent-ruby (~> 1.0)
43+
ice_nine (0.11.2)
44+
listen (3.1.5)
45+
rb-fsevent (~> 0.9, >= 0.9.4)
46+
rb-inotify (~> 0.9, >= 0.9.7)
47+
ruby_dep (~> 1.2)
48+
lita (4.7.1)
49+
bundler (>= 1.3)
50+
faraday (>= 0.8.7)
51+
http_router (>= 0.11.2)
52+
i18n (>= 0.6.9)
53+
ice_nine (>= 0.11.0)
54+
multi_json (>= 1.7.7)
55+
puma (>= 2.7.1)
56+
rack (>= 1.5.2, < 2.0.0)
57+
rb-readline (>= 0.5.1)
58+
redis-namespace (>= 1.3.0)
59+
thor (>= 0.18.1)
60+
lumberjack (1.0.13)
61+
method_source (0.9.0)
62+
multi_json (1.13.1)
63+
multipart-post (2.0.0)
64+
nenv (0.3.0)
65+
notiffany (0.1.1)
66+
nenv (~> 0.1)
67+
shellany (~> 0.0)
68+
octokit (4.8.0)
69+
sawyer (~> 0.8.0, >= 0.5.3)
70+
pry (0.11.3)
71+
coderay (~> 1.1.0)
72+
method_source (~> 0.9.0)
73+
pry-byebug (3.6.0)
74+
byebug (~> 10.0)
75+
pry (~> 0.10)
76+
public_suffix (3.0.2)
77+
puma (3.11.4)
78+
rack (1.6.10)
79+
rack-test (1.0.0)
80+
rack (>= 1.0, < 3)
81+
rake (12.3.1)
82+
rb-fsevent (0.10.3)
83+
rb-inotify (0.9.10)
84+
ffi (>= 0.5.0, < 2)
85+
rb-readline (0.5.5)
86+
redis (4.0.1)
87+
redis-namespace (1.6.0)
88+
redis (>= 3.0.4)
89+
rspec (3.7.0)
90+
rspec-core (~> 3.7.0)
91+
rspec-expectations (~> 3.7.0)
92+
rspec-mocks (~> 3.7.0)
93+
rspec-core (3.7.1)
94+
rspec-support (~> 3.7.0)
95+
rspec-expectations (3.7.0)
96+
diff-lcs (>= 1.2.0, < 2.0)
97+
rspec-support (~> 3.7.0)
98+
rspec-mocks (3.7.0)
99+
diff-lcs (>= 1.2.0, < 2.0)
100+
rspec-support (~> 3.7.0)
101+
rspec-support (3.7.1)
102+
ruby_dep (1.5.0)
103+
safe_yaml (1.0.4)
104+
sawyer (0.8.1)
105+
addressable (>= 2.3.5, < 2.6)
106+
faraday (~> 0.8, < 1.0)
107+
shellany (0.0.1)
108+
thor (0.20.0)
109+
url_mount (0.2.1)
110+
rack
111+
webmock (3.3.0)
112+
addressable (>= 2.3.6)
113+
crack (>= 0.3.2)
114+
hashdiff
115+
116+
PLATFORMS
117+
ruby
118+
119+
DEPENDENCIES
120+
bundler (~> 1.3)
121+
guard
122+
guard-rspec
123+
lita-heaven!
124+
pry-byebug
125+
rack-test
126+
rake
127+
rspec (>= 3.0.0)
128+
webmock
129+
130+
BUNDLED WITH
131+
1.16.1

Guardfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
guard :rspec, cmd: "bundle exec rspec" do
2+
require "guard/rspec/dsl"
3+
dsl = Guard::RSpec::Dsl.new(self)
4+
5+
# RSpec files
6+
rspec = dsl.rspec
7+
watch(rspec.spec_helper) { rspec.spec_dir }
8+
watch(rspec.spec_support) { rspec.spec_dir }
9+
watch(rspec.spec_files)
10+
11+
# Ruby files
12+
ruby = dsl.ruby
13+
dsl.watch_spec_files_for(ruby.lib_files)
14+
15+
end

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# lita-heaven
2+
3+
[![Build Status](https://travis-ci.org/rsanheim/lita-heaven.png?branch=master)](https://travis-ci.org/rsanheim/lita-heaven)
4+
5+
TODO: Add a description of the plugin.
6+
7+
## Installation
8+
9+
Add lita-heaven to your Lita instance's Gemfile:
10+
11+
``` ruby
12+
gem "lita-heaven"
13+
```
14+
15+
## Configuration
16+
17+
TODO: Describe any configuration attributes the plugin exposes.
18+
19+
## Usage
20+
21+
TODO: Describe the plugin's features and how to use them.

Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/lita-heaven.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/heaven"
8+
9+
Lita::Handlers::Heaven.template_root File.expand_path(
10+
File.join("..", "..", "templates"),
11+
__FILE__
12+
)

lib/lita/deploy_request.rb

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
module Lita
2+
class DeployRequest
3+
attr_reader :config
4+
attr_reader :ref
5+
attr_reader :task
6+
attr_reader :user
7+
8+
DEFAULT_REF = "master"
9+
DEFAULT_ENV = "production"
10+
DEFAULT_AUTOMERGE = true
11+
12+
class NullUser
13+
def mention_name
14+
"unknown"
15+
end
16+
end
17+
18+
VALID_SLUG = "([-_\.0-9a-z]+)"
19+
20+
def self.pattern_parts
21+
[
22+
"(deploy|lock|unlock)", # / prefix
23+
"(!)?\s+", # Whether or not it was a forced deployment
24+
VALID_SLUG, # application name
25+
"(?:\/([^\s]+))?", # ref to deploy
26+
"(?:\s+(?:to|in|on)\s+", # to | in | on
27+
VALID_SLUG, # Environment to release to
28+
")"
29+
]
30+
end
31+
32+
def initialize(message:, config:, user: NullUser.new, room: nil)
33+
@message = message
34+
@config = config
35+
@user = user
36+
@room = room
37+
38+
matches = self.class.text_to_deployment_args(@message)
39+
40+
@command = matches[:command]
41+
@app = matches[:app]
42+
@ref = matches[:ref]
43+
@env = matches[:environment]
44+
@forced = matches[:forced]
45+
46+
@ref ||= config.fetch(:default_ref, DEFAULT_REF)
47+
@env ||= config.fetch(:default_env, DEFAULT_ENV)
48+
@auto_merge_on_standard_deploys = config.fetch(:auto_merge_on_standard_deploys, DEFAULT_AUTOMERGE)
49+
end
50+
51+
def self.text_to_deployment_args(text)
52+
deploy_pattern = Regexp.new(pattern_parts.join(""))
53+
matches = deploy_pattern.match(text)
54+
return {} unless matches
55+
{
56+
command: matches[1],
57+
forced: matches[2] == "!",
58+
app: matches[3],
59+
ref: matches[4] || DEFAULT_REF,
60+
environment: matches[5],
61+
}
62+
end
63+
64+
def auto_merge
65+
if forced?
66+
false
67+
else
68+
@auto_merge_on_standard_deploys
69+
end
70+
end
71+
72+
def forced?
73+
@forced
74+
end
75+
76+
def reply
77+
case
78+
when ["lock", "unlock"].include?(@command)
79+
"#{user.mention_name} is #{@command}ing #{repo} in #{env}"
80+
when @command == "deploy" && forced?
81+
"#{user.mention_name} is force #{@command}ing #{repo}/#{ref} to #{env}"
82+
when @command == "deploy"
83+
"#{user.mention_name} is #{@command}ing #{repo}/#{ref} to #{env}"
84+
else
85+
Lita.logger.error("event=unknown_reply message=#{@message}")
86+
end
87+
end
88+
89+
def env
90+
case @env
91+
when "stg"
92+
"staging"
93+
when "prod", "prd"
94+
"production"
95+
else
96+
@env
97+
end
98+
end
99+
100+
def task
101+
case @command
102+
when "lock", "unlock"
103+
"deploy:#{@command}"
104+
else
105+
@command
106+
end
107+
end
108+
109+
def repo
110+
config.fetch(:repo)
111+
end
112+
113+
def payload
114+
app_payload = config.fetch(:payload, {}).dup
115+
payload = merge_payload_defaults(app_payload)
116+
end
117+
118+
private
119+
120+
# Merge defaults that Heaven expects for things like chat notifications,
121+
# so it can show the actual user who is rseponsible for the deploy.
122+
def merge_payload_defaults(hsh)
123+
hsh[:actor] = @user.mention_name
124+
notify_data = {}
125+
notify_data.merge!(user: @user.mention_name) unless NullUser === @user
126+
notify_data.merge!(room: @room.name) if @room
127+
hsh[:notify] = notify_data
128+
hsh
129+
end
130+
131+
end
132+
end

0 commit comments

Comments
 (0)