Commit 5b0a2d55ca4a19cc64dc053cce02bc24e63d8514
1 parent
cda23ec8
Exists in
master
and in
1 other branch
Using ERB to render lighthouseapp body.
Showing
2 changed files
with
45 additions
and
57 deletions
Show diff stats
app/models/issue_tracker.rb
... | ... | @@ -15,6 +15,16 @@ class IssueTracker |
15 | 15 | field :issue_tracker_type, :type => String, :default => 'lighthouseapp' |
16 | 16 | |
17 | 17 | def create_issue err |
18 | + return create_lighthouseapp_issue err if issue_tracker_type == 'lighthouseapp' | |
19 | + create_redmine_issue err if issue_tracker_type == 'redmine' | |
20 | + end | |
21 | + | |
22 | + protected | |
23 | + def create_redmine_issue err | |
24 | + | |
25 | + end | |
26 | + | |
27 | + def create_lighthouseapp_issue err | |
18 | 28 | Lighthouse.account = account |
19 | 29 | Lighthouse.token = api_token |
20 | 30 | |
... | ... | @@ -24,69 +34,13 @@ class IssueTracker |
24 | 34 | ticket = Lighthouse::Ticket.new(:project_id => project_id) |
25 | 35 | ticket.title = "[#{ err.environment }][#{ err.where }] #{err.message.to_s.truncate(100)}" |
26 | 36 | |
27 | - ticket.body = "" | |
28 | - ticket.body += "[See this exception on Errbit](#{ app_err_url err.app, err } \"See this exception on Errbit\")" | |
29 | - ticket.body += "\n" | |
30 | - if notice = err.notices.first | |
31 | - ticket.body += "# #{notice.message} #" | |
32 | - ticket.body += "\n" | |
33 | - ticket.body += "## Summary ##" | |
34 | - ticket.body += "\n" | |
35 | - if notice.request['url'].present? | |
36 | - ticket.body += "### URL ###" | |
37 | - ticket.body += "\n" | |
38 | - ticket.body += "[#{notice.request['url']}](#{notice.request['url']})" | |
39 | - ticket.body += "\n" | |
40 | - end | |
41 | - ticket.body += "### Where ###" | |
42 | - ticket.body += "\n" | |
43 | - ticket.body += notice.err.where | |
44 | - ticket.body += "\n" | |
45 | - | |
46 | - ticket.body += "### Occured ###" | |
47 | - ticket.body += "\n" | |
48 | - ticket.body += notice.created_at.to_s(:micro) | |
49 | - ticket.body += "\n" | |
50 | - | |
51 | - ticket.body += "### Similar ###" | |
52 | - ticket.body += "\n" | |
53 | - ticket.body += (notice.err.notices.count - 1).to_s | |
54 | - ticket.body += "\n" | |
55 | - | |
56 | - ticket.body += "## Params ##" | |
57 | - ticket.body += "\n" | |
58 | - ticket.body += "<code>#{pretty_hash(notice.params)}</code>" | |
59 | - ticket.body += "\n" | |
60 | - | |
61 | - ticket.body += "## Session ##" | |
62 | - ticket.body += "\n" | |
63 | - ticket.body += "<code>#{pretty_hash(notice.session)}</code>" | |
64 | - ticket.body += "\n" | |
65 | - | |
66 | - ticket.body += "## Backtrace ##" | |
67 | - ticket.body += "\n" | |
68 | - ticket.body += "<code>" | |
69 | - for line in notice.backtrace | |
70 | - ticket.body += "#{line['number']}: #{line['file'].sub(/^\[PROJECT_ROOT\]/, '')} -> **#{line['method']}**" | |
71 | - ticket.body += "\n" | |
72 | - end | |
73 | - ticket.body += "</code>" | |
74 | - ticket.body += "\n" | |
75 | - | |
76 | - ticket.body += "## Environment ##" | |
77 | - ticket.body += "\n" | |
78 | - for key, val in notice.env_vars | |
79 | - ticket.body += "#{key}: #{val}" | |
80 | - end | |
81 | - ticket.body += "\n" | |
82 | - end | |
37 | + ticket.body = ERB.new(File.read(Rails.root + "app/views/errs/lighthouseapp_body.txt.erb").gsub(/^\s*/, '')).result(binding) | |
83 | 38 | |
84 | 39 | ticket.tags << "errbit" |
85 | 40 | ticket.save! |
86 | 41 | 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$/, '') |
87 | 42 | end |
88 | 43 | |
89 | - protected | |
90 | 44 | def check_params |
91 | 45 | blank_flags = %w( api_token project_id account ).map {|m| self[m].blank? } |
92 | 46 | if blank_flags.any? && !blank_flags.all? | ... | ... |
... | ... | @@ -0,0 +1,34 @@ |
1 | +[See this exception on Errbit](<%= app_err_url err.app, err %> "See this exception on Errbit") | |
2 | +<% if notice = err.notices.first %> | |
3 | + # <%= notice.message %> # | |
4 | + ## Summary ## | |
5 | + <% if notice.request['url'].present? %> | |
6 | + ### URL ### | |
7 | + [<%= notice.request['url'] %>](<%= notice.request['url'] %>)" | |
8 | + <% end %> | |
9 | + ### Where ### | |
10 | + <%= notice.err.where %> | |
11 | + | |
12 | + ### Occured ### | |
13 | + <%= notice.created_at.to_s(:micro) %> | |
14 | + | |
15 | + ### Similar ### | |
16 | + <%= (notice.err.notices.count - 1).to_s %> | |
17 | + | |
18 | + ## Params ## | |
19 | + <code><%= pretty_hash(notice.params) %></code> | |
20 | + | |
21 | + ## Session ## | |
22 | + <code><%= pretty_hash(notice.session) %></code> | |
23 | + | |
24 | + ## Backtrace ## | |
25 | + <code> | |
26 | + <% for line in notice.backtrace %><%= line['number'] %>: <%= line['file'].sub(/^\[PROJECT_ROOT\]/, '') %> -> **<%= line['method'] %>** | |
27 | + <% end %> | |
28 | + </code> | |
29 | + | |
30 | + ## Environment ## | |
31 | + <% for key, val in notice.env_vars %> | |
32 | + <%= key %>: <%= val %> | |
33 | + <% end %> | |
34 | +<% end %> | ... | ... |