diff --git a/app/models/issue_tracker.rb b/app/models/issue_tracker.rb index a770c57..bac6f1a 100644 --- a/app/models/issue_tracker.rb +++ b/app/models/issue_tracker.rb @@ -15,6 +15,16 @@ class IssueTracker field :issue_tracker_type, :type => String, :default => 'lighthouseapp' def create_issue err + return create_lighthouseapp_issue err if issue_tracker_type == 'lighthouseapp' + create_redmine_issue err if issue_tracker_type == 'redmine' + end + + protected + def create_redmine_issue err + + end + + def create_lighthouseapp_issue err Lighthouse.account = account Lighthouse.token = api_token @@ -24,69 +34,13 @@ class IssueTracker ticket = Lighthouse::Ticket.new(:project_id => project_id) ticket.title = "[#{ err.environment }][#{ err.where }] #{err.message.to_s.truncate(100)}" - ticket.body = "" - ticket.body += "[See this exception on Errbit](#{ app_err_url err.app, err } \"See this exception on Errbit\")" - ticket.body += "\n" - if notice = err.notices.first - ticket.body += "# #{notice.message} #" - ticket.body += "\n" - ticket.body += "## Summary ##" - ticket.body += "\n" - if notice.request['url'].present? - ticket.body += "### URL ###" - ticket.body += "\n" - ticket.body += "[#{notice.request['url']}](#{notice.request['url']})" - ticket.body += "\n" - end - ticket.body += "### Where ###" - ticket.body += "\n" - ticket.body += notice.err.where - ticket.body += "\n" - - ticket.body += "### Occured ###" - ticket.body += "\n" - ticket.body += notice.created_at.to_s(:micro) - ticket.body += "\n" - - ticket.body += "### Similar ###" - ticket.body += "\n" - ticket.body += (notice.err.notices.count - 1).to_s - ticket.body += "\n" - - ticket.body += "## Params ##" - ticket.body += "\n" - ticket.body += "#{pretty_hash(notice.params)}" - ticket.body += "\n" - - ticket.body += "## Session ##" - ticket.body += "\n" - ticket.body += "#{pretty_hash(notice.session)}" - ticket.body += "\n" - - ticket.body += "## Backtrace ##" - ticket.body += "\n" - ticket.body += "" - for line in notice.backtrace - ticket.body += "#{line['number']}: #{line['file'].sub(/^\[PROJECT_ROOT\]/, '')} -> **#{line['method']}**" - ticket.body += "\n" - end - ticket.body += "" - ticket.body += "\n" - - ticket.body += "## Environment ##" - ticket.body += "\n" - for key, val in notice.env_vars - ticket.body += "#{key}: #{val}" - end - ticket.body += "\n" - end + ticket.body = ERB.new(File.read(Rails.root + "app/views/errs/lighthouseapp_body.txt.erb").gsub(/^\s*/, '')).result(binding) ticket.tags << "errbit" ticket.save! err.update_attribute :issue_link, "#{Lighthouse::Ticket.site.to_s.sub(/#{Lighthouse::Ticket.site.path}$/, '')}#{Lighthouse::Ticket.element_path(ticket.id, :project_id => project_id)}".sub(/\.xml$/, '') end - protected def check_params blank_flags = %w( api_token project_id account ).map {|m| self[m].blank? } if blank_flags.any? && !blank_flags.all? diff --git a/app/views/errs/lighthouseapp_body.txt.erb b/app/views/errs/lighthouseapp_body.txt.erb new file mode 100644 index 0000000..c0c6d81 --- /dev/null +++ b/app/views/errs/lighthouseapp_body.txt.erb @@ -0,0 +1,34 @@ +[See this exception on Errbit](<%= app_err_url err.app, err %> "See this exception on Errbit") +<% if notice = err.notices.first %> + # <%= notice.message %> # + ## Summary ## + <% if notice.request['url'].present? %> + ### URL ### + [<%= notice.request['url'] %>](<%= notice.request['url'] %>)" + <% end %> + ### Where ### + <%= notice.err.where %> + + ### Occured ### + <%= notice.created_at.to_s(:micro) %> + + ### Similar ### + <%= (notice.err.notices.count - 1).to_s %> + + ## Params ## + <%= pretty_hash(notice.params) %> + + ## Session ## + <%= pretty_hash(notice.session) %> + + ## Backtrace ## + + <% for line in notice.backtrace %><%= line['number'] %>: <%= line['file'].sub(/^\[PROJECT_ROOT\]/, '') %> -> **<%= line['method'] %>** + <% end %> + + + ## Environment ## + <% for key, val in notice.env_vars %> + <%= key %>: <%= val %> + <% end %> +<% end %> -- libgit2 0.21.2