Commit d9b711849c747a79289f66b2f4a179451858dcdf
Exists in
master
and in
1 other branch
Merge pull request #2 from RyanonRails/master
Added campfire functionality to errbit
Showing
10 changed files
with
74 additions
and
0 deletions
Show diff stats
Gemfile
Gemfile.lock
| ... | ... | @@ -40,6 +40,8 @@ GEM |
| 40 | 40 | bson (1.3.1) |
| 41 | 41 | bson_ext (1.3.1) |
| 42 | 42 | builder (3.0.0) |
| 43 | + campy (0.1.3) | |
| 44 | + multi_json (~> 1.0) | |
| 43 | 45 | capybara (1.1.2) |
| 44 | 46 | mime-types (>= 1.16) |
| 45 | 47 | nokogiri (>= 1.3.3) |
| ... | ... | @@ -275,6 +277,7 @@ DEPENDENCIES |
| 275 | 277 | actionmailer_inline_css (~> 1.3.0) |
| 276 | 278 | bson (= 1.3.1) |
| 277 | 279 | bson_ext (= 1.3.1) |
| 280 | + campy | |
| 278 | 281 | capybara |
| 279 | 282 | database_cleaner (~> 0.6.0) |
| 280 | 283 | devise (~> 1.5.3) | ... | ... |
3.19 KB
3.19 KB
2.8 KB
app/assets/stylesheets/issue_tracker_icons.css.erb
| 1 | 1 | /* Issue Tracker inactive, select, create and goto icons */ |
| 2 | 2 | <% trackers = IssueTracker.subclasses.map{|t| t.label } << 'none' %> |
| 3 | + | |
| 3 | 4 | <% trackers.each do |tracker| %> |
| 4 | 5 | div.issue_tracker.nested label.<%= tracker %> { |
| 5 | 6 | background: url(/assets/<%= tracker %>_inactive.png) no-repeat; | ... | ... |
app/models/issue_tracker.rb
| ... | ... | @@ -0,0 +1,39 @@ |
| 1 | +class IssueTrackers::CampfireTracker < IssueTracker | |
| 2 | + Label = "campfire" | |
| 3 | + Fields = [ | |
| 4 | + [:subdomain, { | |
| 5 | + :placeholder => "Campfire Subdomain" | |
| 6 | + }], | |
| 7 | + [:api_token, { | |
| 8 | + :placeholder => "API Token" | |
| 9 | + }], | |
| 10 | + [:project_id, { | |
| 11 | + :placeholder => "Room ID", | |
| 12 | + :label => "Room ID" | |
| 13 | + }], | |
| 14 | + ] | |
| 15 | + | |
| 16 | + def check_params | |
| 17 | + if Fields.detect {|f| self[f[0]].blank? } | |
| 18 | + errors.add :base, 'You must specify your Campfire Subdomain, API token and Room ID' | |
| 19 | + end | |
| 20 | + end | |
| 21 | + | |
| 22 | + def create_issue(problem, reported_by = nil) | |
| 23 | + # build the campfire client | |
| 24 | + campy = Campy::Room.new(:account => subdomain, :token => api_token, :room_id => project_id) | |
| 25 | + | |
| 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}" | |
| 28 | + | |
| 29 | + # update the problem to say where it was sent | |
| 30 | + problem.update_attributes( | |
| 31 | + :issue_link => "Sent to Campfire", | |
| 32 | + :issue_type => Label | |
| 33 | + ) | |
| 34 | + end | |
| 35 | + | |
| 36 | + def url | |
| 37 | + "http://#{subdomain}.campfirenow.com" | |
| 38 | + end | |
| 39 | +end | |
| 0 | 40 | \ No newline at end of file | ... | ... |
spec/fabricators/issue_tracker_fabricator.rb
| ... | ... | @@ -25,3 +25,9 @@ Fabricator :github_issues_tracker, :from => :issue_tracker, :class_name => "Issu |
| 25 | 25 | username 'test_username' |
| 26 | 26 | end |
| 27 | 27 | |
| 28 | +Fabricator :campfire_tracker, :from => :issue_tracker, :class_name => "IssueTrackers::CampfireTracker" do | |
| 29 | + subdomain 'camproomname' | |
| 30 | + api_token 1234567890 | |
| 31 | + project_id 888555 | |
| 32 | +end | |
| 33 | + | ... | ... |
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe IssueTrackers::CampfireTracker do | |
| 4 | + it "should post the error to campfire and display the error" do | |
| 5 | + # setup fabrications | |
| 6 | + notice = Fabricate :notice | |
| 7 | + tracker = Fabricate :campfire_tracker | |
| 8 | + | |
| 9 | + # stub out campy methods | |
| 10 | + campy = mock('CampfireTracker') | |
| 11 | + Campy::Room.stub(:new).and_return(campy) | |
| 12 | + campy.stub(:paste) { true } | |
| 13 | + | |
| 14 | + # expectations | |
| 15 | + campy.should_receive(:paste).once.with(/errbit|production|foo#bar/).and_return(true) | |
| 16 | + | |
| 17 | + # create the issue | |
| 18 | + tracker.create_issue(notice.problem) | |
| 19 | + end | |
| 20 | + | |
| 21 | + | |
| 22 | +end | |
| 23 | + | ... | ... |