Commit 3dc67f13a8c2b4bbc5ed09afd3b384b612caa0e6
1 parent
76db1687
Exists in
master
and in
1 other branch
update to errbit_plugin v0.2.0
Showing
13 changed files
with
68 additions
and
59 deletions
Show diff stats
Gemfile
| ... | ... | @@ -25,13 +25,10 @@ gem 'rails_autolink' |
| 25 | 25 | # Please don't update hoptoad_notifier to airbrake. |
| 26 | 26 | # It's for internal use only, and we monkeypatch certain methods |
| 27 | 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 | 33 | # Notification services |
| 37 | 34 | # --------------------------------------- | ... | ... |
Gemfile.lock
| 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 | 1 | GEM |
| 16 | 2 | remote: https://rubygems.org/ |
| 17 | 3 | specs: |
| ... | ... | @@ -46,7 +32,7 @@ GEM |
| 46 | 32 | activesupport (3.2.18) |
| 47 | 33 | i18n (~> 0.6, >= 0.6.4) |
| 48 | 34 | multi_json (~> 1.0) |
| 49 | - addressable (2.3.5) | |
| 35 | + addressable (2.3.6) | |
| 50 | 36 | airbrake (3.1.14) |
| 51 | 37 | builder |
| 52 | 38 | json |
| ... | ... | @@ -95,14 +81,23 @@ GEM |
| 95 | 81 | warden (~> 1.2.3) |
| 96 | 82 | diff-lcs (1.2.4) |
| 97 | 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 | 89 | email_spec (1.5.0) |
| 99 | 90 | launchy (~> 2.1) |
| 100 | 91 | mail (~> 2.2) |
| 92 | + errbit_github_plugin (0.1.0) | |
| 93 | + errbit_plugin | |
| 94 | + octokit | |
| 95 | + errbit_plugin (0.2.0) | |
| 101 | 96 | erubis (2.7.0) |
| 102 | 97 | execjs (2.0.2) |
| 103 | 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 | 101 | flowdock (0.3.1) |
| 107 | 102 | httparty (~> 0.7) |
| 108 | 103 | multi_json |
| ... | ... | @@ -169,7 +164,7 @@ GEM |
| 169 | 164 | moped (1.5.1) |
| 170 | 165 | multi_json (1.10.0) |
| 171 | 166 | multi_xml (0.5.5) |
| 172 | - multipart-post (1.2.0) | |
| 167 | + multipart-post (2.0.0) | |
| 173 | 168 | net-scp (1.1.2) |
| 174 | 169 | net-ssh (>= 2.6.5) |
| 175 | 170 | net-sftp (2.1.2) |
| ... | ... | @@ -185,8 +180,8 @@ GEM |
| 185 | 180 | jwt (~> 0.1.4) |
| 186 | 181 | multi_json (~> 1.0) |
| 187 | 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 | 185 | omniauth (1.1.4) |
| 191 | 186 | hashie (>= 1.2, < 3) |
| 192 | 187 | rack |
| ... | ... | @@ -246,6 +241,7 @@ GEM |
| 246 | 241 | rdoc (3.12.2) |
| 247 | 242 | json (~> 1.4) |
| 248 | 243 | ref (1.0.5) |
| 244 | + request_store (1.0.6) | |
| 249 | 245 | rest-client (1.6.7) |
| 250 | 246 | mime-types (>= 1.16) |
| 251 | 247 | ri_cal (0.8.8) |
| ... | ... | @@ -268,7 +264,7 @@ GEM |
| 268 | 264 | json |
| 269 | 265 | rest-client |
| 270 | 266 | safe_yaml (0.9.7) |
| 271 | - sawyer (0.5.1) | |
| 267 | + sawyer (0.5.5) | |
| 272 | 268 | addressable (~> 2.3.5) |
| 273 | 269 | faraday (~> 0.8, < 0.10) |
| 274 | 270 | simplecov (0.7.1) |
| ... | ... | @@ -339,9 +335,10 @@ DEPENDENCIES |
| 339 | 335 | database_cleaner |
| 340 | 336 | decent_exposure |
| 341 | 337 | devise |
| 338 | + draper | |
| 342 | 339 | email_spec |
| 343 | - errbit_github_plugin! | |
| 344 | - errbit_plugin! | |
| 340 | + errbit_github_plugin | |
| 341 | + errbit_plugin | |
| 345 | 342 | execjs |
| 346 | 343 | fabrication |
| 347 | 344 | flowdock | ... | ... |
app/assets/stylesheets/issue_tracker_icons.css.erb
| 1 | 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 | 16 | <% end %> |
| 18 | 17 | ... | ... |
app/decorators/issue_tracker_decorator.rb
| ... | ... | @@ -9,9 +9,8 @@ class IssueTrackerDecorator < Draper::Decorator |
| 9 | 9 | delegate_all |
| 10 | 10 | |
| 11 | 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 | 14 | end |
| 16 | 15 | end |
| 17 | 16 | |
| ... | ... | @@ -26,12 +25,12 @@ class IssueTrackerDecorator < Draper::Decorator |
| 26 | 25 | end |
| 27 | 26 | |
| 28 | 27 | def params_class(tracker) |
| 29 | - [choosen?(tracker), label].join(" ").strip | |
| 28 | + [chosen?(tracker), label].join(" ").strip | |
| 30 | 29 | end |
| 31 | 30 | |
| 32 | 31 | private |
| 33 | 32 | |
| 34 | - def choosen?(issue_tracker) | |
| 33 | + def chosen?(issue_tracker) | |
| 35 | 34 | key == issue_tracker.type_tracker.to_s ? 'chosen' : '' |
| 36 | 35 | end |
| 37 | 36 | ... | ... |
app/models/app.rb
| ... | ... | @@ -44,7 +44,7 @@ class App |
| 44 | 44 | accepts_nested_attributes_for :watchers, :allow_destroy => true, |
| 45 | 45 | :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? } |
| 46 | 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 | 48 | accepts_nested_attributes_for :notification_service, :allow_destroy => true, |
| 49 | 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 | 12 | field :type_tracker, :type => String |
| 13 | 13 | field :options, :type => Hash, :default => {} |
| 14 | 14 | |
| 15 | + validate :validate_tracker | |
| 16 | + | |
| 15 | 17 | ## |
| 16 | 18 | # Update default_url_option with valid data from the request information |
| 17 | 19 | # |
| ... | ... | @@ -24,13 +26,21 @@ class IssueTracker |
| 24 | 26 | end |
| 25 | 27 | |
| 26 | 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 | 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 | 42 | delegate :configured?, :to => :tracker |
| 32 | 43 | delegate :create_issue, :to => :tracker |
| 33 | - delegate :label, :to => :tracker | |
| 34 | 44 | delegate :comments_allowed?, :to => :tracker |
| 35 | 45 | delegate :url, :to => :tracker |
| 36 | 46 | end | ... | ... |
app/models/problem.rb
| ... | ... | @@ -63,6 +63,13 @@ class Problem |
| 63 | 63 | env.present? ? where(:environment => env) : scoped |
| 64 | 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 | 73 | def notices |
| 67 | 74 | Notice.for_errs(errs).ordered |
| 68 | 75 | end |
| ... | ... | @@ -149,7 +156,7 @@ class Problem |
| 149 | 156 | def issue_type |
| 150 | 157 | # Return issue_type if configured, but fall back to detecting app's issue tracker |
| 151 | 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 | 160 | end |
| 154 | 161 | |
| 155 | 162 | def self.search(value) | ... | ... |
app/views/apps/index.html.haml
| ... | ... | @@ -36,7 +36,7 @@ |
| 36 | 36 | - if any_issue_trackers? |
| 37 | 37 | %td.issue_tracker |
| 38 | 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 | 40 | - if app.issue_tracker.url |
| 41 | 41 | = link_to( tracker_img, app.issue_tracker.url ) |
| 42 | 42 | - else | ... | ... |
app/views/problems/_issue_tracker_links.html.haml
| ... | ... | @@ -6,10 +6,10 @@ |
| 6 | 6 | %span.disabled= link_to 'creating...', '#', :class => "#{problem.issue_type}_inactive create-issue" |
| 7 | 7 | = link_to 'retry', create_issue_app_problem_path(app, problem), :method => :post |
| 8 | 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 | 11 | - elsif app.github_repo? |
| 12 | 12 | - if current_user.can_create_github_issues? |
| 13 | 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 | 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 "Create an application" do |
| 80 | 80 | click_on I18n.t('apps.new.add_app') |
| 81 | 81 | expect(page.has_content?(I18n.t('controllers.apps.flash.create.success'))).to eql true |
| 82 | 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 | 84 | expect(app.issue_tracker.options['username']).to eql 'token' |
| 85 | 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 | 309 | end |
| 310 | 310 | end |
| 311 | 311 | |
| 312 | - ErrbitPlugin::Register.issue_trackers.each do |key, klass| | |
| 312 | + ErrbitPlugin::Registry.issue_trackers.each do |key, klass| | |
| 313 | 313 | context key do |
| 314 | 314 | it "should save tracker params" do |
| 315 | 315 | issue_tracker_klass = klass.new(@app, {}) |
| ... | ... | @@ -322,7 +322,7 @@ describe AppsController do |
| 322 | 322 | @app.reload |
| 323 | 323 | |
| 324 | 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 | 326 | issue_tracker_klass.fields.each do |field, field_info| |
| 327 | 327 | case field |
| 328 | 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 | 31 | it 'creates an issue if issue tracker is configured' do |
| 32 | 32 | a = problem.app |
| 33 | 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 | 35 | issue_creation.execute |
| 36 | 36 | expect(errors).to be_empty |
| 37 | 37 | end | ... | ... |
spec/views/problems/show.html.haml_spec.rb
| ... | ... | @@ -31,7 +31,7 @@ describe "problems/show.html.haml" do |
| 31 | 31 | |
| 32 | 32 | def with_issue_tracker(tracker, problem) |
| 33 | 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 | 35 | view.stub(:problem).and_return(problem) |
| 36 | 36 | view.stub(:app).and_return(problem.app) |
| 37 | 37 | end | ... | ... |