Permalink
Browse files

Add support scripts

  • Loading branch information...
qrush committed Aug 15, 2012
1 parent 5e248dd commit 2cfa9d96d246f1a073001e07e4e0e47130b4e901
Showing with 111 additions and 0 deletions.
  1. +16 −0 script/add_owner
  2. +16 −0 script/change_email
  3. +52 −0 script/merge_users
  4. +27 −0 script/permadelete
View
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+
+name, email = *ARGV
+
+if name.nil? || email.nil?
+ abort "Usage: script/add_owner [GEM_NAME] [USER_EMAIL]"
+end
+
+ENV['RAILS_ENV'] ||= 'production'
+require_relative '../config/environment'
+
+user = User.find_by_email!(email)
+rubygem = Rubygem.find_by_name!(name)
+rubygem.ownerships.create(:user_id => user.id)
+
+puts "#{email} added to #{name}."
View
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+
+from_email, to_email = *ARGV
+
+if from_email.nil? || to_email.nil?
+ abort "Usage: script/change_email [FROM_EMAIL] [TO_EMAIL]"
+end
+
+ENV['RAILS_ENV'] ||= 'production'
+require_relative '../config/environment'
+
+from_user = User.find_by_email!(from_email)
+from_user.email = to_email
+from_user.save!
+
+puts "#{from_user.name}'s email is now: #{to_email}"
View
@@ -0,0 +1,52 @@
+#!/usr/bin/env ruby
+
+first, second = *ARGV
+
+if first.nil? || second.nil?
+ abort "Usage: script/merge_users [FIRST_EMAIL] [SECOND_EMAIL]"
+end
+
+ENV['RAILS_ENV'] ||= 'production'
+require_relative '../config/environment'
+
+first_user = User.find_by_email!(first)
+second_user = User.find_by_email!(second)
+
+require 'highline'
+terminal = HighLine.new
+
+puts "Which email do you want to keep?"
+email = terminal.choose do |menu|
+ menu.choice first_user.email
+ menu.choice second_user.email
+end
+
+puts "Which handle do you want to keep?"
+handle = terminal.choose do |menu|
+ menu.choice first_user.handle
+ menu.choice second_user.handle
+end
+
+if email == first_user.email
+ chosen_user = first_user
+ other_user = second_user
+else
+ chosen_user = second_user
+ other_user = first_user
+end
+
+puts "Merging #{chosen_user.email}/#{handle}..."
+
+(other_user.rubygems - chosen_user.rubygems).each do |rubygem|
+ puts "Merging ownership for #{rubygem.name}..."
+ ownership = rubygem.ownerships.find_by_user_id(other_user.id)
+ ownership.user = chosen_user
+ ownership.save!
+end
+
+other_user.destroy
+
+chosen_user.handle = handle
+chosen_user.save!
+
+puts "Done!"
View
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+unless name = ARGV.first
+ abort "Usage: script/permadelete [GEM_NAME]"
+end
+
+ENV['RAILS_ENV'] ||= 'production'
+require_relative '../config/environment'
+
+index = Indexer.new
+rubygem = Rubygem.find_by_name!(name)
+names = rubygem.versions.map(&:full_name)
+
+require 'highline'
+terminal = HighLine.new
+confirm = terminal.ask("Are you sure you want to permadelete #{name} with #{names.size} versions? (Y/N)")
+
+if confirm.upcase == "Y" || confirm.upcase == "YES"
+ names.map { |n| index.directory.files.get("gems/#{n}.gem") }.each(&:destroy)
+ names.map { |n| index.directory.files.get("quick/Marshal.4.8/#{n}.gemspec.rz") }.each(&:destroy)
+
+ rubygem.destroy
+
+ puts "#{name} permadeleted."
+else
+ abort "No problem! #{name} lives on."
+end

0 comments on commit 2cfa9d9

Please sign in to comment.