Skip to content

Instantly share code, notes, and snippets.

@mitio
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitio/8886156 to your computer and use it in GitHub Desktop.
Save mitio/8886156 to your computer and use it in GitHub Desktop.
Quick scripts to help me grade hw 05 for the "Programming Ruby" course -- http://2013.fmi.ruby.bg/tasks/5
require 'time'
task_ends_at = '2014-01-22 17:30:00 +200'
late_commits_unix_timestamp = Time.parse(task_ends_at).utc.to_i
def commit_timestamp_of(commit_line)
commit_line.split(/\s+/).first.to_i
end
def commit_sha_of(commit_line)
commit_line.split(/ /)[1]
end
Dir["#{Dir.pwd}/*"].each do |path|
next unless File.directory?(path) and File.exist?("#{path}/.git/config")
folder = File.basename path
print "Checking #{folder}... "
Dir.chdir path
commits = `git log --pretty=format:'%ct (%ci) %h %an - %s' origin/master`.lines.reverse
is_late_commit = -> commit { commit_timestamp_of(commit) > late_commits_unix_timestamp }
late_commits = commits.select(&is_late_commit)
if late_commits.empty?
puts "OK"
else
last_good_commit = commits.reject(&is_late_commit).last
puts "LATE:"
late_commits.each do |commit|
puts " #{commit}"
end
puts " Moving to last good commit: #{last_good_commit}"
system "git checkout #{commit_sha_of last_good_commit}"
end
end
verbose = ARGV.include? 'verbose'
Dir["#{Dir.pwd}/*"].each do |path|
next unless File.directory?(path) and File.exist?("#{path}/.git/config")
folder = File.basename path
print "Checking #{folder}... "
Dir.chdir path
checks_output = `rake check`
if $?.exitstatus == 0
puts 'OK'
else
puts 'FAILED'
puts checks_output if verbose
end
end
Dir['*.rb'].each do |solution_file|
next unless solution_file =~ /\b(x?\d+).rb$/
target_folder = $1
fork do
require_relative solution_file
if !Object.const_defined?('REPOSITORY')
puts "Missing constant REPOSITORY for #{solution_file}"
elsif File.exist?("#{target_folder}/.git/config")
puts "Skipping #{target_folder} as it seems to exist. Repo is: #{REPOSITORY}"
else
system "git clone '#{REPOSITORY}' '#{target_folder}'"
end
end
Process.waitall
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment