mirror of
https://github.com/System-End/highway.git
synced 2026-04-19 22:05:13 +00:00
Create clone_projects_job.rb
This commit is contained in:
parent
ec70cfa6fd
commit
42be4286f6
1 changed files with 26 additions and 0 deletions
26
app/jobs/clone_projects_job.rb
Normal file
26
app/jobs/clone_projects_job.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class CloneProjectsJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform
|
||||
submissions = YAML.load_file(Rails.root.join("submissions.yml"))
|
||||
|
||||
submissions["projects"].each do |url|
|
||||
url = url.chomp("/")
|
||||
url = "#{url}.git" unless url.end_with?(".git")
|
||||
|
||||
org, repo = url.gsub("https://github.com/", "").gsub(".git", "").split("/")
|
||||
|
||||
target_dir = File.join(Rails.root, "content", "projects", org, repo)
|
||||
|
||||
if Dir.exist?(target_dir) && Dir.exist?(File.join(target_dir, ".git"))
|
||||
Rails.logger.info "Pulling latest for #{org}/#{repo}..."
|
||||
system("cd '#{target_dir}' && git pull")
|
||||
else
|
||||
Rails.logger.info "Cloning #{org}/#{repo}..."
|
||||
system("git clone #{url} '#{target_dir}'")
|
||||
end
|
||||
end
|
||||
|
||||
Rails.logger.info "Done cloning and updating all projects!"
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue