Commit 3dc67f13a8c2b4bbc5ed09afd3b384b612caa0e6

Authored by Stephen Crosby
1 parent 76db1687
Exists in master and in 1 other branch production

update to errbit_plugin v0.2.0

@@ -25,13 +25,10 @@ gem 'rails_autolink' @@ -25,13 +25,10 @@ gem 'rails_autolink'
25 # Please don't update hoptoad_notifier to airbrake. 25 # Please don't update hoptoad_notifier to airbrake.
26 # It's for internal use only, and we monkeypatch certain methods 26 # It's for internal use only, and we monkeypatch certain methods
27 gem 'hoptoad_notifier', "~> 2.4" 27 gem 'hoptoad_notifier', "~> 2.4"
  28 +gem 'draper', :require => false
28 29
29 -gem 'errbit_plugin',  
30 - :git => 'https://github.com/errbit/errbit_plugin.git'  
31 - # :path => 'vendor/gems/errbit_plugin'  
32 -gem 'errbit_github_plugin',  
33 - :git => 'https://github.com/errbit/errbit_github_plugin.git'  
34 - # :path => 'vendor/gems/errbit_github_plugin' 30 +gem 'errbit_plugin'
  31 +gem 'errbit_github_plugin'
35 32
36 # Notification services 33 # Notification services
37 # --------------------------------------- 34 # ---------------------------------------
1 -GIT  
2 - remote: https://github.com/errbit/errbit_github_plugin.git  
3 - revision: c0f3b366110b4c5e61b06a0acbdb3e19aa2b0379  
4 - specs:  
5 - errbit_github_plugin (0.0.1)  
6 - errbit_plugin  
7 - octokit  
8 -  
9 -GIT  
10 - remote: https://github.com/errbit/errbit_plugin.git  
11 - revision: 1bac2fb6800b0ad24233093fc6891d34bb20e2eb  
12 - specs:  
13 - errbit_plugin (0.0.1)  
14 -  
15 GEM 1 GEM
16 remote: https://rubygems.org/ 2 remote: https://rubygems.org/
17 specs: 3 specs:
@@ -46,7 +32,7 @@ GEM @@ -46,7 +32,7 @@ GEM
46 activesupport (3.2.18) 32 activesupport (3.2.18)
47 i18n (~> 0.6, >= 0.6.4) 33 i18n (~> 0.6, >= 0.6.4)
48 multi_json (~> 1.0) 34 multi_json (~> 1.0)
49 - addressable (2.3.5) 35 + addressable (2.3.6)
50 airbrake (3.1.14) 36 airbrake (3.1.14)
51 builder 37 builder
52 json 38 json
@@ -95,14 +81,23 @@ GEM @@ -95,14 +81,23 @@ GEM
95 warden (~> 1.2.3) 81 warden (~> 1.2.3)
96 diff-lcs (1.2.4) 82 diff-lcs (1.2.4)
97 dotenv (0.9.0) 83 dotenv (0.9.0)
  84 + draper (1.3.0)
  85 + actionpack (>= 3.0)
  86 + activemodel (>= 3.0)
  87 + activesupport (>= 3.0)
  88 + request_store (~> 1.0.3)
98 email_spec (1.5.0) 89 email_spec (1.5.0)
99 launchy (~> 2.1) 90 launchy (~> 2.1)
100 mail (~> 2.2) 91 mail (~> 2.2)
  92 + errbit_github_plugin (0.1.0)
  93 + errbit_plugin
  94 + octokit
  95 + errbit_plugin (0.2.0)
101 erubis (2.7.0) 96 erubis (2.7.0)
102 execjs (2.0.2) 97 execjs (2.0.2)
103 fabrication (2.9.0) 98 fabrication (2.9.0)
104 - faraday (0.8.8)  
105 - multipart-post (~> 1.2.0) 99 + faraday (0.9.0)
  100 + multipart-post (>= 1.2, < 3)
