2012-10-27 19:04:28 +01:00
|
|
|
namespace :project do
|
|
|
|
desc 'Fix pull requests where was delete the "from project"'
|
2014-01-21 04:51:49 +00:00
|
|
|
task fix_orphan_pulls: :environment do
|
2012-10-27 19:04:28 +01:00
|
|
|
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})"
|
2012-11-12 14:59:46 +00:00
|
|
|
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
|
2014-01-21 04:51:49 +00:00
|
|
|
say pull.save(validate: false) ? 'success' : 'fail!'
|
2012-11-12 14:59:46 +00:00
|
|
|
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]
|
2014-01-21 04:51:49 +00:00
|
|
|
say pull.save(validate: false) ? 'success' : 'fail!'
|
2012-10-27 19:04:28 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|