Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 20th, 2012  |  syntax: None  |  size: 1.97 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #require './config/environment' # FIXME REMOVE
  2. require 'grit'
  3. require 'fileutils'
  4. namespace :git_repos do
  5.   desc "Clone or update git repos for all projects"
  6.   task :create => :environment do
  7.     workspace_dir = File.join(Rails.root, "tmp", "xrono_git_workspace")
  8.     puts "Creating workspace directory at #{workspace_dir}"
  9.     FileUtils.rm_rf File.join(workspace_dir) if Dir.exists?(workspace_dir)
  10.     Dir.mkdir( workspace_dir )
  11.     Client.active.all.each do |client|
  12.       puts "Working on client #{client.name}"
  13.       #make the client directories
  14.       client_directory = File.join(workspace_dir,  client.name.gsub("//","").gsub(" ","_").gsub("/",""))
  15.       puts "\tCreating client directory at #{client_directory}"
  16.       Dir.mkdir(client_directory) unless Dir.exists?(client_directory)
  17.  
  18.       #Loop over the projects and clone or update the repos
  19.       client.projects.with_git_repos.all.each do |project|
  20.         puts "\t\tWorking on Project #{project.name}"
  21.         project_directory = File.join(client_directory, project.name.gsub("//","").gsub(" ","_").gsub("/",""))
  22.         grit = Grit::Git.new('/tmp/')
  23.         puts "\t\t\tAttempting to clone #{project.git_repo_url} to #{project_directory}"
  24.         begin
  25.           grit.clone({:quiet => false, :verbose => true, :progress => true, :branch => '37s'}, project.git_repo_url, project_directory)
  26.         rescue Grit::Git::GitTimeout
  27.           next
  28.         end
  29.         xrono_markdown = File.join(project_directory, "XRONO.md")
  30.         release_notes  = File.join(project_directory, "RELEASE_NOTES.md")
  31.  
  32.         if File.exists?(xrono_markdown)
  33.           project.xrono_notes = File.read(xrono_markdown)
  34.         else
  35.           project.xrono_notes = nil
  36.         end
  37.         if File.exists?(release_notes)
  38.           project.release_notes = File.read(release_notes)
  39.         else
  40.           project.release_notes = nil
  41.         end
  42.         project.save
  43.       end
  44.     end
  45.     puts "Cleaning up workspace directory"
  46.     FileUtils.rm_rf File.join(workspace_dir)
  47.   end
  48. end