106 flowdock (0.3.1) 101 flowdock (0.3.1)
107 httparty (~> 0.7) 102 httparty (~> 0.7)
108 multi_json 103 multi_json
@@ -169,7 +164,7 @@ GEM @@ -169,7 +164,7 @@ GEM
169 moped (1.5.1) 164 moped (1.5.1)
170 multi_json (1.10.0) 165 multi_json (1.10.0)
171 multi_xml (0.5.5) 166 multi_xml (0.5.5)
172 - multipart-post (1.2.0) 167 + multipart-post (2.0.0)
173 net-scp (1.1.2) 168 net-scp (1.1.2)
174 net-ssh (>= 2.6.5) 169 net-ssh (>= 2.6.5)
175 net-sftp (2.1.2) 170 net-sftp (2.1.2)
@@ -185,8 +180,8 @@ GEM @@ -185,8 +180,8 @@ GEM
185 jwt (~> 0.1.4) 180 jwt (~> 0.1.4)
186 multi_json (~> 1.0) 181 multi_json (~> 1.0)
187 rack (~> 1.2) 182 rack (~> 1.2)
188 - octokit (2.6.0)  
189 - sawyer (~> 0.5.1) 183 + octokit (3.3.1)
  184 + sawyer (~> 0.5.3)
190 omniauth (1.1.4) 185 omniauth (1.1.4)
191 hashie (>= 1.2, < 3) 186 hashie (>= 1.2, < 3)
192 rack 187 rack
@@ -246,6 +241,7 @@ GEM @@ -246,6 +241,7 @@ GEM
246 rdoc (3.12.2) 241 rdoc (3.12.2)
247 json (~> 1.4) 242 json (~> 1.4)
248 ref (1.0.5) 243 ref (1.0.5)
  244 + request_store (1.0.6)
249 rest-client (1.6.7) 245 rest-client (1.6.7)
250 mime-types (>= 1.16) 246 mime-types (>= 1.16)
251 ri_cal (0.8.8) 247 ri_cal (0.8.8)
@@ -268,7 +264,7 @@ GEM @@ -268,7 +264,7 @@ GEM
268 json 264 json
269 rest-client 265 rest-client
270 safe_yaml (0.9.7) 266 safe_yaml (0.9.7)
271 - sawyer (0.5.1) 267 + sawyer (0.5.5)
272 addressable (~> 2.3.5) 268 addressable (~> 2.3.5)
273 faraday (~> 0.8, < 0.10) 269 faraday (~> 0.8, < 0.10)
274 simplecov (0.7.1) 270 simplecov (0.7.1)
@@ -339,9 +335,10 @@ DEPENDENCIES @@ -339,9 +335,10 @@ DEPENDENCIES
339 database_cleaner 335 database_cleaner
340 decent_exposure 336 decent_exposure
341 devise 337 devise
  338 + draper
342 email_spec 339 email_spec
343 - errbit_github_plugin!  
344 - errbit_plugin! 340 + errbit_github_plugin
  341 + errbit_plugin
345 execjs 342 execjs
346 fabrication 343 fabrication
347 flowdock 344 flowdock
app/assets/stylesheets/issue_tracker_icons.css.erb
1 /* Issue Tracker inactive, select, create and goto icons */ 1 /* Issue Tracker inactive, select, create and goto icons */
2 -<% trackers = IssueTracker.subclasses.map{|t| t.label } << 'none' %>  
3 2
4 -<% trackers.each do |tracker| %>  
5 -div.issue_tracker.nested label.<%= tracker %> {  
6 - background: url(<%= asset_path "#{ tracker }_inactive.png" %>) no-repeat; 3 +<% ErrbitPlugin::Registry.issue_trackers.keys.each do |label| %>
  4 +div.issue_tracker.nested label.<%= label %> {
  5 + background: url(<%= asset_path "#{ label }_inactive.png" %>) no-repeat;
7 } 6 }
8 -div.issue_tracker.nested label.r_on.<%= tracker %> {  
9 - background: url(<%= asset_path "#{ tracker }_create.png" %>) no-repeat; 7 +div.issue_tracker.nested label.r_on.<%= label %> {
  8 + background: url(<%= asset_path "#{ label }_create.png" %>) no-repeat;
10 } 9 }
11 -#action-bar a.<%= tracker %>_create {  
12 - background: transparent url(<%= asset_path "#{ tracker }_create.png" %>) 6px 5px no-repeat; 10 +#action-bar a.<%= label %>_create {
  11 + background: transparent url(<%= asset_path "#{ label }_create.png" %>) 6px 5px no-repeat;
13 } 12 }
14 -#action-bar a.<%= tracker %>_goto {  
15 - background: transparent url(<%= asset_path "#{ tracker }_goto.png" %>) 6px 5px no-repeat; 13 +#action-bar a.<%= label %>_goto {
  14 + background: transparent url(<%= asset_path "#{ label }_goto.png" %>) 6px 5px no-repeat;
