Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add task to update user info #23

Merged
merged 1 commit into from
Dec 29, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/tasks/update_account_info.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "#{Rails.root}/config/environment"

desc 'Update account info with github.com'
task :update_account_info do
User.all.each do |user|
puts "Fetch user info about \033[36m%s\033[39m..." % user.username
begin
user_info = user.github_client.user
rescue => e
# TODO Notify error to admin
$stderr.puts ["#{e.class} #{e.message}:", *e.backtrace.map {|m| ' '+m }].join("\n")
next
end

{
username: user_info['login'],
name: user_info['name'],
avatar_url: user_info['avatar_url']
}.each {|attribute, value| user.send("#{attribute}=", value) }

if user.changed?
change_detail = user.changes.map {|attribute, (before, after)| '%s: %s -> %s' % [attribute, before, after] }.join(', ')
puts "User \033[36m%s\033[39m changed (%s)." % [user.username, change_detail]
else
puts "User \033[36m%s\033[39m not changed." % [user.username]
end

user.save!
end
end