-
-
Notifications
You must be signed in to change notification settings - Fork 916
/
merge_users
executable file
·52 lines (39 loc) · 1.12 KB
/
merge_users
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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!"