Commit 5d9e0d99e97f44818d3f7247f080cdbcfadae508

Authored by darkodosenovic
2 parents d9b71184 52f0f6d7
Exists in master and in 1 other branch production

Merge pull request #3 from amaabca/display_tweaks

More campfire integration
Gemfile
... ... @@ -34,6 +34,7 @@ gem 'rack-ssl-enforcer'
34 34 gem 'fabrication', "~> 1.3.0" # Both for tests, and loading demo data
35 35 gem 'rails_autolink', '~> 1.0.9'
36 36 gem 'campy'
  37 +gem 'heroku'
37 38  
38 39 platform :ruby do
39 40 gem 'mongo', '= 1.3.1'
... ...
Gemfile.lock
... ... @@ -68,6 +68,7 @@ GEM
68 68 rspec (~> 2.0)
69 69 erubis (2.7.0)
70 70 eventmachine (0.12.10)
  71 + excon (0.15.5)
71 72 execjs (1.4.0)
72 73 multi_json (~> 1.0)
73 74 fabrication (1.3.2)
... ... @@ -81,6 +82,14 @@ GEM
81 82 libxml-ruby (~> 2.0)
82 83 has_scope (0.5.1)
83 84 hashie (1.2.0)
  85 + heroku (2.30.1)
  86 + heroku-api (~> 0.3.1)
  87 + launchy (>= 0.3.2)
  88 + netrc (~> 0.7.5)
  89 + rest-client (~> 1.6.1)
  90 + rubyzip
  91 + heroku-api (0.3.2)
  92 + excon (~> 0.15.5)
84 93 hike (1.2.1)
85 94 hoptoad_notifier (2.4.11)
86 95 activesupport
... ... @@ -128,6 +137,7 @@ GEM
128 137 railties (>= 3.0.0)
129 138 multi_json (1.3.6)
130 139 multipart-post (1.1.5)
  140 + netrc (0.7.5)
131 141 nokogiri (1.5.0)
132 142 oa-core (0.3.2)
133 143 oauth2 (0.5.2)
... ... @@ -285,6 +295,7 @@ DEPENDENCIES
285 295 execjs
286 296 fabrication (~> 1.3.0)
287 297 haml
  298 + heroku
288 299 hoptoad_notifier (~> 2.4)
289 300 htmlentities (~> 4.3.0)
290 301 inherited_resources
... ...
app/models/issue_trackers/campfire_tracker.rb
... ... @@ -24,11 +24,11 @@ class IssueTrackers::CampfireTracker < IssueTracker
24 24 campy = Campy::Room.new(:account => subdomain, :token => api_token, :room_id => project_id)
25 25  
26 26 # post the issue to the campfire room
27   - campy.paste "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{issue_title problem}"
  27 + campy.speak "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{issue_title problem}"
28 28  
29 29 # update the problem to say where it was sent
30 30 problem.update_attributes(
31   - :issue_link => "Sent to Campfire",
  31 + :issue_link => url,
32 32 :issue_type => Label
33 33 )
34 34 end
... ...
app/models/notice_observer.rb
... ... @@ -4,6 +4,11 @@ class NoticeObserver < Mongoid::Observer
4 4 def after_create notice
5 5 return unless should_notify? notice
6 6  
  7 + # if the app has the campfire tracker, post into the chat
  8 + if !notice.app.issue_tracker.nil? && notice.app.issue_tracker.is_a?(CampfireTracker)
  9 + notice.app.issue_tracker.create_issue(notice)
  10 + end
  11 +
