diff --git a/Gemfile b/Gemfile index 57f3206..0b4feae 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'http://rubygems.org' gem 'rails', '3.0.5' gem 'nokogiri' -gem 'mongoid', '2.0.0.rc.8' +gem 'mongoid', '2.0.2' gem 'haml' gem 'will_paginate' gem 'devise', '~> 1.1.8' diff --git a/Gemfile.lock b/Gemfile.lock index 623603a..c57644b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ GEM addressable (2.2.5) arel (2.0.9) bcrypt-ruby (2.1.4) - bson (1.3.0) + bson (1.3.1) bson_ext (1.3.0) builder (2.1.2) crack (0.1.8) @@ -78,13 +78,12 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.16) - mongo (1.3.0) - bson (>= 1.3.0) - mongoid (2.0.0.rc.8) + mongo (1.3.1) + bson (>= 1.3.1) + mongoid (2.0.2) activemodel (~> 3.0) - mongo (~> 1.2) + mongo (~> 1.3) tzinfo (~> 0.3.22) - will_paginate (~> 3.0.pre) mongoid_rails_migrations (0.0.10) activesupport (~> 3.0.0) bundler (>= 0.9.19) @@ -161,7 +160,7 @@ DEPENDENCIES factory_girl_rails haml lighthouse-api - mongoid (= 2.0.0.rc.8) + mongoid (= 2.0.2) mongoid_rails_migrations nokogiri pivotal-tracker diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a831f1f..158eb23 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -42,4 +42,8 @@ module ApplicationHelper def pivotal_tracker? object object.issue_tracker_type == "pivotal" end + + def fogbugz_tracker? object + object.issue_tracker_type == 'fogbugz' + end end diff --git a/app/models/app.rb b/app/models/app.rb index ef9058d..ad4d5ba 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -21,7 +21,7 @@ class App embeds_many :watchers embeds_many :deploys embeds_one :issue_tracker - references_many :errs, :dependent => :destroy + has_many :errs, :dependent => :destroy before_validation :generate_api_key, :on => :create before_save :normalize_github_url @@ -35,7 +35,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| !%w(lighthouseapp redmine pivotal).include?(attrs[:issue_tracker_type]) } + :reject_if => proc { |attrs| !%w(lighthouseapp redmine pivotal fogbugz).include?(attrs[:issue_tracker_type]) } # Mongoid Bug: find(id) on association proxies returns an Enumerator def self.find_by_id!(app_id) diff --git a/app/models/err.rb b/app/models/err.rb index 4652588..a4b3857 100644 --- a/app/models/err.rb +++ b/app/models/err.rb @@ -16,8 +16,8 @@ class Err index :last_notice_at index :app_id - referenced_in :app - references_many :notices + belongs_to :app, inverse_of: :errs + has_many :notices validates_presence_of :klass, :environment diff --git a/app/models/issue_tracker.rb b/app/models/issue_tracker.rb index 2b0f6ab..7344d49 100644 --- a/app/models/issue_tracker.rb +++ b/app/models/issue_tracker.rb @@ -12,6 +12,8 @@ class IssueTracker field :account, :type => String field :api_token, :type => String field :project_id, :type => String + field :username, :type => String + field :password, :type => String field :issue_tracker_type, :type => String, :default => 'lighthouseapp' def create_issue err @@ -68,18 +70,20 @@ class IssueTracker end def create_fogbugz_issue err - fogbugz = Fogbugz::Interface.new(:email => email, :password => password, :uri => uri) - fogbugz.account = account - fogbugz.token = api_token + fogbugz = Fogbugz::Interface.new(:email => username, :password => password, :uri => "https://#{account}.fogbugz.com") + fogbugz.authenticate issue = {} issue['sTitle'] = issue_title err - issue['sProject'] = project_id + issue['sArea'] = project_id + puts err.app.inspect + puts app_err_url(err.app, err) issue['sEvent'] = self.class.fogbugz_body_template.result(binding) - issue['sTags'] << 'errbit' + issue['sTags'] = ['errbit'].join(',') + issue['cols'] = ['ixBug'].join(',') - fogbugz.command( - # err.update_attribute :issue_link, "#{FogBugz::Issue.site.to_s.sub(/#{FogBugz::Issue.site.path}$/, '')}#{FogBugz::Issue.element_path(issue.id, :project => project_id}".sub(/\.xml$/, '') + # fb_resp = fogbugz.command(:new, issue) + # err.update_attribute :issue_link, "https://#{account}.fogbugz.com/default.asp?#{fb_resp['case']['ixBug']}" end def issue_title err @@ -87,19 +91,24 @@ class IssueTracker end def check_params - blank_flag_fields = %w(api_token project_id) - blank_flag_fields << 'account' if %w(lighthouseapp redmine).include? issue_tracker_type + blank_flag_fields = %w(project_id) + if(%w(fogbugz).include?(issue_tracker_type)) + blank_flag_fields += %w(username password) + else + blank_flag_fields << 'api_token' + end + blank_flag_fields << 'account' if(%w(fogbugz lighthouseapp redmine).include?(issue_tracker_type)) blank_flags = blank_flag_fields.map {|m| self[m].blank? } if blank_flags.any? && !blank_flags.all? message = case issue_tracker_type when 'lighthouseapp' - "You must specify your Lighthouseapp account, api token and project id" + 'You must specify your Lighthouseapp account, api token and project id' when 'redmine' - "You must specify your Redmine url, api token and project id" + 'You must specify your Redmine url, api token and project id' when 'pivotal' - "You must specify your Pivotal Tracker api token and project id" + 'You must specify your Pivotal Tracker api token and project id' when 'fogbugz' - "You must specify your FogBugz account, project id, username, and password" + 'You must specify your FogBugz Area Name, Username, and Password' end errors.add(:base, message) end diff --git a/app/models/notice.rb b/app/models/notice.rb index dd9d03d..dfe449f 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -11,7 +11,7 @@ class Notice field :request, :type => Hash field :notifier, :type => Hash - referenced_in :err + belongs_to :err index :err_id after_create :cache_last_notice_at diff --git a/app/views/apps/_fields.html.haml b/app/views/apps/_fields.html.haml index ef5601c..ace5ea3 100644 --- a/app/views/apps/_fields.html.haml +++ b/app/views/apps/_fields.html.haml @@ -45,13 +45,15 @@ = label_tag :issue_tracker_type_redmine, 'Redmine', :for => label_for_attr(w, 'issue_tracker_type_redmine') = w.radio_button :issue_tracker_type, :pivotal = label_tag :issue_tracker_type_pivotal, 'Pivotal Tracker', :for => label_for_attr(w, 'issue_tracker_type_pivotal') + = w.radio_button :issue_tracker_type, :fogbugz + = label_tag :issue_tracker_type_fogbugz, 'FogBugz', :for => label_for_attr(w, 'issue_tracker_type_fogbugz') %div.tracker_params.lighthouseapp{:class => lighthouse_tracker?(w.object) ? 'chosen' : nil} = w.label :account, "Account" = w.text_field :account, :placeholder => "abc from abc.lighthouseapp.com" = w.label :api_token, "API token" = w.text_field :api_token, :placeholder => "API Token for your account" = w.label :project_id, "Project ID" - = w.text_field :project_id, :placeholder => "123 from abc from abc.lighthouseapp.com/projects/123" + = w.text_field :project_id, :placeholder => "123 from abc.lighthouseapp.com/projects/123" %div.tracker_params.redmine{:class => redmine_tracker?(w.object) ? 'chosen' : nil} = w.label :account, "Redmine URL" = w.text_field :account, :placeholder => "like http://www.redmine.org/" @@ -64,3 +66,12 @@ = w.text_field :project_id = w.label :api_token, "API token" = w.text_field :api_token, :placeholder => "API Token for your account" + %div.tracker_params.fogbugz{:class => fogbugz_tracker?(w.object) ? 'chosen' : nil} + = w.label :project_id, "Area Name" + = w.text_field :project_id + = w.label :account, "FogBugz URL" + = w.text_field :account, :placeholder => "abc from http://abc.fogbugz.com/" + = w.label :username, 'account username' + = w.text_field :username, :placeholder => 'Username/Email for your account' + = w.label :password, 'account password' + = w.password_field :password, :placeholder => 'Password for your account' diff --git a/app/views/errs/fogbugz_body.txt.erb b/app/views/errs/fogbugz_body.txt.erb new file mode 100644 index 0000000..38f0546 --- /dev/null +++ b/app/views/errs/fogbugz_body.txt.erb @@ -0,0 +1,31 @@ +"See this exception on Errbit": <%= app_err_url(err.app, err) %> +<% if notice = err.notices.first %> + <%= notice.message %> + + Summary + - Where + <%= notice.err.where %> + + - Occured + <%= notice.created_at.to_s(:micro) %> + + - Similar + <%= (notice.err.notices_count - 1).to_s %> + + Params + <%= pretty_hash(notice.params) %> + + Session + <%= pretty_hash(notice.session) %> + + Backtrace + <% for line in notice.backtrace %> + <%= line['number'] %>: <%= line['file'].sub(/^\[PROJECT_ROOT\]/, '') %> + <% end %> + + Environment + <% for key, val in notice.env_vars %> + <%= key %>: <%= val %> + <% end %> +<% end %> + diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 35239bd..7daa481 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -507,7 +507,7 @@ a.button.active { } /* Watchers and Issue Tracker Forms */ -div.nested.watcher .user, div.nested.watcher .email, div.issue_tracker.nested .lighthouseapp, div.issue_tracker.nested .redmine, div.issue_tracker.nested .pivotal { +div.nested.watcher .user, div.nested.watcher .email, div.issue_tracker.nested .lighthouseapp, div.issue_tracker.nested .redmine, div.issue_tracker.nested .pivotal, div.issue_tracker.nested .fogbugz { display: none; } div.nested.watcher .choosen, div.nested.issue_tracker .chosen { diff --git a/spec/controllers/apps_controller_spec.rb b/spec/controllers/apps_controller_spec.rb index 568a0a1..9b60a68 100644 --- a/spec/controllers/apps_controller_spec.rb +++ b/spec/controllers/apps_controller_spec.rb @@ -261,6 +261,33 @@ describe AppsController do response.body.should match(/You must specify your Pivotal Tracker api token and project id/) end end + + context "fogbugz" do + context 'with correct params' do + before do + put :update, :id => @app.id, :app => { :issue_tracker_attributes => { + :issue_tracker_type => 'fogbugz', :project_id => 'Service - Peon', :username => '1234', :password => '123123' } } + @app.reload + end + + subject {@app.issue_tracker} + its(:issue_tracker_type) {should == 'fogbugz'} + its(:project_id) {should == 'Service - Peon'} + its(:username) {should == '1234'} + its(:password) {should == '123123'} + end + + context 'insufficient params' do + it 'shows validation notice' do + put :update, :id => @app.id, :app => { :issue_tracker_attributes => { + :issue_tracker_type => 'fogbugz', :project_id => '1234' } } + @app.reload + + @app.issue_tracker.should be_nil + response.body.should match(/You must specify your FogBugz Area Name, Username, and Password/) + end + end + end end end -- libgit2 0.21.2