16 } 15 }
17 <% end %> 16 <% end %>
18 17
app/decorators/issue_tracker_decorator.rb
@@ -9,9 +9,8 @@ class IssueTrackerDecorator &lt; Draper::Decorator @@ -9,9 +9,8 @@ class IssueTrackerDecorator &lt; Draper::Decorator
9 delegate_all 9 delegate_all
10 10
11 def issue_trackers 11 def issue_trackers
12 - @issue_trackers ||= ErrbitPlugin::Register.issue_trackers  
13 - @issue_trackers.each do |key, it|  
14 - yield IssueTrackerDecorator.new(it.new(app, {}), key) 12 + ErrbitPlugin::Registry.issue_trackers.each do |key, object|
  13 + yield IssueTrackerDecorator.new(object, key)
15 end 14 end
16 end 15 end
17 16
@@ -26,12 +25,12 @@ class IssueTrackerDecorator &lt; Draper::Decorator @@ -26,12 +25,12 @@ class IssueTrackerDecorator &lt; Draper::Decorator
26 end 25 end
27 26
28 def params_class(tracker) 27 def params_class(tracker)
29 - [choosen?(tracker), label].join(" ").strip 28 + [chosen?(tracker), label].join(" ").strip
30 end 29 end
31 30
32 private 31 private
33 32
34 - def choosen?(issue_tracker) 33 + def chosen?(issue_tracker)
35 key == issue_tracker.type_tracker.to_s ? 'chosen' : '' 34 key == issue_tracker.type_tracker.to_s ? 'chosen' : ''
36 end 35 end
37 36
app/models/app.rb
@@ -44,7 +44,7 @@ class App @@ -44,7 +44,7 @@ class App
44 accepts_nested_attributes_for :watchers, :allow_destroy => true, 44 accepts_nested_attributes_for :watchers, :allow_destroy => true,
45 :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? } 45 :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? }
46 accepts_nested_attributes_for :issue_tracker, :allow_destroy => true, 46 accepts_nested_attributes_for :issue_tracker, :allow_destroy => true,
47 - :reject_if => proc { |attrs| !ErrbitPlugin::Register.issue_trackers.keys.map(&:to_s).include?(attrs[:type_tracker].to_s) } 47 + :reject_if => proc { |attrs| !ErrbitPlugin::Registry.issue_trackers.keys.map(&:to_s).include?(attrs[:type_tracker].to_s) }
48 accepts_nested_attributes_for :notification_service, :allow_destroy => true, 48 accepts_nested_attributes_for :notification_service, :allow_destroy => true,
49 :reject_if => proc { |attrs| !NotificationService.subclasses.map(&:to_s).include?(attrs[:type].to_s) } 49 :reject_if => proc { |attrs| !NotificationService.subclasses.map(&:to_s).include?(attrs[:type].to_s) }
50 50
app/models/issue_tracker.rb
@@ -12,6 +12,8 @@ class IssueTracker @@ -12,6 +12,8 @@ class IssueTracker
12 field :type_tracker, :type => String 12 field :type_tracker, :type => String
13 field :options, :type => Hash, :default => {} 13 field :options, :type => Hash, :default => {}
14 14
  15 + validate :validate_tracker
  16 +
15 ## 17 ##
16 # Update default_url_option with valid data from the request information 18 # Update default_url_option with valid data from the request information
17 # 19 #
@@ -24,13 +26,21 @@ class IssueTracker @@ -24,13 +26,21 @@ class IssueTracker
24 end 26 end
25 27
26 def tracker 28 def tracker
27 - @tracker ||= ErrbitPlugin::Register.issue_tracker(self.type_tracker).new(app, self.options)  
28 - rescue NameError  
29 - ErrbitPlugin::NoneIssueTracker.new(app, {}) 29 + klass = ErrbitPlugin::Registry.issue_trackers[self.type_tracker]
  30 + klass = ErrbitPlugin::NoneIssueTracker unless klass
  31 +
  32 + @tracker = klass.new(app, self.options)
30 end 33 end
  34 +
  35 + # Allow the tracker to validate its own params
  36 + def validate_tracker
  37 + (tracker.errors || {}).each do |k,v|
  38 + errors.add k, v
  39 + end
  40 + end
  41 +
