From 3dc67f13a8c2b4bbc5ed09afd3b384b612caa0e6 Mon Sep 17 00:00:00 2001 From: Stephen Crosby Date: Sat, 30 Aug 2014 19:45:14 -0700 Subject: [PATCH] update to errbit_plugin v0.2.0 --- Gemfile | 9 +++------ Gemfile.lock | 43 ++++++++++++++++++++----------------------- app/assets/stylesheets/issue_tracker_icons.css.erb | 19 +++++++++---------- app/decorators/issue_tracker_decorator.rb | 9 ++++----- app/models/app.rb | 2 +- app/models/issue_tracker.rb | 18 ++++++++++++++---- app/models/problem.rb | 9 ++++++++- app/views/apps/index.html.haml | 2 +- app/views/problems/_issue_tracker_links.html.haml | 6 +++--- spec/acceptance/app_regenerate_api_key_spec.rb | 2 +- spec/controllers/apps_controller_spec.rb | 4 ++-- spec/interactors/issue_creation_spec.rb | 2 +- spec/views/problems/show.html.haml_spec.rb | 2 +- 13 files changed, 68 insertions(+), 59 deletions(-) diff --git a/Gemfile b/Gemfile index 07d1a5d..754b76d 100644 --- a/Gemfile +++ b/Gemfile @@ -25,13 +25,10 @@ gem 'rails_autolink' # Please don't update hoptoad_notifier to airbrake. # It's for internal use only, and we monkeypatch certain methods gem 'hoptoad_notifier', "~> 2.4" +gem 'draper', :require => false -gem 'errbit_plugin', - :git => 'https://github.com/errbit/errbit_plugin.git' - # :path => 'vendor/gems/errbit_plugin' -gem 'errbit_github_plugin', - :git => 'https://github.com/errbit/errbit_github_plugin.git' - # :path => 'vendor/gems/errbit_github_plugin' +gem 'errbit_plugin' +gem 'errbit_github_plugin' # Notification services # --------------------------------------- diff --git a/Gemfile.lock b/Gemfile.lock index 115b717..2fa04a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,17 +1,3 @@ -GIT - remote: https://github.com/errbit/errbit_github_plugin.git - revision: c0f3b366110b4c5e61b06a0acbdb3e19aa2b0379 - specs: - errbit_github_plugin (0.0.1) - errbit_plugin - octokit - -GIT - remote: https://github.com/errbit/errbit_plugin.git - revision: 1bac2fb6800b0ad24233093fc6891d34bb20e2eb - specs: - errbit_plugin (0.0.1) - GEM remote: https://rubygems.org/ specs: @@ -46,7 +32,7 @@ GEM activesupport (3.2.18) i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) - addressable (2.3.5) + addressable (2.3.6) airbrake (3.1.14) builder json @@ -95,14 +81,23 @@ GEM warden (~> 1.2.3) diff-lcs (1.2.4) dotenv (0.9.0) + draper (1.3.0) + actionpack (>= 3.0) + activemodel (>= 3.0) + activesupport (>= 3.0) + request_store (~> 1.0.3) email_spec (1.5.0) launchy (~> 2.1) mail (~> 2.2) + errbit_github_plugin (0.1.0) + errbit_plugin + octokit + errbit_plugin (0.2.0) erubis (2.7.0) execjs (2.0.2) fabrication (2.9.0) - faraday (0.8.8) - multipart-post (~> 1.2.0) + faraday (0.9.0) + multipart-post (>= 1.2, < 3) flowdock (0.3.1) httparty (~> 0.7) multi_json @@ -169,7 +164,7 @@ GEM moped (1.5.1) multi_json (1.10.0) multi_xml (0.5.5) - multipart-post (1.2.0) + multipart-post (2.0.0) net-scp (1.1.2) net-ssh (>= 2.6.5) net-sftp (2.1.2) @@ -185,8 +180,8 @@ GEM jwt (~> 0.1.4) multi_json (~> 1.0) rack (~> 1.2) - octokit (2.6.0) - sawyer (~> 0.5.1) + octokit (3.3.1) + sawyer (~> 0.5.3) omniauth (1.1.4) hashie (>= 1.2, < 3) rack @@ -246,6 +241,7 @@ GEM rdoc (3.12.2) json (~> 1.4) ref (1.0.5) + request_store (1.0.6) rest-client (1.6.7) mime-types (>= 1.16) ri_cal (0.8.8) @@ -268,7 +264,7 @@ GEM json rest-client safe_yaml (0.9.7) - sawyer (0.5.1) + sawyer (0.5.5) addressable (~> 2.3.5) faraday (~> 0.8, < 0.10) simplecov (0.7.1) @@ -339,9 +335,10 @@ DEPENDENCIES database_cleaner decent_exposure devise + draper email_spec - errbit_github_plugin! - errbit_plugin! + errbit_github_plugin + errbit_plugin execjs fabrication flowdock diff --git a/app/assets/stylesheets/issue_tracker_icons.css.erb b/app/assets/stylesheets/issue_tracker_icons.css.erb index 81eb7bb..15148e6 100644 --- a/app/assets/stylesheets/issue_tracker_icons.css.erb +++ b/app/assets/stylesheets/issue_tracker_icons.css.erb @@ -1,18 +1,17 @@ /* Issue Tracker inactive, select, create and goto icons */ -<% trackers = IssueTracker.subclasses.map{|t| t.label } << 'none' %> -<% trackers.each do |tracker| %> -div.issue_tracker.nested label.<%= tracker %> { - background: url(<%= asset_path "#{ tracker }_inactive.png" %>) no-repeat; +<% ErrbitPlugin::Registry.issue_trackers.keys.each do |label| %> +div.issue_tracker.nested label.<%= label %> { + background: url(<%= asset_path "#{ label }_inactive.png" %>) no-repeat; } -div.issue_tracker.nested label.r_on.<%= tracker %> { - background: url(<%= asset_path "#{ tracker }_create.png" %>) no-repeat; +div.issue_tracker.nested label.r_on.<%= label %> { + background: url(<%= asset_path "#{ label }_create.png" %>) no-repeat; } -#action-bar a.<%= tracker %>_create { - background: transparent url(<%= asset_path "#{ tracker }_create.png" %>) 6px 5px no-repeat; +#action-bar a.<%= label %>_create { + background: transparent url(<%= asset_path "#{ label }_create.png" %>) 6px 5px no-repeat; } -#action-bar a.<%= tracker %>_goto { - background: transparent url(<%= asset_path "#{ tracker }_goto.png" %>) 6px 5px no-repeat; +#action-bar a.<%= label %>_goto { + background: transparent url(<%= asset_path "#{ label }_goto.png" %>) 6px 5px no-repeat; } <% end %> diff --git a/app/decorators/issue_tracker_decorator.rb b/app/decorators/issue_tracker_decorator.rb index 82774ec..c7ab0e4 100644 --- a/app/decorators/issue_tracker_decorator.rb +++ b/app/decorators/issue_tracker_decorator.rb @@ -9,9 +9,8 @@ class IssueTrackerDecorator < Draper::Decorator delegate_all def issue_trackers - @issue_trackers ||= ErrbitPlugin::Register.issue_trackers - @issue_trackers.each do |key, it| - yield IssueTrackerDecorator.new(it.new(app, {}), key) + ErrbitPlugin::Registry.issue_trackers.each do |key, object| + yield IssueTrackerDecorator.new(object, key) end end @@ -26,12 +25,12 @@ class IssueTrackerDecorator < Draper::Decorator end def params_class(tracker) - [choosen?(tracker), label].join(" ").strip + [chosen?(tracker), label].join(" ").strip end private - def choosen?(issue_tracker) + def chosen?(issue_tracker) key == issue_tracker.type_tracker.to_s ? 'chosen' : '' end diff --git a/app/models/app.rb b/app/models/app.rb index 9c2bdfc..293e7ae 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -44,7 +44,7 @@ class App accepts_nested_attributes_for :watchers, :allow_destroy => true, :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? } accepts_nested_attributes_for :issue_tracker, :allow_destroy => true, - :reject_if => proc { |attrs| !ErrbitPlugin::Register.issue_trackers.keys.map(&:to_s).include?(attrs[:type_tracker].to_s) } + :reject_if => proc { |attrs| !ErrbitPlugin::Registry.issue_trackers.keys.map(&:to_s).include?(attrs[:type_tracker].to_s) } accepts_nested_attributes_for :notification_service, :allow_destroy => true, :reject_if => proc { |attrs| !NotificationService.subclasses.map(&:to_s).include?(attrs[:type].to_s) } diff --git a/app/models/issue_tracker.rb b/app/models/issue_tracker.rb index a1499fc..830e2f8 100644 --- a/app/models/issue_tracker.rb +++ b/app/models/issue_tracker.rb @@ -12,6 +12,8 @@ class IssueTracker field :type_tracker, :type => String field :options, :type => Hash, :default => {} + validate :validate_tracker + ## # Update default_url_option with valid data from the request information # @@ -24,13 +26,21 @@ class IssueTracker end def tracker - @tracker ||= ErrbitPlugin::Register.issue_tracker(self.type_tracker).new(app, self.options) - rescue NameError - ErrbitPlugin::NoneIssueTracker.new(app, {}) + klass = ErrbitPlugin::Registry.issue_trackers[self.type_tracker] + klass = ErrbitPlugin::NoneIssueTracker unless klass + + @tracker = klass.new(app, self.options) end + + # Allow the tracker to validate its own params + def validate_tracker + (tracker.errors || {}).each do |k,v| + errors.add k, v + end + end + delegate :configured?, :to => :tracker delegate :create_issue, :to => :tracker - delegate :label, :to => :tracker delegate :comments_allowed?, :to => :tracker delegate :url, :to => :tracker end diff --git a/app/models/problem.rb b/app/models/problem.rb index bc7a728..adf6f5e 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -63,6 +63,13 @@ class Problem env.present? ? where(:environment => env) : scoped end + def url + Rails.application.routes.url_helpers.app_problem_url(app, self, + :host => Errbit::Config.host, + :port => Errbit::Config.port + ) + end + def notices Notice.for_errs(errs).ordered end @@ -149,7 +156,7 @@ class Problem def issue_type # Return issue_type if configured, but fall back to detecting app's issue tracker attributes['issue_type'] ||= - (app.issue_tracker_configured? && app.issue_tracker.label) || nil + (app.issue_tracker_configured? && app.issue_tracker.type_tracker) || nil end def self.search(value) diff --git a/app/views/apps/index.html.haml b/app/views/apps/index.html.haml index 19f8064..0278076 100644 --- a/app/views/apps/index.html.haml +++ b/app/views/apps/index.html.haml @@ -36,7 +36,7 @@ - if any_issue_trackers? %td.issue_tracker - if app.issue_tracker_configured? - - tracker_img = image_tag("#{app.issue_tracker.label}_goto.png") + - tracker_img = image_tag("#{app.issue_tracker.type_tracker}_goto.png") - if app.issue_tracker.url = link_to( tracker_img, app.issue_tracker.url ) - else diff --git a/app/views/problems/_issue_tracker_links.html.haml b/app/views/problems/_issue_tracker_links.html.haml index dac3ae1..2df004a 100644 --- a/app/views/problems/_issue_tracker_links.html.haml +++ b/app/views/problems/_issue_tracker_links.html.haml @@ -6,10 +6,10 @@ %span.disabled= link_to 'creating...', '#', :class => "#{problem.issue_type}_inactive create-issue" = link_to 'retry', create_issue_app_problem_path(app, problem), :method => :post - else - - if app.issue_tracker_configured? && !app.issue_tracker.label.eql?('github') - %span= link_to 'create issue', create_issue_app_problem_path(app, problem), :method => :post, :class => "#{app.issue_tracker.label}_create create-issue" + - if app.issue_tracker_configured? && !app.issue_tracker.type_tracker.eql?('github') + %span= link_to 'create issue', create_issue_app_problem_path(app, problem), :method => :post, :class => "#{app.issue_tracker.type_tracker}_create create-issue" - elsif app.github_repo? - if current_user.can_create_github_issues? %span= link_to 'create issue', create_issue_app_problem_path(app, problem, :tracker => 'user_github'), :method => :post, :class => "github_create create-issue" - - elsif app.issue_tracker_configured? && app.issue_tracker.label.eql?('github') + - elsif app.issue_tracker_configured? && app.issue_tracker.type_tracker.eql?('github') %span= link_to 'create issue', create_issue_app_problem_path(app, problem), :method => :post, :class => "github_create create-issue" diff --git a/spec/acceptance/app_regenerate_api_key_spec.rb b/spec/acceptance/app_regenerate_api_key_spec.rb index 70f5c40..5dfc9b2 100644 --- a/spec/acceptance/app_regenerate_api_key_spec.rb +++ b/spec/acceptance/app_regenerate_api_key_spec.rb @@ -80,7 +80,7 @@ feature "Create an application" do click_on I18n.t('apps.new.add_app') expect(page.has_content?(I18n.t('controllers.apps.flash.create.success'))).to eql true app = App.where(:name => 'My new app').first - expect(app.issue_tracker.type_tracker).to eql 'IssueTrackers::GithubIssuesTracker' + expect(app.issue_tracker.type_tracker).to eql 'github' expect(app.issue_tracker.options['username']).to eql 'token' expect(app.issue_tracker.options['password']).to eql 'pass' diff --git a/spec/controllers/apps_controller_spec.rb b/spec/controllers/apps_controller_spec.rb index 6b7d8d8..27d7b62 100644 --- a/spec/controllers/apps_controller_spec.rb +++ b/spec/controllers/apps_controller_spec.rb @@ -309,7 +309,7 @@ describe AppsController do end end - ErrbitPlugin::Register.issue_trackers.each do |key, klass| + ErrbitPlugin::Registry.issue_trackers.each do |key, klass| context key do it "should save tracker params" do issue_tracker_klass = klass.new(@app, {}) @@ -322,7 +322,7 @@ describe AppsController do @app.reload tracker = @app.issue_tracker - expect(tracker.tracker).to be_a(ErrbitPlugin::Register.issue_tracker(key)) + expect(tracker.tracker).to be_a(ErrbitPlugin::Registry.issue_tracker(key)) issue_tracker_klass.fields.each do |field, field_info| case field when :ticket_properties; tracker.send(field.to_sym).should == 'card_type = defect' diff --git a/spec/interactors/issue_creation_spec.rb b/spec/interactors/issue_creation_spec.rb index 852d8d9..2f02630 100644 --- a/spec/interactors/issue_creation_spec.rb +++ b/spec/interactors/issue_creation_spec.rb @@ -31,7 +31,7 @@ describe IssueCreation do it 'creates an issue if issue tracker is configured' do a = problem.app a.build_issue_tracker - expect(ErrbitPlugin::Register).to receive(:issue_tracker).and_return(FakeIssueTracker) + expect(ErrbitPlugin::Registry).to receive(:issue_tracker).and_return(FakeIssueTracker) issue_creation.execute expect(errors).to be_empty end diff --git a/spec/views/problems/show.html.haml_spec.rb b/spec/views/problems/show.html.haml_spec.rb index b4cea86..bfb4d3b 100644 --- a/spec/views/problems/show.html.haml_spec.rb +++ b/spec/views/problems/show.html.haml_spec.rb @@ -31,7 +31,7 @@ describe "problems/show.html.haml" do def with_issue_tracker(tracker, problem) problem.app.issue_tracker = IssueTracker.new :type_tracker => tracker, :options => {:api_token => "token token token", :project_id => "1234"} - ErrbitPlugin::Register.stub(:issue_tracker).with(tracker).and_return(tracker.constantize) + ErrbitPlugin::Registry.stub(:issue_tracker).with(tracker).and_return(tracker.constantize) view.stub(:problem).and_return(problem) view.stub(:app).and_return(problem.app) end -- libgit2 0.21.2