7 12 Mailer.err_notification(notice).deliver
8 13 end
9 14  
... ... @@ -15,5 +20,4 @@ class NoticeObserver < Mongoid::Observer
15 20 (Errbit::Config.per_app_email_at_notices && app.email_at_notices || Errbit::Config.email_at_notices).include?(notice.problem.notices_count) &&
16 21 app.notification_recipients.any?
17 22 end
18   -
19 23 end
... ...
app/views/errs/_issue_tracker_links.html.haml
1   -- if @app.issue_tracker_configured? || current_user.github_account?
2   - - if @problem.issue_link.present?
3   - %span= link_to 'go to issue', @problem.issue_link, :class => "#{@problem.issue_type}_goto goto-issue"
4   - = link_to 'unlink issue', unlink_issue_app_err_path(@app, @problem), :method => :delete, :data => { :confirm => "Unlink err issues?" }, :class => "unlink-issue"
5   - - elsif @problem.issue_link == "pending"
6   - %span.disabled= link_to 'creating...', '#', :class => "#{@problem.issue_type}_inactive create-issue"
7   - = link_to 'retry', create_issue_app_err_path(@app, @problem), :method => :post
8   - - else
9   - - if @app.github_repo?
10   - - if current_user.can_create_github_issues?
11   - %span= link_to 'create issue', create_issue_app_err_path(@app, @problem, :tracker => 'user_github'), :method => :post, :class => "github_create create-issue"
12   - - elsif @app.issue_tracker_configured? && @app.issue_tracker.is_a?(GithubIssuesTracker)
13   - %span= link_to 'create issue', create_issue_app_err_path(@app, @problem), :method => :post, :class => "github_create create-issue"
14   - - if @app.issue_tracker_configured? && !@app.issue_tracker.is_a?(GithubIssuesTracker)
15   - %span= link_to 'create issue', create_issue_app_err_path(@app, @problem), :method => :post, :class => "#{@app.issue_tracker.label}_create create-issue"
  1 +- unless @app.issue_tracker_configured? && @app.issue_tracker.is_a?(CampfireTracker)
  2 + - if @app.issue_tracker_configured? || current_user.github_account?
  3 + - if @problem.issue_link.present?
  4 + %span= link_to 'go to issue', @problem.issue_link, :class => "#{@problem.issue_type}_goto goto-issue"
  5 + = link_to 'unlink issue', unlink_issue_app_err_path(@app, @problem), :method => :delete, :data => { :confirm => "Unlink err issues?" }, :class => "unlink-issue"
  6 + - elsif @problem.issue_link == "pending"
  7 + %span.disabled= link_to 'creating...', '#', :class => "#{@problem.issue_type}_inactive create-issue"
  8 + = link_to 'retry', create_issue_app_err_path(@app, @problem), :method => :post
  9 + - else
  10 + - if @app.github_repo?
  11 + - if current_user.can_create_github_issues?
  12 + %span= link_to 'create issue', create_issue_app_err_path(@app, @problem, :tracker => 'user_github'), :method => :post, :class => "github_create create-issue"
  13 + - elsif @app.issue_tracker_configured? && @app.issue_tracker.is_a?(GithubIssuesTracker)
  14 + %span= link_to 'create issue', create_issue_app_err_path(@app, @problem), :method => :post, :class => "github_create create-issue"
  15 + - if @app.issue_tracker_configured? && !@app.issue_tracker.is_a?(GithubIssuesTracker)
  16 + %span= link_to 'create issue', create_issue_app_err_path(@app, @problem), :method => :post, :class => "#{@app.issue_tracker.label}_create create-issue"
... ...
lib/tasks/errbit/demo.rake
... ... @@ -41,7 +41,7 @@ namespace :errbit do
41 41 end
42 42  
43 43 errors.each do |error_template|
44   - rand(34).times do
  44 + rand(1).times do
45 45  
46 46 error_report = error_template.reverse_merge({
47 47 :error_class => "StandardError",
... ...
spec/controllers/errs_controller_spec.rb
... ... @@ -188,6 +188,14 @@ describe ErrsController do
188 188 response.body.should_not button_matcher
189 189 end
190 190  
  191 + it "should not exist for err's app with campfire" do
  192 + tracker = Fabricate(:campfire_tracker)
  193 + err = Fabricate(:err, :problem => Fabricate(:problem, :app => tracker.app))
  194 + get :show, :app_id => err.app.id, :id => err.problem.id
  195 +
  196 + response.body.should_not button_matcher
  197 + end
  198 +
191 199 it "should exist for err's app with issue tracker" do
192 200 tracker = Fabricate(:lighthouse_tracker)
193 201 err = Fabricate(:err, :problem => Fabricate(:problem, :app => tracker.app))
... ...
spec/models/issue_trackers/campfire_tracker_spec.rb
... ... @@ -9,15 +9,13 @@ describe IssueTrackers::CampfireTracker do
9 9 # stub out campy methods
10 10 campy = mock('CampfireTracker')
11 11 Campy::Room.stub(:new).and_return(campy)
12   - campy.stub(:paste) { true }
  12 + campy.stub(:speak) { true }
13 13  
14 14 # expectations
15   - campy.should_receive(:paste).once.with(/errbit|production|foo#bar/).and_return(true)
  15 + campy.should_receive(:speak).once.with(/errbit|production|foo#bar/).and_return(true)
16 16  
17 17 # create the issue
18 18 tracker.create_issue(notice.problem)
19 19 end
20   -
21   -
22 20 end
23 21  
... ...
spec/models/notice_observer_spec.rb
... ... @@ -43,4 +43,26 @@ describe NoticeObserver do
43 43 Fabricate(:notice, :err => @err)
44 44 end
45 45 end
  46 +
  47 + describe "notifications for campfire" do
  48 +
  49 + before do
  50 + Errbit::Config.per_app_email_at_notices = true
  51 + @app = Fabricate(:app_with_watcher, :email_at_notices => [1], :issue_tracker => Fabricate(:campfire_tracker))
  52 + @err = Fabricate(:err, :problem => Fabricate(:problem, :app => @app, :notices_count => 100))
  53 + end
  54 +
  55 + after do
  56 + Errbit::Config.per_app_email_at_notices = false
  57 + end
  58 +
  59 + it "should create a campfire issue" do
  60 + @err.problem.stub(:notices_count).and_return(1)
  61 + @app.issue_tracker.stub!(:create_issue).and_return(true)
  62 + @app.issue_tracker.should_receive(:create_issue)
  63 +
  64 + Fabricate(:notice, :err => @err)
  65 + end
  66 + end
  67 +
46 68 end
... ...