31 delegate :configured?, :to => :tracker 42 delegate :configured?, :to => :tracker
32 delegate :create_issue, :to => :tracker 43 delegate :create_issue, :to => :tracker
33 - delegate :label, :to => :tracker  
34 delegate :comments_allowed?, :to => :tracker 44 delegate :comments_allowed?, :to => :tracker
35 delegate :url, :to => :tracker 45 delegate :url, :to => :tracker
36 end 46 end
app/models/problem.rb
@@ -63,6 +63,13 @@ class Problem @@ -63,6 +63,13 @@ class Problem
63 env.present? ? where(:environment => env) : scoped 63 env.present? ? where(:environment => env) : scoped
64 end 64 end
65 65
  66 + def url
  67 + Rails.application.routes.url_helpers.app_problem_url(app, self,
  68 + :host => Errbit::Config.host,
  69 + :port => Errbit::Config.port
  70 + )
  71 + end
  72 +
66 def notices 73 def notices
67 Notice.for_errs(errs).ordered 74 Notice.for_errs(errs).ordered
68 end 75 end
@@ -149,7 +156,7 @@ class Problem @@ -149,7 +156,7 @@ class Problem
149 def issue_type 156 def issue_type
150 # Return issue_type if configured, but fall back to detecting app's issue tracker 157 # Return issue_type if configured, but fall back to detecting app's issue tracker
151 attributes['issue_type'] ||= 158 attributes['issue_type'] ||=
152 - (app.issue_tracker_configured? && app.issue_tracker.label) || nil 159 + (app.issue_tracker_configured? && app.issue_tracker.type_tracker) || nil
153 end 160 end
154 161
155 def self.search(value) 162 def self.search(value)
app/views/apps/index.html.haml
@@ -36,7 +36,7 @@ @@ -36,7 +36,7 @@
36 - if any_issue_trackers? 36 - if any_issue_trackers?
37 %td.issue_tracker 37 %td.issue_tracker
38 - if app.issue_tracker_configured? 38 - if app.issue_tracker_configured?
39 - - tracker_img = image_tag("#{app.issue_tracker.label}_goto.png") 39 + - tracker_img = image_tag("#{app.issue_tracker.type_tracker}_goto.png")
40 - if app.issue_tracker.url 40 - if app.issue_tracker.url
41 = link_to( tracker_img, app.issue_tracker.url ) 41 = link_to( tracker_img, app.issue_tracker.url )
42 - else 42 - else
app/views/problems/_issue_tracker_links.html.haml
@@ -6,10 +6,10 @@ @@ -6,10 +6,10 @@
6 %span.disabled= link_to 'creating...', '#', :class => "#{problem.issue_type}_inactive create-issue" 6 %span.disabled= link_to 'creating...', '#', :class => "#{problem.issue_type}_inactive create-issue"
7 = link_to 'retry', create_issue_app_problem_path(app, problem), :method => :post 7 = link_to 'retry', create_issue_app_problem_path(app, problem), :method => :post
8 - else 8 - else
9 - - if app.issue_tracker_configured? && !app.issue_tracker.label.eql?('github')  
10 - %span= link_to 'create issue', create_issue_app_problem_path(app, problem), :method => :post, :class => "#{app.issue_tracker.label}_create create-issue" 9 + - if app.issue_tracker_configured? && !app.issue_tracker.type_tracker.eql?('github')
  10 + %span= link_to 'create issue', create_issue_app_problem_path(app, problem), :method => :post, :class => "#{app.issue_tracker.type_tracker}_create create-issue"
