Skip to content

Commit

Permalink
Merge pull request errbit#827 from stevecrozz/issue_tracker_templates
Browse files Browse the repository at this point in the history
Refs errbit#785 add md and txt issue tracker templates
  • Loading branch information
stevecrozz committed Feb 13, 2015
2 parents ce703f5 + b8bacbc commit 6cb19c2
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 41 deletions.
2 changes: 1 addition & 1 deletion app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def show
end

def create_issue
body = render_to_string "issue_trackers/issue", layout: false, formats: [:txt]
body = render_to_string "issue_trackers/issue", layout: false, formats: [:md]
title = "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}"

issue = Issue.new(problem: problem, user: current_user, title: title, body: body)
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/hash_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module HashHelper

def pretty_hash(hash, nesting = 0)
return '{}' if hash.empty?

tab_size = 2
nesting += 1

Expand Down
41 changes: 41 additions & 0 deletions app/views/issue_trackers/issue.md.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[See this exception on Errbit](<%= app_problem_url problem.app, problem %>)
<% if notice = problem.notices.first %>
# <%= notice.message %> #
## Summary ##
<% if notice.request['url'].present? %>
### URL ###
[<%= notice.request['url'] %>](<%= notice.request['url'] %>)"
<% end %>
### Where ###
<%= notice.where %>

### Occured ###
<%= notice.created_at.to_s(:micro) %>

### Similar ###
<%= (notice.problem.notices_count - 1).to_s %>

## Params ##
~~~
<%= pretty_hash(notice.params) %>
~~~

## Session ##
~~~
<%= pretty_hash(notice.session) %>
~~~

## Backtrace ##
~~~
<% notice.backtrace_lines.each do |line| %><%= line.number %>: <%= line.file_relative %> -> **<%= line.method %>**
<% end %>
~~~

<% if notice.env_vars.present? %>
## Environment ##
| Key | Value |
|------------|------------|
<% notice.env_vars.each do |key, val| %>| <%= key %> | <%= val %> |
<% end %>
<% end %>
<% end %>
56 changes: 16 additions & 40 deletions app/views/issue_trackers/issue.txt.erb
Original file line number Diff line number Diff line change
@@ -1,45 +1,21 @@
[See this exception on Errbit](<%= app_problem_url problem.app, problem %> "See this exception on Errbit")
Errbit link: <%= app_problem_url problem.app, problem %>
<% if notice = problem.notices.first %>
# <%= notice.message %> #
## Summary ##
<% if notice.request['url'].present? %>
### URL ###
[<%= notice.request['url'] %>](<%= notice.request['url'] %>)"
<% end %>
### Where ###
<%= notice.where %>

### Occured ###
<%= notice.created_at.to_s(:micro) %>

### Similar ###
<%= (notice.problem.notices_count - 1).to_s %>

## Params ##
```
<%= pretty_hash(notice.params) %>
```
<% notice.message %>

## Session ##
```
<%= pretty_hash(notice.session) %>
```

## Backtrace ##
```
<% notice.backtrace_lines.each do |line| %><%= line.number %>: <%= line.file_relative %> -> **<%= line.method %>**
Summary
-------
<% if notice.request['url'].present? %>
URL: <%= notice.request['url'] %>
<% end %>
```

## Environment ##

<table>
<% for key, val in notice.env_vars %>
<tr>
<td><%= key %>:</td>
<td><%= val %></td>
</tr>
Where: <%= notice.where %>
Occured: <%= notice.created_at.to_s(:micro) %>
Similar: <%= (notice.problem.notices_count - 1).to_s %>
Params: <%= pretty_hash notice.params %>
Session: <%= pretty_hash notice.session %>
Env: <%= pretty_hash notice.env_vars %>

Backtrace
---------
<% notice.backtrace_lines.each do |line| %><%= sprintf('%5d: %s **%s', line.number, line.file_relative, line.method) %>
<% end %>
</table>
<% end %>

16 changes: 16 additions & 0 deletions spec/views/issue_trackers/issue.md.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe "issue_trackers/issue.md.erb", type: 'view' do
let(:problem) {
problem = Fabricate(:problem)
Fabricate(:notice, :err => Fabricate(:err, :problem => problem))
problem
}

before do
allow(view).to receive(:problem).and_return(problem)
end

it "has the problem url" do
render
expect(rendered).to match(app_problem_url problem.app, problem)
end
end
16 changes: 16 additions & 0 deletions spec/views/issue_trackers/issue.txt.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe "issue_trackers/issue.txt.erb", type: 'view' do
let(:problem) {
problem = Fabricate(:problem)
Fabricate(:notice, :err => Fabricate(:err, :problem => problem))
problem
}

before do
allow(view).to receive(:problem).and_return(problem)
end

it "has the problem url" do
render
expect(rendered).to match(app_problem_url problem.app, problem)
end
end

0 comments on commit 6cb19c2

Please sign in to comment.