Commit e012272c11cd3581404aa6bb42313565aafc076c

Authored by Nick Recobra
1 parent 5c3489a2
Exists in master and in 1 other branch production

Redmine issue tracker integration.

Gemfile.lock
1 1 GIT
2 2 remote: git://github.com/oruen/redmine_client.git
3   - revision: ab198901fdd7f67f43614c8e72e6c10f38c9387a
  3 + revision: 0df20a8b695869b03cfa129560b938a0af346add
4 4 specs:
5 5 redmine_client (0.0.1)
6 6 activeresource (>= 2.3.0)
... ...
app/models/issue_tracker.rb
... ... @@ -21,7 +21,16 @@ class IssueTracker
21 21  
22 22 protected
23 23 def create_redmine_issue err
24   -
  24 + token = api_token
  25 + RedmineClient::Base.configure do
  26 + self.token = token
  27 + end
  28 + RedmineClient::Issue.site = account + "/projects/:project_id"
  29 + issue = RedmineClient::Issue.new(:project_id => project_id)
  30 + issue.subject = issue_title err
  31 + issue.description = ERB.new(File.read(Rails.root + "app/views/errs/redmine_body.txt.erb").gsub(/^\s*/, '')).result(binding)
  32 + issue.save!
  33 + err.update_attribute :issue_link, "#{RedmineClient::Issue.site.to_s.sub(/#{RedmineClient::Issue.site.path}$/, '')}#{RedmineClient::Issue.element_path(issue.id, :project_id => project_id)}".sub(/\.xml$/, '')
25 34 end
26 35  
27 36 def create_lighthouseapp_issue err
... ... @@ -32,7 +41,7 @@ class IssueTracker
32 41 Lighthouse::Ticket.site
33 42  
34 43 ticket = Lighthouse::Ticket.new(:project_id => project_id)
35   - ticket.title = "[#{ err.environment }][#{ err.where }] #{err.message.to_s.truncate(100)}"
  44 + ticket.title = issue_title err
36 45  
37 46 ticket.body = ERB.new(File.read(Rails.root + "app/views/errs/lighthouseapp_body.txt.erb").gsub(/^\s*/, '')).result(binding)
38 47  
... ... @@ -41,6 +50,10 @@ class IssueTracker
41 50 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$/, '')
42 51 end
43 52  
  53 + def issue_title err
  54 + "[#{ err.environment }][#{ err.where }] #{err.message.to_s.truncate(100)}"
  55 + end
  56 +
44 57 def check_params
45 58 blank_flags = %w( api_token project_id account ).map {|m| self[m].blank? }
46 59 if blank_flags.any? && !blank_flags.all?
... ...
app/views/errs/redmine_body.txt.erb 0 → 100644
... ... @@ -0,0 +1,34 @@
  1 +"See this exception on Errbit":<%= app_err_url err.app, err %>
  2 +<% if notice = err.notices.first %>
  3 + h1. <%= notice.message %>
  4 + h2. Summary
  5 + <% if notice.request['url'].present? %>
  6 + h3. URL
  7 + [<%= notice.request['url'] %>](<%= notice.request['url'] %>)"
  8 + <% end %>
  9 + h3. Where
  10 + <%= notice.err.where %>
  11 +
  12 + h3. Occured
  13 + <%= notice.created_at.to_s(:micro) %>
  14 +
  15 + h3. Similar
  16 + <%= (notice.err.notices.count - 1).to_s %>
  17 +
  18 + h2. Params
  19 + <pre><%= pretty_hash(notice.params) %></pre>
  20 +
  21 + h2. Session
  22 + <pre><%= pretty_hash(notice.session) %></pre>
  23 +
  24 + h2. Backtrace
  25 + <pre>
  26 + <% for line in notice.backtrace %><%= line['number'] %>: <%= line['file'].sub(/^\[PROJECT_ROOT\]/, '') %> -> *<%= line['method'] %>*
  27 + <% end %>
  28 + </pre>
  29 +
  30 + h2. Environment
  31 + <% for key, val in notice.env_vars %>
  32 + <%= key %>: <%= val %>
  33 + <% end %>
  34 +<% end %>
... ...
spec/controllers/errs_controller_spec.rb
... ... @@ -262,19 +262,18 @@ describe ErrsController do
262 262 before(:each) do
263 263 number = 5
264 264 @issue_link = "#{tracker.account}/projects/#{tracker.project_id}/issues/#{number}.xml"
265   - body = "<issue></issue>"
  265 + body = "<issue><id type=\"integer\">#{number}</id></issue>"
266 266 stub_request(:post, "#{tracker.account}/projects/#{tracker.project_id}/issues.xml").to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body )
267 267  
268 268 post :create_issue, :app_id => err.app.id, :id => err.id
269 269 err.reload
270 270 end
271 271  
272   - it "should make request to Lighthouseapp with err params" do
273   - requested = have_requested(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml")
274   - WebMock.should requested.with(:headers => {'X-Lighthousetoken' => tracker.api_token})
275   - WebMock.should requested.with(:body => /<tag>errbit<\/tag>/)
276   - WebMock.should requested.with(:body => /<title>\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/title>/)
277   - WebMock.should requested.with(:body => /<body>.+<\/body>/m)
  272 + it "should make request to Redmine with err params" do
  273 + requested = have_requested(:post, "#{tracker.account}/projects/#{tracker.project_id}/issues.xml")
  274 + WebMock.should requested.with(:headers => {'X-Redmine-API-Key' => tracker.api_token})
  275 + WebMock.should requested.with(:body => /<subject>\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/subject>/)
  276 + WebMock.should requested.with(:body => /<description>.+<\/description>/m)
278 277 end
279 278  
280 279 it "should redirect to err page" do
... ...