11 - elsif app.github_repo? 11 - elsif app.github_repo?
12 - if current_user.can_create_github_issues? 12 - if current_user.can_create_github_issues?
13 %span= link_to 'create issue', create_issue_app_problem_path(app, problem, :tracker => 'user_github'), :method => :post, :class => "github_create create-issue" 13 %span= link_to 'create issue', create_issue_app_problem_path(app, problem, :tracker => 'user_github'), :method => :post, :class => "github_create create-issue"
14 - - elsif app.issue_tracker_configured? && app.issue_tracker.label.eql?('github') 14 + - elsif app.issue_tracker_configured? && app.issue_tracker.type_tracker.eql?('github')
15 %span= link_to 'create issue', create_issue_app_problem_path(app, problem), :method => :post, :class => "github_create create-issue" 15 %span= link_to 'create issue', create_issue_app_problem_path(app, problem), :method => :post, :class => "github_create create-issue"
spec/acceptance/app_regenerate_api_key_spec.rb
@@ -80,7 +80,7 @@ feature &quot;Create an application&quot; do @@ -80,7 +80,7 @@ feature &quot;Create an application&quot; do
80 click_on I18n.t('apps.new.add_app') 80 click_on I18n.t('apps.new.add_app')
81 expect(page.has_content?(I18n.t('controllers.apps.flash.create.success'))).to eql true 81 expect(page.has_content?(I18n.t('controllers.apps.flash.create.success'))).to eql true
82 app = App.where(:name => 'My new app').first 82 app = App.where(:name => 'My new app').first
83 - expect(app.issue_tracker.type_tracker).to eql 'IssueTrackers::GithubIssuesTracker' 83 + expect(app.issue_tracker.type_tracker).to eql 'github'
84 expect(app.issue_tracker.options['username']).to eql 'token' 84 expect(app.issue_tracker.options['username']).to eql 'token'
85 expect(app.issue_tracker.options['password']).to eql 'pass' 85 expect(app.issue_tracker.options['password']).to eql 'pass'
86 86
spec/controllers/apps_controller_spec.rb
@@ -309,7 +309,7 @@ describe AppsController do @@ -309,7 +309,7 @@ describe AppsController do
309 end 309 end
310 end 310 end
311 311
312 - ErrbitPlugin::Register.issue_trackers.each do |key, klass| 312 + ErrbitPlugin::Registry.issue_trackers.each do |key, klass|
313 context key do 313 context key do
314 it "should save tracker params" do 314 it "should save tracker params" do
315 issue_tracker_klass = klass.new(@app, {}) 315 issue_tracker_klass = klass.new(@app, {})
@@ -322,7 +322,7 @@ describe AppsController do @@ -322,7 +322,7 @@ describe AppsController do
322 @app.reload 322 @app.reload
323 323
324 tracker = @app.issue_tracker 324 tracker = @app.issue_tracker
325 - expect(tracker.tracker).to be_a(ErrbitPlugin::Register.issue_tracker(key)) 325 + expect(tracker.tracker).to be_a(ErrbitPlugin::Registry.issue_tracker(key))
326 issue_tracker_klass.fields.each do |field, field_info| 326 issue_tracker_klass.fields.each do |field, field_info|
327 case field 327 case field
328 when :ticket_properties; tracker.send(field.to_sym).should == 'card_type = defect' 328 when :ticket_properties; tracker.send(field.to_sym).should == 'card_type = defect'
spec/interactors/issue_creation_spec.rb
@@ -31,7 +31,7 @@ describe IssueCreation do @@ -31,7 +31,7 @@ describe IssueCreation do
31 it 'creates an issue if issue tracker is configured' do 31 it 'creates an issue if issue tracker is configured' do
32 a = problem.app 32 a = problem.app
33 a.build_issue_tracker 33 a.build_issue_tracker
34 - expect(ErrbitPlugin::Register).to receive(:issue_tracker).and_return(FakeIssueTracker) 34 + expect(ErrbitPlugin::Registry).to receive(:issue_tracker).and_return(FakeIssueTracker)
35 issue_creation.execute 35 issue_creation.execute
36 expect(errors).to be_empty 36 expect(errors).to be_empty
37 end 37 end
spec/views/problems/show.html.haml_spec.rb
@@ -31,7 +31,7 @@ describe &quot;problems/show.html.haml&quot; do @@ -31,7 +31,7 @@ describe &quot;problems/show.html.haml&quot; do
31 31
32 def with_issue_tracker(tracker, problem) 32 def with_issue_tracker(tracker, problem)
33 problem.app.issue_tracker = IssueTracker.new :type_tracker => tracker, :options => {:api_token => "token token token", :project_id => "1234"} 33 problem.app.issue_tracker = IssueTracker.new :type_tracker => tracker, :options => {:api_token => "token token token", :project_id => "1234"}
34 - ErrbitPlugin::Register.stub(:issue_tracker).with(tracker).and_return(tracker.constantize) 34 + ErrbitPlugin::Registry.stub(:issue_tracker).with(tracker).and_return(tracker.constantize)
35 view.stub(:problem).and_return(problem) 35 view.stub(:problem).and_return(problem)
36 view.stub(:app).and_return(problem.app) 36 view.stub(:app).and_return(problem.app)
37 end 37 end