From ba1ab6a45006ab039b35d5c2224947cca93a0ba7 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 17 Feb 2012 12:20:45 -0500 Subject: [PATCH] Initial Commit: --- README.rdoc | 3 + .../exceptionhandler_controller.rb | 54 ++++++++++ app/helpers/exceptionhandler_helper.rb | 98 +++++++++++++++++++ app/views/exceptionhandler/index.html.erb | 2 + config/locales/en.yml | 3 + init.rb | 10 ++ lang/en.yml | 2 + .../exceptionhandler_controller_test.rb | 8 ++ test/test_helper.rb | 5 + 9 files changed, 185 insertions(+) create mode 100644 README.rdoc create mode 100644 app/controllers/exceptionhandler_controller.rb create mode 100644 app/helpers/exceptionhandler_helper.rb create mode 100644 app/views/exceptionhandler/index.html.erb create mode 100644 config/locales/en.yml create mode 100644 init.rb create mode 100644 lang/en.yml create mode 100644 test/functional/exceptionhandler_controller_test.rb create mode 100644 test/test_helper.rb diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..fe92931 --- /dev/null +++ b/README.rdoc @@ -0,0 +1,3 @@ += exception_handler + +Description goes here diff --git a/app/controllers/exceptionhandler_controller.rb b/app/controllers/exceptionhandler_controller.rb new file mode 100644 index 0000000..7232215 --- /dev/null +++ b/app/controllers/exceptionhandler_controller.rb @@ -0,0 +1,54 @@ +# exceptionhandler_controller.rb +# @date Feb. 15, 2012 +# @author ricky barrette +# @author twenty codes +# +# Copyright 2012 Rick Barrette +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This controller class will handler incomming http requests containing new exception reports. +# When a new exception report is recieved, it will be compared to existing bug issues. +# If there is a match, the existing issue will be updated +# if not a new bug issue will be generated. +class ExceptionhandlerController < ApplicationController + unloadable + + helper :exceptionhandler + include ExceptionhandlerHelper + + def index +# @bug_id = Tracker.find_by_name("Bug").id +# @issues = Project.find_by_name(params[:app]).issues +# @custom_fields = CustomField + + if params.size < 8 + @output = " not enough args " + else + issue_id = check_for_existing_report + if issue_id > 0 + # TODO update report + @output = issue_id + else + if file_new_report + @output = "new report filed" + else + @output = "Failed to file report" + end + end + end + rescue RuntimeError + @output = "ERROR" + end + +end #EOF diff --git a/app/helpers/exceptionhandler_helper.rb b/app/helpers/exceptionhandler_helper.rb new file mode 100644 index 0000000..30c1d19 --- /dev/null +++ b/app/helpers/exceptionhandler_helper.rb @@ -0,0 +1,98 @@ +# exceptionhandler_helper.rb +# @date Feb. 15, 2012 +# @author ricky barrette +# @authro twenty codes +# +# Copyright 2012 Rick Barrette +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module ExceptionhandlerHelper + + # Checks the database for exisiting reports + # @return id report is existing else 0 + def check_for_existing_report + bug_id = Tracker.find_by_name("Bug").id + issues = Project.find_by_name(params[:app]).issues + issues.each do |issue| + if issue.tracker_id == bug_id + id = check_issue(issue) + if id > 0 + return id + end + end + end + return 0; + end + + # checks a specific issue agains params + # @return id of report if matching, else 0 + def check_issue(issue) + if issue.subject == params[:msg] +# if issue.description == params[:description] + if check_issue_custom_values(issue) + return issue.id + end +# else +# return 0 +# end + else + return 0 + end + end + + #checks if this issue is a match for params based on it's custom values' + # @return true if matching + def check_issue_custom_values (issue) + count = 0 + custom_fields = CustomField + issue.custom_field_values.each do |value| + case custom_fields.find_by_id(value.custom_field_id).name + when "Version" + if value.value == params[:version] + count += 1 + end + when "StackTrace" + if value.value == params[:stackTrace] + count += 1 + end + when "Cause" + if value.value == params[:cause] + count += 1 + end + end + end + if count == 3 + return true + else + return false + end + end + + # files a new exception report in redmine + # @return true if new report was filed + def file_new_report + issue = Issue.new + issue.tracker = Tracker.find_by_name("Bug") + issue.subject = params[:msg] + issue.description = params[:description] + issue.project = Project.find_by_name(params[:app]) + issue.start_date = Time.now.localtime.strftime("%Y-%m-%d") + issue.priority = IssuePriority.find_by_name("Normal") + issue.author = User.find_by_mail("rickbarrette@gmail.com") + issue.status = IssueStatus.find_by_name("New") + + issue.save + end + +end #EOF \ No newline at end of file diff --git a/app/views/exceptionhandler/index.html.erb b/app/views/exceptionhandler/index.html.erb new file mode 100644 index 0000000..5094e50 --- /dev/null +++ b/app/views/exceptionhandler/index.html.erb @@ -0,0 +1,2 @@ +

Exception Handler

+<%= @output %> diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..c55090a --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,3 @@ +# English strings go here for Rails i18n +en: + my_label: "My label" diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..2a00ec7 --- /dev/null +++ b/init.rb @@ -0,0 +1,10 @@ +require 'redmine' + +Redmine::Plugin.register :redmine_exception_handler do + name 'Redmine Exception Handler plugin' + author 'Rick Barrette ' + description 'This is an Exception Report Handler plugin for Redmine' + version '0.0.1' + url 'http://example.com/path/to/plugin' + author_url 'http://rickbarrette.dyndns.org' +end diff --git a/lang/en.yml b/lang/en.yml new file mode 100644 index 0000000..e338591 --- /dev/null +++ b/lang/en.yml @@ -0,0 +1,2 @@ +# English strings go here +my_label: "My label" diff --git a/test/functional/exceptionhandler_controller_test.rb b/test/functional/exceptionhandler_controller_test.rb new file mode 100644 index 0000000..f6e9f1b --- /dev/null +++ b/test/functional/exceptionhandler_controller_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ExceptionhandlerControllerTest < ActionController::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..bd1ed0c --- /dev/null +++ b/test/test_helper.rb @@ -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