rack-error_to_slack 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c05f43afdc31e42d6acb7fd9d5225525b530fe07
4
+ data.tar.gz: 41ca890f677ab6b2ae6ce9169653f121a41c62e9
5
+ SHA512:
6
+ metadata.gz: 03a3b38eda04fe4b01b8d43d63e54860f67e78ebb813018e0e9321f22d3e9e6cf7b206b5b3966501d7de7d5b4ef3d8bfa3836c201a9e84cec7e127adb92f4134
7
+ data.tar.gz: 4f1154deaf0908d48445ef38e9538e2a144e606118eb22b2679569853678811a4cac35748b9660e85ccd601c3c7ab0248c8dcdebc7c9e2db1a8a67a2ef93146c
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /rdoc/
21
+
22
+ ## Environment normalisation:
23
+ /.bundle/
24
+ /vendor/bundle
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-error_to_slack.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 ITO Shogo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Rack::ErrorToSlack
2
+ This is a rack middleware that post error to slack.
3
+ EXAMPLE: ![](https://github.com/showwin/rack-error_to_slack/blob/master/doc/sample.png)
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'rack-error_to_slack'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install rack-error_to_slack
21
+
22
+ ## Usage
23
+ ### for Rails 4.x
24
+ #### Step1
25
+ `config/environments/development.rb`
26
+ ```
27
+ config.middleware.use Rack::ErrorToSlack
28
+ ```
29
+
30
+ #### Step2
31
+ `config/initializers/error_to_slack.rb`
32
+ ```
33
+ Rack::ErrorToSlack.configure do |config|
34
+ config.webhook_url = 'https://hooks.slack.com/services/your_webhook_url'
35
+ ### follows are option ###
36
+ # emoji icon of slack post
37
+ config.emoji = ':ghost:' # default: ':innocent:'
38
+ # username of slack post
39
+ config.slackname = 'ErrorSharing' # default: 'ErrorToSlack'
40
+ end
41
+ ```
42
+
43
+ ## LICENSE
44
+ [MIT](https://github.com/showwin/rack-error_to_slack/blob/master/LICENSE)
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rack/error_to_slack"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/doc/sample.png ADDED
Binary file
@@ -0,0 +1,32 @@
1
+ require 'rack/error_to_slack/version'
2
+ require 'rack/error_to_slack/configuration'
3
+ require 'rack/error_to_slack/message'
4
+
5
+ module Rack
6
+ # ErrorToSlack Class
7
+ class ErrorToSlack
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ begin
14
+ response = @app.call(env)
15
+ rescue Exception => exception
16
+ Message.new(env, exception.message).send
17
+ raise exception
18
+ end
19
+ response
20
+ end
21
+
22
+ class << self
23
+ def configure
24
+ yield(configuration)
25
+ end
26
+
27
+ def configuration
28
+ @configuration ||= Configuration.new
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ module Rack
2
+ class ErrorToSlack
3
+ # Configuration Class
4
+ class Configuration
5
+ attr_accessor :webhook_url
6
+ attr_accessor :emoji
7
+ attr_accessor :slackname
8
+ attr_reader :branch
9
+ attr_reader :username
10
+
11
+ def initialize
12
+ @webhook_url = nil
13
+ @emoji = ':innocent:'
14
+ @slackname = 'ErrorToSlack'
15
+ @branch = `git rev-parse --abbrev-ref HEAD`.chomp || 'SOME BRANCH'
16
+ @username = `whoami`.chomp || 'Anonymous'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,44 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module Rack
6
+ class ErrorToSlack
7
+ # Message Class
8
+ class Message
9
+ def initialize(env, err_msg)
10
+ @data = {
11
+ 'text': "#{username} encountered an error while " \
12
+ "`#{env['REQUEST_METHOD']} #{env['PATH_INFO']}` " \
13
+ "on branch `#{branch}`\n" \
14
+ "```#{err_msg}```",
15
+ 'username': slackname,
16
+ 'icon_emoji': emoji
17
+ }
18
+ end
19
+
20
+ def send
21
+ request_url = ErrorToSlack.configuration.webhook_url
22
+ Net::HTTP.post_form(URI.parse(request_url), 'payload' => @data.to_json)
23
+ end
24
+
25
+ private
26
+
27
+ def username
28
+ ErrorToSlack.configuration.username
29
+ end
30
+
31
+ def branch
32
+ ErrorToSlack.configuration.branch
33
+ end
34
+
35
+ def slackname
36
+ ErrorToSlack.configuration.slackname
37
+ end
38
+
39
+ def emoji
40
+ ErrorToSlack.configuration.emoji
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class ErrorToSlack
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/error_to_slack/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rack-error_to_slack'
8
+ spec.version = Rack::ErrorToSlack::VERSION
9
+ spec.authors = ['showwin']
10
+ spec.email = ['showwin_kmc@yahoo.co.jp']
11
+
12
+ spec.summary = %q{rack middleware to post error to slack}
13
+ spec.description = %q{this is a rack middleware to post error to slack}
14
+ spec.homepage = 'https://github.com/showwin/rack-error_to_slack'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.10'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'uri'
25
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-error_to_slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - showwin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: uri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: this is a rack middleware to post error to slack
70
+ email:
71
+ - showwin_kmc@yahoo.co.jp
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - doc/sample.png
86
+ - lib/rack/error_to_slack.rb
87
+ - lib/rack/error_to_slack/configuration.rb
88
+ - lib/rack/error_to_slack/message.rb
89
+ - lib/rack/error_to_slack/version.rb
90
+ - rack-error_to_slack.gemspec
91
+ homepage: https://github.com/showwin/rack-error_to_slack
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: rack middleware to post error to slack
114
+ test_files: []
115
+ has_rdoc: