Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 26, 2012
@terrcin terrcin Added in some extra custom fields: Application, Last Occurred At. Onl…
…y updated dup issues if they are in the same ENV
3f0aa39
@terrcin terrcin better formatting of the issue subject e33401f
Commits on Mar 28, 2012
@terrcin terrcin putting the app and env in the subject so it's easily seen when looki…
…ng at emails, posting backtrace every 10 occurances and correctly reopening closed tickets.
c5c4b1b
Showing with 47 additions and 18 deletions.
  1. +47 −18 app/controllers/airbrake_controller.rb
View
65 app/controllers/airbrake_controller.rb
@@ -21,12 +21,15 @@ def index
read_settings(redmine_params)
subject = build_subject
- @issue = Issue.find_by_subject_and_project_id_and_tracker_id(subject, @settings[:project].id, @settings[:tracker].id)
-
+ @issue = Issue.find_by_subject_and_project_id_and_tracker_id(subject, @settings[:project].id, @settings[:tracker].id, :order => 'id DESC')
+
if @issue.nil?
create_new_issue
- else
+ elsif @issue.custom_value_for(@environment_field.id).value == @notice['server_environment']['environment_name'] && @issue.custom_value_for(@application_field.id).value == redmine_params[:application]
+
update_existing_issue
+ else
+ create_new_issue
end
render :layout => false
@@ -80,6 +83,7 @@ def read_settings(params)
@settings[:author] = User.find_by_login(params[:login]) if params.has_key?(:login)
@settings[:category] = IssueCategory.find_by_name(params[:category]) if params.has_key?(:category)
@settings[:assign_to] = User.find_by_login(params[:assigned_to]) if params.has_key?(:assigned_to)
+ @settings[:application] = params[:application] if params.has_key?(:application)
read_local_settings
check_custom_field_assignments
@@ -104,8 +108,10 @@ def create_new_issue
@issue.assigned_to = @settings[:assign_to]
@issue.priority = @settings[:priority] unless @settings[:priority].nil?
@issue.description = render_to_string(:partial => 'issue_description')
- @issue.status = issue_status_open
+ @issue.status = IssueStatus.default
@issue.custom_values.build(:custom_field => @occurrences_field, :value => '1')
+ @issue.custom_values.build(:custom_field => @last_occured_field, :value => Time.now.to_date.to_s )
+ @issue.custom_values.build(:custom_field => @application_field, :value => @settings[:application])
@issue.custom_values.build(:custom_field => @environment_field, :value => @notice['server_environment']['environment_name'])
@issue.custom_values.build(:custom_field => @version_field, :value => @notice['server_environment']['app_version']) unless @notice['server_environment']['app_version'].nil?
@issue.save!
@@ -119,31 +125,42 @@ def check_custom_field_assignments
end
def update_existing_issue
- environment_name = @notice['server_environment']['environment_name']
- if (['always', environment_name].include?(@settings[:reopen_strategy]))
- @issue.status = issue_status_open if @issue.status.is_closed?
- @issue.init_journal(@settings[:author], "h4. Issue reopened after occurring again in #{environment_name} environment")
- end
+
number_occurrences = @issue.custom_value_for(@occurrences_field.id).value
- @issue.custom_field_values = { @occurrences_field.id => (number_occurrences.to_i+1).to_s }
+ @issue.custom_field_values = { @occurrences_field.id => (number_occurrences.to_i+1).to_s, @last_occured_field.id => Time.now.to_date.to_s }
+
+ if @issue.closed?
+ @issue.status = IssueStatus.default
+ environment_name = @notice['server_environment']['environment_name']
+ journal = @issue.init_journal(@settings[:author], "h4. Issue reopened after happening again.Occurances was at #{number_occurrences.to_s}")
+ journal.notes = render_to_string(:partial => 'issue_description') # put in new call stack just in case it's relavant. the issue had closed after all.
+ journal.save
+ elsif number_occurrences % 10 == 0
+ journal = @issue.journals.new :version => @issue.journals.maximum(:version)+1
+ journal.notes = journal.notes = render_to_string(:partial => 'issue_description') # put in new call stack every now and again just in case it's relavant
+ journal.save
+ end
+
@issue.save!
+ begin
+ @issue.touch # forcing this as the above doesn't actually change the updated_on field all the time
+ rescue
+ end
end
-
- def issue_status_open
- IssueStatus.find(:first, :conditions => {:is_default => true}, :order => 'position ASC')
- end
-
+
def build_subject
error_class = @notice['error']['class']
# if there's only one line, it gets parsed into a hash instead of an array
+ # the split is to remove [PROJECT_ROOT] etc... from within the begining of the file name makes it nicer when listing issues
if @notice['error']['backtrace']['line'].is_a? Hash
- file = @notice['error']['backtrace']['line']['file']
+ file = @notice['error']['backtrace']['line']['file'].split(']/').last
line = @notice['error']['backtrace']['line']['number']
else
- file = @notice['error']['backtrace']['line'].first()['file']
+ file = @notice['error']['backtrace']['line'].first()['file'].split(']/').last
line = @notice['error']['backtrace']['line'].first()['number']
end
- "[Airbrake] #{error_class} in #{file}:#{line}"[0..254]
+
+ "[#{@settings[:application]}:#{@notice['server_environment']['environment_name']}] #{error_class} in #{file}:#{ line[([-200, line.length*-1].max)..-1] }"
end
def find_or_create_custom_fields
@@ -153,6 +170,18 @@ def find_or_create_custom_fields
@occurrences_field.save(false)
end
+ @last_occured_field = IssueCustomField.find_or_initialize_by_name('Last occurance')
+ if @last_occured_field.new_record?
+ @last_occured_field.attributes = {:field_format => 'date', :default_value => '', :is_filter => true}
+ @last_occured_field.save(false)
+ end
+
+ @application_field = IssueCustomField.find_or_initialize_by_name('Application')
+ if @application_field.new_record?
+ @application_field.attributes = {:field_format => 'string', :default_value => '', :is_filter => true}
+ @application_field.save(false)
+ end
+
@environment_field = IssueCustomField.find_or_initialize_by_name('Environment')
if @environment_field.new_record?
@environment_field.attributes = {:field_format => 'string', :default_value => 'production', :is_filter => true}

No commit comments for this range

Something went wrong with that request. Please try again.