Skip to content

Commit

Permalink
Merge pull request #23 from tricknotes/support-account-info-changed
Browse files Browse the repository at this point in the history
Add task to update user info
  • Loading branch information
tricknotes committed Dec 29, 2012
2 parents 88bd051 + e907bb4 commit c423121
Showing 1 changed file with 30 additions and 0 deletions.
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

0 comments on commit c423121

Please sign in to comment.