require 'date' module Rudy module SCM class SVN attr_accessor :base_uri def initialize(uri) @base_uri = uri end def create_release raise "There are local changes. Please revert or check them in!" unless everything_checked_in? raise "Invalid base URI (#{@base_uri}). Check RUDY_SVN_BASE." unless valid_uri?(@base_uri) raise "You must run this command from SVN you want to release from!" unless svn_dir?(Dir.pwd) re = `svn info`.match /^URL:\s+(.+)$/ release = re[1] if re release_tag = "#{@base_uri}/#{generate_release_tag}" puts "Creating tag: #{release_tag}" cmd = "svn copy -m 'Another Release by Rudy!' #{release} #{release_tag}" `#{cmd} 2>&1` release_tag end def generate_release_tag now = Time.now mon = now.mon.to_s.rjust(2, '0') day = now.day.to_s.rjust(2, '0') rev = "r01" criteria = ['rudy', now.year, mon, day, rev] tag = criteria.join(RUDY_DELIM) # Keep incrementing the revision number until we find the next one. tag.succ! while (valid_uri?("#{@base_uri}/#{tag}")) tag end def svn_dir?(path) (File.exists?(File.join(path, '.svn'))) end def valid_uri?(uri) ret = `svn info #{uri} 2>&1` || '' # Valid SVN URIs will return some info (ret =~ /Repository UUID/) ? true : false end def everything_checked_in? `svn diff . 2>&1` == '' # svn diff should return nothing end end end end