Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
267 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,116 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.3.6) | ||
bcrypt-ruby (3.1.2) | ||
coderay (1.1.0) | ||
daemons (1.1.9) | ||
data_mapper (1.2.0) | ||
dm-aggregates (~> 1.2.0) | ||
dm-constraints (~> 1.2.0) | ||
dm-core (~> 1.2.0) | ||
dm-migrations (~> 1.2.0) | ||
dm-serializer (~> 1.2.0) | ||
dm-timestamps (~> 1.2.0) | ||
dm-transactions (~> 1.2.0) | ||
dm-types (~> 1.2.0) | ||
dm-validations (~> 1.2.0) | ||
data_objects (0.10.13) | ||
addressable (~> 2.1) | ||
diff-lcs (1.2.5) | ||
dm-aggregates (1.2.0) | ||
dm-core (~> 1.2.0) | ||
dm-constraints (1.2.0) | ||
dm-core (~> 1.2.0) | ||
dm-core (1.2.1) | ||
addressable (~> 2.3) | ||
dm-do-adapter (1.2.0) | ||
data_objects (~> 0.10.6) | ||
dm-core (~> 1.2.0) | ||
dm-migrations (1.2.0) | ||
dm-core (~> 1.2.0) | ||
dm-postgres-adapter (1.2.0) | ||
dm-do-adapter (~> 1.2.0) | ||
do_postgres (~> 0.10.6) | ||
dm-serializer (1.2.2) | ||
dm-core (~> 1.2.0) | ||
fastercsv (~> 1.5) | ||
json (~> 1.6) | ||
json_pure (~> 1.6) | ||
multi_json (~> 1.0) | ||
dm-sqlite-adapter (1.2.0) | ||
dm-do-adapter (~> 1.2.0) | ||
do_sqlite3 (~> 0.10.6) | ||
dm-timestamps (1.2.0) | ||
dm-core (~> 1.2.0) | ||
dm-transactions (1.2.0) | ||
dm-core (~> 1.2.0) | ||
dm-types (1.2.2) | ||
bcrypt-ruby (~> 3.0) | ||
dm-core (~> 1.2.0) | ||
fastercsv (~> 1.5) | ||
json (~> 1.6) | ||
multi_json (~> 1.0) | ||
stringex (~> 1.4) | ||
uuidtools (~> 2.1) | ||
dm-validations (1.2.0) | ||
dm-core (~> 1.2.0) | ||
do_postgres (0.10.13) | ||
data_objects (= 0.10.13) | ||
do_sqlite3 (0.10.13) | ||
data_objects (= 0.10.13) | ||
dotenv (2.0.1) | ||
eventmachine (1.0.4) | ||
faraday (0.9.1) | ||
multipart-post (>= 1.2, < 3) | ||
fastercsv (1.5.5) | ||
json (1.8.2) | ||
json_pure (1.8.1) | ||
method_source (0.8.2) | ||
multi_json (1.11.0) | ||
multipart-post (2.0.0) | ||
pry (0.10.1) | ||
coderay (~> 1.1.0) | ||
method_source (~> 0.8.1) | ||
slop (~> 3.4) | ||
pry-nav (0.2.4) | ||
pry (>= 0.9.10, < 0.11.0) | ||
rack (1.6.1) | ||
rack-test (0.6.3) | ||
rack (>= 1.0) | ||
rake (10.4.2) | ||
rspec (2.14.1) | ||
rspec-core (~> 2.14.0) | ||
rspec-expectations (~> 2.14.0) | ||
rspec-mocks (~> 2.14.0) | ||
rspec-core (2.14.8) | ||
rspec-expectations (2.14.5) | ||
diff-lcs (>= 1.1.3, < 2.0) | ||
rspec-mocks (2.14.6) | ||
slack-notify (0.4.1) | ||
faraday (~> 0.9) | ||
json (~> 1.8) | ||
slop (3.6.0) | ||
stringex (1.5.1) | ||
thin (1.6.3) | ||
daemons (~> 1.0, >= 1.0.9) | ||
eventmachine (~> 1.0) | ||
rack (~> 1.0) | ||
uuidtools (2.1.4) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
data_mapper | ||
dm-postgres-adapter | ||
dm-sqlite-adapter | ||
dotenv | ||
pry | ||
pry-nav | ||
rack | ||
rack-test (~> 0.6.2) | ||
rake | ||
rspec (~> 2.14.1) | ||
slack-notify | ||
thin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'data_mapper' | ||
require 'dm-migrations' | ||
|
||
class Commit | ||
include DataMapper::Resource | ||
|
||
property :id , Serial | ||
property :sha , String | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'bundler' | ||
Bundler.setup | ||
|
||
APP_ROOT = File.expand_path("../", File.dirname(File.join(__FILE__))) | ||
RACK_ENV = ENV['RACK_ENV'] || "development"; | ||
|
||
$LOAD_PATH.unshift(APP_ROOT) | ||
|
||
require 'data_mapper' | ||
DataMapper.setup(:default, ENV["DATABASE_URL"] || "sqlite3://#{APP_ROOT}/db/#{RACK_ENV}.db") | ||
|
||
require 'commits' | ||
DataMapper.finalize | ||
|
||
case RACK_ENV | ||
when "development", "production" | ||
# We run the migrations if not runned | ||
City.auto_upgrade! | ||
when "test" | ||
# We recreate the database with the schema from scratch | ||
City.auto_migrate! | ||
else | ||
raise "Invalid RACK_ENV #{RACK_ENV}" | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'bundler' | ||
Bundler.setup | ||
require 'logger' | ||
|
||
APP_ROOT = File.expand_path(File.dirname(File.join(__FILE__))) | ||
RACK_ENV = ENV['RACK_ENV'] || "development"; | ||
|
||
LOGGER = Logger.new(STDOUT) | ||
|
||
$LOAD_PATH.unshift(APP_ROOT) | ||
|
||
require 'dotenv' | ||
Dotenv.load( | ||
File.expand_path(".#{RACK_ENV}.env"), | ||
File.expand_path(".env") ) | ||
|
||
require 'data_mapper' | ||
DataMapper.setup(:default, ENV["DATABASE_URL"] || "sqlite3://#{APP_ROOT}/db/#{RACK_ENV}.db") | ||
|
||
require 'commit' | ||
DataMapper.finalize | ||
|
||
case RACK_ENV | ||
when "development", "production" | ||
# We run the migrations if not runned | ||
Commit.auto_upgrade! | ||
when "test" | ||
# We recreate the database with the schema from scratch | ||
Commit.auto_migrate! | ||
else | ||
raise "Invalid RACK_ENV #{RACK_ENV}" | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'yaml' | ||
require 'slack-notify' | ||
|
||
class HerokuSlack | ||
def initialize | ||
LOGGER.info("INIT") | ||
@client = SlackNotify::Client.new( | ||
webhook_url: ENV['SLACK_WEBHOOK_URL'], | ||
channel: "#autonotifications", | ||
username: "martinosis", | ||
icon_emoji: ":shipit:", | ||
link_names: 1 | ||
) | ||
@gh_user = "martinos" | ||
@gh_project = "heroku_slack_integration" | ||
end | ||
|
||
def call(env) | ||
req = Rack::Request.new(env) | ||
params = req.params | ||
notify_slack(params) | ||
['200', {'Content-Type' => 'text/plain'}, [req.to_yaml + "\n" + params.to_yaml]] | ||
end | ||
|
||
def html_diffs(new_sha) | ||
"https://github.com/#{@gh_user}/#{@gh_project}/compare/#{prev_sha}...#{new_sha}" | ||
end | ||
|
||
def store_sha(sha) | ||
Commit.create(sha: sha) | ||
end | ||
|
||
def prev_sha | ||
last = Commit.last | ||
LOGGER.info "\033[31mLastcommit#{last.inspect}\033[0m" | ||
last && last.sha | ||
end | ||
|
||
def log(env) | ||
req = Rack::Request.new(env) | ||
params = req.params | ||
LOGGER.info("Params: #{params.to_yaml}") | ||
LOGGER.info("ENV: #{env.to_yaml}") | ||
end | ||
|
||
def notify_slack(params) | ||
if sha = params["sha"] | ||
if prev_sha | ||
params["diff"] = html_diffs(sha) | ||
end | ||
store_sha(sha) | ||
end | ||
@client.notify(params.to_yaml) | ||
end | ||
end | ||
|