Last active
August 29, 2015 13:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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