From 5570f4cf4243eb19d09e31fc389ba8b4620d737a Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Wed, 22 Feb 2012 12:57:29 -0500 Subject: [PATCH 1/3] Added support for package name. This will require a new manadoty custom field. Package name will be used for exsiting report checks. --- .../exceptionhandler_controller.rb | 169 ++++++++++++++---- 1 file changed, 138 insertions(+), 31 deletions(-) diff --git a/app/controllers/exceptionhandler_controller.rb b/app/controllers/exceptionhandler_controller.rb index f3976c2..a326517 100644 --- a/app/controllers/exceptionhandler_controller.rb +++ b/app/controllers/exceptionhandler_controller.rb @@ -1,7 +1,7 @@ -# exceptionhandler_controller.rb +# exceptionhandler_helper.rb # @date Feb. 15, 2012 # @author ricky barrette -# @author twenty codes +# @authro twenty codes # # Copyright 2012 Rick Barrette # @@ -17,38 +17,145 @@ # 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 - if params.size < 8 - @output = " not enough args " - elsif Project.find_by_name(params[:app]) == nil - @output = "No Project Found" - else - issue_id = check_for_existing_report - if issue_id > 0 - update_report(issue_id) - @output = "Updated report" - else - issue = create_new_report - if issue.valid? - issue.save - @output = "New report filed" - else - @output = issue.errors.full_messages +module ExceptionhandlerHelper + + # Checks the database for exisiting reports + # @return id report is existing else 0 + def check_for_existing_report + bug_id = tracker.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 - rescue RuntimeError - @output = "ERROR" + 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 check_issue_custom_values(issue) + return issue.id + 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 "Package" + if value.value == params[:package] + count += 1 + end + when "Cause" + if value.value == params[:cause] + count += 1 + end + end + end + if count == 4 + return true + else + return false + end + end + + # files a new exception report in redmine + # @return true if new report was filed + def create_new_report + issue = Issue.new + issue.tracker = tracker + 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 %T") + issue.priority = IssuePriority.find_by_name("Normal") + issue.author = User.anonymous + issue.status = IssueStatus.find_by_name("New") + + issue.custom_values = [ + create_custom_value(CustomField.find_by_name("StackTrace").id, params[:stackTrace]), + create_custom_value(CustomField.find_by_name("Cause").id, params[:cause]), + create_custom_value(CustomField.find_by_name("Count").id, "1"), + create_custom_value(CustomField.find_by_name("Device").id, params[:device]), + create_custom_value(CustomField.find_by_name("Version").id, value = params[:version]), + create_custom_value(CustomField.find_by_name("Package").id, value = params[:package]), + create_custom_value(CustomField.find_by_name("Date").id, value = params[:date]) + ] + return issue + end + + # returns a new custom value + def create_custom_value(field_id, value) + custom_value = CustomValue.new + custom_value.custom_field_id = field_id + custom_value.value = value + custom_value.customized_type = "Issue" + return custom_value + end + + # retrives an issue by it's id and updates it + # @returns updated issue + def update_report(issue_id) + issue = Issue.find_by_id(issue_id) + if params[:description].length > 0 + description = issue.description + description += "\n\n--- New Description --- \n" + description += params[:description] + issue.description = description + end + + custom_fields = CustomField + issue.custom_field_values.each do |value| + case custom_fields.find_by_id(value.custom_field_id).name + when "Device" + value.value = value.value += "\n" + value.value = value.value += params[:device] + when "Date" + value.value = value.value += "\n" + value.value = value.value += params[:date] + when "Count" + value.value = (value.value.to_i + 1).to_s + end + value.save + end + issue.init_journal(User.anonymous, "Issue updated") + issue.save + end + + # gets the prodived tracker + # if it doesnt exist, defualt to Bug + def tracker + if(params[:tracker]!= nil) + if params[:tracker].length > 0 + t = Tracker.find_by_name(params[:tracker]) + if(t != nil) + return t + end + end + end + return Tracker.find_by_name("Bug") end end #EOF From 8aa39f26ac575310866798f192ce2a886b9b8b4d Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Wed, 22 Feb 2012 13:17:48 -0500 Subject: [PATCH 2/3] Fixed my mistake of writing changes the the wronge file --- .../exceptionhandler_controller.rb | 165 +++--------------- app/helpers/exceptionhandler_helper.rb | 7 +- 2 files changed, 35 insertions(+), 137 deletions(-) diff --git a/app/controllers/exceptionhandler_controller.rb b/app/controllers/exceptionhandler_controller.rb index a326517..a7765fe 100644 --- a/app/controllers/exceptionhandler_controller.rb +++ b/app/controllers/exceptionhandler_controller.rb @@ -1,7 +1,7 @@ -# exceptionhandler_helper.rb +# exceptionhandler_controller.rb # @date Feb. 15, 2012 # @author ricky barrette -# @authro twenty codes +# @author twenty codes # # Copyright 2012 Rick Barrette # @@ -17,145 +17,38 @@ # 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.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 +# 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 - # checks a specific issue agains params - # @return id of report if matching, else 0 - def check_issue(issue) - if issue.subject == params[:msg] - if check_issue_custom_values(issue) - return issue.id + helper :exceptionhandler + include ExceptionhandlerHelper + + def index + if params.size < 9 + @output = " not enough args " + elsif Project.find_by_name(params[:app]) == nil + @output = "No Project Found" + else + issue_id = check_for_existing_report + if issue_id > 0 + update_report(issue_id) + @output = "Updated report" 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 "Package" - if value.value == params[:package] - count += 1 - end - when "Cause" - if value.value == params[:cause] - count += 1 - end - end - end - if count == 4 - return true - else - return false - end - end - - # files a new exception report in redmine - # @return true if new report was filed - def create_new_report - issue = Issue.new - issue.tracker = tracker - 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 %T") - issue.priority = IssuePriority.find_by_name("Normal") - issue.author = User.anonymous - issue.status = IssueStatus.find_by_name("New") - - issue.custom_values = [ - create_custom_value(CustomField.find_by_name("StackTrace").id, params[:stackTrace]), - create_custom_value(CustomField.find_by_name("Cause").id, params[:cause]), - create_custom_value(CustomField.find_by_name("Count").id, "1"), - create_custom_value(CustomField.find_by_name("Device").id, params[:device]), - create_custom_value(CustomField.find_by_name("Version").id, value = params[:version]), - create_custom_value(CustomField.find_by_name("Package").id, value = params[:package]), - create_custom_value(CustomField.find_by_name("Date").id, value = params[:date]) - ] - return issue - end - - # returns a new custom value - def create_custom_value(field_id, value) - custom_value = CustomValue.new - custom_value.custom_field_id = field_id - custom_value.value = value - custom_value.customized_type = "Issue" - return custom_value - end - - # retrives an issue by it's id and updates it - # @returns updated issue - def update_report(issue_id) - issue = Issue.find_by_id(issue_id) - if params[:description].length > 0 - description = issue.description - description += "\n\n--- New Description --- \n" - description += params[:description] - issue.description = description - end - - custom_fields = CustomField - issue.custom_field_values.each do |value| - case custom_fields.find_by_id(value.custom_field_id).name - when "Device" - value.value = value.value += "\n" - value.value = value.value += params[:device] - when "Date" - value.value = value.value += "\n" - value.value = value.value += params[:date] - when "Count" - value.value = (value.value.to_i + 1).to_s - end - value.save - end - issue.init_journal(User.anonymous, "Issue updated") - issue.save - end - - # gets the prodived tracker - # if it doesnt exist, defualt to Bug - def tracker - if(params[:tracker]!= nil) - if params[:tracker].length > 0 - t = Tracker.find_by_name(params[:tracker]) - if(t != nil) - return t + issue = create_new_report + if issue.valid? + issue.save + @output = "New report filed" + else + @output = issue.errors.full_messages end end end - return Tracker.find_by_name("Bug") + rescue RuntimeError + @output = "ERROR" end end #EOF diff --git a/app/helpers/exceptionhandler_helper.rb b/app/helpers/exceptionhandler_helper.rb index 091579b..a326517 100644 --- a/app/helpers/exceptionhandler_helper.rb +++ b/app/helpers/exceptionhandler_helper.rb @@ -64,13 +64,17 @@ module ExceptionhandlerHelper if value.value == params[:stackTrace] count += 1 end + when "Package" + if value.value == params[:package] + count += 1 + end when "Cause" if value.value == params[:cause] count += 1 end end end - if count == 3 + if count == 4 return true else return false @@ -96,6 +100,7 @@ module ExceptionhandlerHelper create_custom_value(CustomField.find_by_name("Count").id, "1"), create_custom_value(CustomField.find_by_name("Device").id, params[:device]), create_custom_value(CustomField.find_by_name("Version").id, value = params[:version]), + create_custom_value(CustomField.find_by_name("Package").id, value = params[:package]), create_custom_value(CustomField.find_by_name("Date").id, value = params[:date]) ] return issue From 8cca3b5eee57315d6af9fb97e16195abd3ab6ce9 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Wed, 22 Feb 2012 13:20:32 -0500 Subject: [PATCH 3/3] Updated version from 0.0.2 to 0.0.3 --- init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.rb b/init.rb index b66c643..ddef4af 100644 --- a/init.rb +++ b/init.rb @@ -4,7 +4,7 @@ Redmine::Plugin.register :redmine_exception_handler do name 'Redmine Exception Handler plugin' author 'Rick Barrette ' description 'An Exception Report Handler plugin for Redmine' - version '0.0.2' + version '0.0.3' url 'http://example.com/redmine/exceptionhandler' author_url 'http://rickbarrette.dyndns.org' end