2012-02-23 15:17:02 +00:00
|
|
|
require 'highline/import'
|
2012-08-27 17:01:59 +01:00
|
|
|
require 'open-uri'
|
2012-02-23 15:17:02 +00:00
|
|
|
|
2012-08-27 17:01:59 +01:00
|
|
|
namespace :add_branch do
|
|
|
|
desc 'Fork project branch'
|
|
|
|
task :fork_branch, :path, :src_branch, :dst_branch do |t, args|
|
|
|
|
tmp_path = File.join Dir.tmpdir, "#{Time.now.to_i}#{rand(1000)}"
|
|
|
|
system("git clone #{args[:path]} #{tmp_path}")
|
2012-09-17 11:09:30 +01:00
|
|
|
system("cd #{tmp_path} && git push origin :#{args[:dst_branch]}")
|
2012-08-27 17:01:59 +01:00
|
|
|
system("cd #{tmp_path} && git checkout remotes/origin/#{args[:src_branch]} || git checkout master")
|
|
|
|
system("cd #{tmp_path} && git checkout -b #{args[:dst_branch]} && git push origin HEAD")
|
|
|
|
FileUtils.rm_rf tmp_path
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Add branch for platform projects"
|
|
|
|
task :platform => :environment do
|
|
|
|
src_branch = ENV['SRC_BRANCH'] || 'import_mandriva2011'
|
|
|
|
dst_branch = ENV['DST_BRANCH'] || 'rosa2012lts'
|
|
|
|
say "START add branch #{dst_branch} from #{src_branch}"
|
|
|
|
Platform.find_by_name(dst_branch).repositories.each do |r|
|
|
|
|
say "=== Process #{r.name} repo"
|
|
|
|
r.projects.find_each do |p|
|
|
|
|
next if p.repo.branches.map(&:name).include?(dst_branch)
|
|
|
|
say "===== Process #{p.name} project"
|
|
|
|
Rake::Task['add_branch:fork_branch'].execute(:path => p.path, :src_branch => src_branch, :dst_branch => dst_branch)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
say 'DONE'
|
|
|
|
end
|
2012-02-23 15:17:02 +00:00
|
|
|
|
2012-08-27 17:01:59 +01:00
|
|
|
desc "Add branch for owner projects by list"
|
|
|
|
task :list => :environment do
|
|
|
|
source = ENV['SOURCE'] || 'https://dl.dropbox.com/u/984976/texlive.txt'
|
|
|
|
owner = User.find_by_uname(ENV['OWNER']) || Group.find_by_uname!(ENV['OWNER'] || 'import')
|
|
|
|
platform = Platform.find_by_name!(ENV['PLATFORM'] || 'rosa2012.1')
|
|
|
|
repo = platform.repositories.find_by_name!(ENV['REPO'] || 'main')
|
|
|
|
src_branch = ENV['SRC_BRANCH'] || 'import_cooker'
|
|
|
|
dst_branch = ENV['DST_BRANCH'] || 'rosa2012.1'
|
|
|
|
say "START fork from #{src_branch} to #{dst_branch} branch using #{source} for #{owner.uname}. Add to repo '#{platform.name}/#{repo.name}'."
|
|
|
|
open(source).readlines.each do |name|
|
|
|
|
name.chomp!; name.strip!
|
|
|
|
print "Fork branch for '#{name}'... "
|
2012-09-19 17:32:53 +01:00
|
|
|
if p = Project.find_by_owner_and_name(owner.uname, name)
|
2012-08-27 17:01:59 +01:00
|
|
|
# Rake::Task['add_branch:fork_branch'].execute(:path => p.path, :src_branch => src_branch, :dst_branch => dst_branch)
|
|
|
|
system "bundle exec rake add_branch:fork_branch[#{p.path},#{src_branch},#{dst_branch}] -s RAILS_ENV=#{Rails.env} > /dev/null 2>&1"
|
|
|
|
print 'Ok!'
|
|
|
|
repo.projects << p rescue print ' Add to repo failed!'
|
|
|
|
else
|
|
|
|
print 'Not Found!'
|
|
|
|
end
|
|
|
|
puts
|
2012-02-23 15:17:02 +00:00
|
|
|
end
|
2012-08-27 17:01:59 +01:00
|
|
|
say 'DONE'
|
2012-02-23 15:17:02 +00:00
|
|
|
end
|
|
|
|
end
|