diff --git a/Gemfile.lock b/Gemfile.lock index e741880..b9010c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -116,7 +116,7 @@ GEM errbit_lighthouse_plugin (0.1.0) errbit_plugin (~> 0) lighthouse-api (~> 2) - errbit_pivotal_plugin (0.1.0) + errbit_pivotal_plugin (0.2.0) errbit_plugin (~> 0.4, >= 0.4.0) pivotal-tracker (~> 0.5, >= 0.5.0) errbit_plugin (0.4.0) @@ -191,7 +191,7 @@ GEM railties method_source (0.8.2) mime-types (1.25.1) - mini_portile (0.6.0) + mini_portile (0.6.1) mongoid (3.1.5) activemodel (~> 3.2) moped (~> 1.4) @@ -217,8 +217,8 @@ GEM net-ssh (2.7.0) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) - nokogiri (1.6.3.1) - mini_portile (= 0.6.0) + nokogiri (1.6.4.1) + mini_portile (~> 0.6.0) nokogiri-happymapper (0.5.9) nokogiri (~> 1.5) oauth (0.4.7) diff --git a/db/migrate/20110812135951_move_issue_trackers_to_sti.rb b/db/migrate/20110812135951_move_issue_trackers_to_sti.rb index 26a5d4d..3c042b3 100644 --- a/db/migrate/20110812135951_move_issue_trackers_to_sti.rb +++ b/db/migrate/20110812135951_move_issue_trackers_to_sti.rb @@ -5,21 +5,27 @@ class MoveIssueTrackersToSti < Mongoid::Migration # All issue trackers now subclass the IssueTracker model, # and their class is stored in the '_type' field, which is # also aliased to 'type'. - if app.issue_tracker && app.issue_tracker.attributes["issue_tracker_type"] - app.issue_tracker._type = case app.issue_tracker.issue_tracker_type - when 'lighthouseapp'; "LighthouseTracker" - when 'redmine'; "RedmineTracker" - when 'pivotal'; "PivotalLabsTracker" - when 'fogbugz'; "FogbugzTracker" - when 'mingle'; "MingleTracker" + tracker = app.attributes['issue_tracker'] + if tracker && tracker['issue_tracker_type'] + tracker['_type'] = case tracker['issue_tracker_type'] + when 'lighthouseapp'; "IssueTrackers::LighthouseTracker" + when 'redmine'; "IssueTrackers::RedmineTracker" + when 'pivotal'; "IssueTrackers::PivotalLabsTracker" + when 'fogbugz'; "IssueTrackers::FogbugzTracker" + when 'mingle'; "IssueTrackers::MingleTracker" else; nil end - if app.issue_tracker.issue_tracker_type == "none" - app.issue_tracker = nil + + if tracker['issue_tracker_type'] == "none" + App.collection.where({ _id: app.id }).update({ + "$unset" => { :issue_tracker => 1 } + }) else - app.issue_tracker.issue_tracker_type = nil + tracker.delete('issue_tracker_type') + App.collection.where({ _id: app.id }).update({ + "$set" => { :issue_tracker => tracker } + }) end - app.save end end end diff --git a/db/migrate/20120603112130_change_github_url_to_github_repo.rb b/db/migrate/20120603112130_change_github_url_to_github_repo.rb index 1b28226..c2ce2a4 100644 --- a/db/migrate/20120603112130_change_github_url_to_github_repo.rb +++ b/db/migrate/20120603112130_change_github_url_to_github_repo.rb @@ -1,9 +1,21 @@ class ChangeGithubUrlToGithubRepo < Mongoid::Migration + def self.normalize_github_repo(repo) + return if repo.blank? + github_host = URI.parse(Errbit::Config.github_url).host + github_host = Regexp.escape(github_host) + repo.strip! + repo.sub!(/(git@|https?:\/\/)#{github_host}(\/|:)/, '') + repo.sub!(/\.git$/, '') + repo + end + def self.up App.collection.find.update({'$rename' => {'github_url' => 'github_repo'}}, :multi => true, :safe => true) App.all.each do |app| - app.send :normalize_github_repo - app.save + normalized_repo = self.normalize_github_repo(app.attributes['github_repo']) + App.collection.where({ _id: app.id }).update({ + "$set" => { :github_repo => normalized_repo } + }) end end diff --git a/db/migrate/20131011155638_extract_issue_tracker.rb b/db/migrate/20131011155638_extract_issue_tracker.rb index 71c4480..e5503b9 100644 --- a/db/migrate/20131011155638_extract_issue_tracker.rb +++ b/db/migrate/20131011155638_extract_issue_tracker.rb @@ -1,15 +1,44 @@ class ExtractIssueTracker < Mongoid::Migration + TRACKER_MAPPING = { + 'ErrbitTracPlugin::IssueTracker' => 'trac', + 'IssueTrackers::BitbucketIssuesTracker' => 'bitbucket', + 'IssueTrackers::FogbugzTracker' => 'fogbugz', + 'IssueTrackers::GithubIssuesTracker' => 'github', + 'IssueTrackers::GitlabTracker' => 'gitlab', + 'IssueTrackers::JiraTracker' => 'jira', + 'IssueTrackers::LighthouseTracker' => 'lighthouse', + 'IssueTrackers::PivotalLabsTracker' => 'pivotal', + 'IssueTrackers::RedmineTracker' => 'redmine', + 'IssueTrackers::UnfuddleTracker' => 'unfuddle' + } + def self.up - App.collection.find.each do |app| - if app['issue_tracker'] && !app['issue_tracker'].empty? - it = app['issue_tracker'] - it['type_tracker'] = app['issue_tracker']['_type'] - it['options'] = app['issue_tracker'].dup - it.delete('_type') - App.collection.find( - :_id => app['_id'] - ).update(app) + App.all.each do |app| + require 'pry' + binding.pry + next unless app.attributes['issue_tracker'].present? + next unless app.attributes['issue_tracker']['_type'].present? + + options = app['issue_tracker'].dup + options.delete('_type') + options.delete('_id') + + _type = app.attributes['issue_tracker']['_type'] + updated_at = options.delete('updated_at') + created_at = options.delete('created_at') + + if TRACKER_MAPPING.include?(_type) + tracker = { + 'type_tracker' => TRACKER_MAPPING[_type], + 'options' => options, + 'updated_at' => updated_at, + 'created_at' => created_at + } + + App.collection.where({ _id: app.id }).update({ + "$set" => { :issue_tracker => tracker } + }) end end end -- libgit2 0.21.2