Commit 715c3e31 authored by jz143's avatar jz143

send slack notifications

parent 6d942036
...@@ -85,3 +85,6 @@ gem 'resque', '~> 1.26.0' ...@@ -85,3 +85,6 @@ gem 'resque', '~> 1.26.0'
gem 'god', '~> 0.13.7' gem 'god', '~> 0.13.7'
gem 'bootstrap-sass', '~> 3.3.5' gem 'bootstrap-sass', '~> 3.3.5'
# post to Slack
gem 'slack-notifier', '~> 1.5.1'
...@@ -216,6 +216,7 @@ GEM ...@@ -216,6 +216,7 @@ GEM
rack (~> 1.5) rack (~> 1.5)
rack-protection (~> 1.4) rack-protection (~> 1.4)
tilt (>= 1.3, < 3) tilt (>= 1.3, < 3)
slack-notifier (1.5.1)
spring (1.3.6) spring (1.3.6)
sprockets (3.3.3) sprockets (3.3.3)
rack (~> 1.0) rack (~> 1.0)
...@@ -279,6 +280,7 @@ DEPENDENCIES ...@@ -279,6 +280,7 @@ DEPENDENCIES
sass-rails (~> 5.0) sass-rails (~> 5.0)
sdoc (~> 0.4.0) sdoc (~> 0.4.0)
simple_form simple_form
slack-notifier (~> 1.5.1)
spring spring
sqlite3 sqlite3
therubyracer therubyracer
......
...@@ -79,6 +79,9 @@ class AppFilesController < ApplicationController ...@@ -79,6 +79,9 @@ class AppFilesController < ApplicationController
if @app_file.save if @app_file.save
format.html { redirect_to @app_file.app, notice: 'App file has been uploaded.' } format.html { redirect_to @app_file.app, notice: 'App file has been uploaded.' }
format.json { render :show, status: :created, location: @app_file } format.json { render :show, status: :created, location: @app_file }
SendSlackUpdateJob.perform_later "[!!] %s uploaded [%s](%s) (ver. %s for %s) <!channel>" \
% [if current_user.nil? then 'Guest' else current_user.display_name end, @app_file.app.name, app_url(@app_file.app), @app_file.version, @app_file.platform].map { |s| SlackNotifier.escape(s.to_s) }
else else
format.html { render :new } format.html { render :new }
format.json { render json: @app_file.errors, status: :unprocessable_entity } format.json { render json: @app_file.errors, status: :unprocessable_entity }
...@@ -123,6 +126,9 @@ class AppFilesController < ApplicationController ...@@ -123,6 +126,9 @@ class AppFilesController < ApplicationController
end end
@app_file.increment!(:download_count) @app_file.increment!(:download_count)
SendSlackUpdateJob.perform_later "%s downloaded [%s](%s) (ver. %s for %s)" \
% [if current_user.nil? then 'Guest' else current_user.display_name end, @app_file.app.name, app_url(@app_file.app), @app_file.version, @app_file.platform].map { |s| SlackNotifier.escape(s.to_s) }
end end
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
......
...@@ -43,6 +43,9 @@ class AppsController < ApplicationController ...@@ -43,6 +43,9 @@ class AppsController < ApplicationController
if @app.save if @app.save
format.html { redirect_to @app, notice: 'App was successfully created.' } format.html { redirect_to @app, notice: 'App was successfully created.' }
format.json { render :show, status: :created, location: @app } format.json { render :show, status: :created, location: @app }
SendSlackUpdateJob.perform_later "[!!!] %s created a new app [%s](%s) <!channel>" \
% [if current_user.nil? then 'Guest' else current_user.display_name end, @app.name, app_url(@app)].map { |s| SlackNotifier.escape(s.to_s) }
else else
format.html { render :new } format.html { render :new }
format.json { render json: @app.errors, status: :unprocessable_entity } format.json { render json: @app.errors, status: :unprocessable_entity }
...@@ -58,6 +61,9 @@ class AppsController < ApplicationController ...@@ -58,6 +61,9 @@ class AppsController < ApplicationController
if @app.update(app_params) if @app.update(app_params)
format.html { redirect_to @app, notice: 'App was successfully updated.' } format.html { redirect_to @app, notice: 'App was successfully updated.' }
format.json { render :show, status: :ok, location: @app } format.json { render :show, status: :ok, location: @app }
SendSlackUpdateJob.perform_later "[!!!] %s updated information of app [%s](%s) <!channel>" \
% [if current_user.nil? then 'Guest' else current_user.display_name end, @app.name, app_url(@app)].map { |s| SlackNotifier.escape(s.to_s) }
else else
format.html { render :edit } format.html { render :edit }
format.json { render json: @app.errors, status: :unprocessable_entity } format.json { render json: @app.errors, status: :unprocessable_entity }
......
class SendSlackUpdateJob < ActiveJob::Base
queue_as :web_background
def perform(message, attachments)
SlackNotifier.ping message, attachments: attachments
end
end
::SlackNotifier = Slack::Notifier.new Settings.slack.webhook_url
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment