Skip to content

Instantly share code, notes, and snippets.

@masterkain
Created March 1, 2012 03:29
Show Gist options
  • Save masterkain/1947035 to your computer and use it in GitHub Desktop.
Save masterkain/1947035 to your computer and use it in GitHub Desktop.
Sidekiq GitHub issue reporter
gem 'sidekiq'
gem 'octokit'
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
@ryanlecompte
Copy link

Very cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment