Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yeah committed Oct 3, 2008
0 parents commit 89c9cb0
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
= hoptoad_server

This is a simple Redmine plugin that makes Redmine act like a Hoptoad server. All exceptions caught and sent by HoptoadNotifier will create or update an Issue in Redmine.

= Installation & Configuration

Just install the Plugin following the general Redmine plugin installation instructions at http://www.redmine.org/wiki/redmine/Plugins.

Then, go to Administration -> Settings -> Incoming emails in your Redmine and generate an API key.

Now, download and install the HoptoadNotifier following the excellent instructions on their github page http://github.com/thoughtbot/hoptoad_notifier.

When it comes to creating your config/initializers/hoptoad.rb file, deviate from the standard and put in something like this:

HoptoadNotifier.configure do |config|
config.api_key = {:project => 'my_redmine_project_identifier', # the one you specified for your project in Redmine
:tracker => 'Bug', # the name of your Tracker of choice in Redmine
:api_key => 'my_redmine_api_key', # the key you generated before in Redmine (NOT YOUR HOPTOAD API KEY!)
:category => 'Development', # the name of a ticket category (optional.)
:assigned_to => 'admin', # the login of a user the ticket should get assigned to by default (optional.)
:priority => 5 # the default priority (use a number, not a name. optional.)
}.to_yaml
config.host = 'my_redmine_host.com' # the hostname your Redmine runs at
config.port = 443 # the port your Redmine runs at
end

You're done. You can start receiving your Exceptions in Redmine!
51 changes: 51 additions & 0 deletions app/controllers/notices_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class NoticesController < ApplicationController
unloadable
def index
notice = YAML.load(request.raw_post)['notice']
redmine_params = YAML.load(notice['api_key'])

if authorized = Setting.mail_handler_api_key == redmine_params[:api_key]

project = Project.find_by_name(redmine_params[:project])
tracker = project.trackers.find_by_name(redmine_params[:tracker])
author = User.anonymous

issue = Issue.find_or_initialize_by_subject_and_project_id_and_tracker_id_and_author_id_and_description(notice['error_message'],
project.id,
tracker.id,
author.id,
'Hoptoad Issue')

if issue.new_record?
issue.category = IssueCategory.find_by_name(redmine_params[:category]) unless redmine_params[:category].blank?
issue.assigned_to = User.find_by_login(redmine_params[:assigned_to]) unless redmine_params[:assigned_to].blank?
issue.priority_id = redmine_params[:priority] unless redmine_params[:priority].blank?
end

issue.save!

journal = issue.init_journal(author, "h4. Backtrace\n\n<pre>#{notice['back'].to_yaml}</pre>\n\n
h4. Request\n\n<pre>#{notice['request'].to_yaml}</pre>\n\n
h4. Session\n\n<pre>#{notice['session'].to_yaml}</pre>\n\n
h4. Environment\n\n<pre>#{notice['environment'].to_yaml}</pre>")

if issue.status.blank? or issue.status.is_closed?
issue.status = IssueStatus.find(:first, :conditions => {:is_default => true}, :order => 'position ASC')
end


issue.save!

if issue.new_record?
Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added')
else
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
end

render :status => 200, :text => "Received bug report. Created/updated issue #{issue.id}."
else
logger.info 'Unauthorized Hoptoad API request.'
render :status => 403, :text => 'You provided a wrong or no Redmine API key.'
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/notices_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module NoticesHelper
end
8 changes: 8 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'redmine'

Redmine::Plugin.register :redmine_hoptoad_server do
name 'Redmine Hoptoad Server plugin'
author 'Jan Schulz-Hofen'
description 'This plugin turns Redmin into a Hoptoad server, i.e. an API provider which can be used with the hoptoad_notifier which is available at: http://www.hoptoadapp.com/'
version '0.0.1'
end
2 changes: 2 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# English strings go here
my_label: "My label"
8 changes: 8 additions & 0 deletions test/functional/notices_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require File.dirname(__FILE__) + '/../test_helper'

class NoticesControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Load the normal Rails helper
require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')

# Ensure that we are using the temporary fixture path
Engines::Testing.set_fixture_path

0 comments on commit 89c9cb0

Please sign in to comment.