Created
March 1, 2012 03:29
-
-
Save masterkain/1947035 to your computer and use it in GitHub Desktop.
Sidekiq GitHub issue reporter
This file contains hidden or 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
gem 'sidekiq' | |
gem 'octokit' |
This file contains hidden or 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
require 'octokit' | |
class GithubNotifier | |
def initialize(login, password, repository, options={}) | |
@repository = repository | |
@options = options | |
@client = ::Octokit::Client.new(login: login, password: password) | |
end | |
def call(*args) | |
yield | |
rescue => ex | |
send_to_github(args[1], ex, @repository, @options) | |
raise | |
end | |
private | |
def send_to_github(msg, ex, repo, opts) | |
backtrace = (ex.backtrace ? clean_backtrace(ex) : []).join("\n") | |
message = "#{ex.class}: #{ex.message}" | |
@client.create_issue(repo, "[#{Rails.env.to_s}] #{message}", "Revision: #{REVISION}\n\n**Data**\n\n```#{msg}```\n\n**Exception**\n\n```#{message}```\n\n**Backtrace**\n\n```\n#{backtrace}```", opts) | |
rescue => ex | |
puts "Cannot send the exception to GitHub. #{ex.class}:#{ex.message}" | |
end | |
def clean_backtrace(exception) | |
if Rails.respond_to?(:backtrace_cleaner) | |
Rails.backtrace_cleaner.send(:filter, exception.backtrace) | |
else | |
exception.backtrace | |
end | |
end | |
end | |
Sidekiq.configure_server do |config| | |
config.redis = Sidekiq::RedisConnection.create(namespace: Settings.app.redis.namespace, size: 25, url: Settings.app.redis.uri) | |
config.server_middleware do |chain| | |
chain.add GithubNotifier, Settings.services.github.login, Settings.services.github.password, 'my/repo', { assignee: 'my_github_handle', labels: ['Ruby on Rails'] } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very cool!