rosa-build/lib/tasks/fix_orphan_pulls.rake

27 lines
1.1 KiB
Ruby
Raw Normal View History

2012-10-27 19:04:28 +01:00
namespace :project do
desc 'Fix pull requests where was delete the "from project"'
task :fix_orphan_pulls => :environment do
projects = Project.where('ancestry IS NOT NULL')
say "Pull requests total count is #{PullRequest.count}"
PullRequest.all.each_with_index do |pull, ind|
say "Check pull with id:#{pull.id} (#{ind+1}/#{PullRequest.count})"
if pull.from_project.present?
print ' updating...'
pull.from_project_name = pull.from_project.name
pull.from_project_owner_uname = pull.from_project.owner.uname
say pull.save(:validate => false) ? 'success' : 'fail!'
else
2012-10-27 19:04:28 +01:00
print ' its orphan! updating...'
2012-11-09 15:01:22 +00:00
parent_path = File.join(APP_CONFIG['git_path'], 'pull_requests', pull.to_project.owner.uname, pull.to_project.name)
2012-10-27 19:04:28 +01:00
Dir.chdir(parent_path) do
# Get an owner and project name from the pull dir
elements = Dir["#{pull.id}-*"].first.split '-' rescue []
pull.from_project_owner_uname, pull.from_project_name = elements[1], elements[2]
say pull.save(:validate => false) ? 'success' : 'fail!'
end
end
end
end
end