Class: SvnAuto::Project
- Inherits:
-
Object
- Object
- SvnAuto::Project
- Defined in:
- lib/svnauto/project.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
The name of the project.
-
#repository ⇒ Object
The repository for this project.
Class Method Summary collapse
-
.clean_name(non_clean_name) ⇒ Object
remove special characters from a project name.
-
.from_cwd(config) ⇒ Object
Try to get info about the current directory’s repository.
Instance Method Summary collapse
-
#branches(subdir = nil) ⇒ Object
get the full URL path for branches.
-
#checkout(version = nil, to = nil) ⇒ Object
checkout to the workspace.
-
#create ⇒ Object
create the necessary project directories in the repository.
-
#directories ⇒ Object
get a list of the directories that SvnAuto uses.
-
#initialize(options = {}) ⇒ Project
constructor
Setup a new project.
-
#latest_release_branch ⇒ Object
get the latest release branch version.
-
#latest_release_tag(branch_version) ⇒ Object
get the latest release tag for the given branch version.
-
#merge(version, start_tag, end_tag, &error_block) ⇒ Object
do some common stuff for merging.
-
#prepare(force) ⇒ Object
make sure the project is ready to be used.
-
#prompt_for_name ⇒ Object
prompt the user to pick a project name from the repository.
-
#release(version = nil) ⇒ Object
get the full URL to the release branch.
-
#tags(subdir = nil) ⇒ Object
get the full URL path for tags.
-
#to_s ⇒ Object
convert to a string.
-
#trunk ⇒ Object
get the full URL to the trunk for this repository and project.
-
#url ⇒ Object
get the URL to this project.
Constructor Details
#initialize(options = {}) ⇒ Project
Setup a new project
70 71 72 73 |
# File 'lib/svnauto/project.rb', line 70 def initialize (={}) @name = [:name] @repository = [:repository] end |
Instance Attribute Details
#name ⇒ Object
The name of the project
30 31 32 |
# File 'lib/svnauto/project.rb', line 30 def name @name end |
#repository ⇒ Object
The repository for this project
34 35 36 |
# File 'lib/svnauto/project.rb', line 34 def repository @repository end |
Class Method Details
.clean_name(non_clean_name) ⇒ Object
remove special characters from a project name
64 65 66 |
# File 'lib/svnauto/project.rb', line 64 def self.clean_name (non_clean_name) non_clean_name.gsub(Constants::NAME_RE, '_') end |
.from_cwd(config) ⇒ Object
Try to get info about the current directory’s repository
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/svnauto/project.rb', line 38 def self.from_cwd (config) url = nil project = nil # see if we're in an svn directory info = SvnInfo.for('.', false) if info.status url = info.repository_root project = info.url # try to find a matching repository repository = config[:repositories].find {|r| r.url == url} repository ||= Repository.new(:url => url) new({ :repository => repository, :name => project[url.length + 1 .. -1].sub(/\/.*$/, ''), }) else new end end |
Instance Method Details
#branches(subdir = nil) ⇒ Object
get the full URL path for branches
256 257 258 259 260 |
# File 'lib/svnauto/project.rb', line 256 def branches (subdir=nil) path = "#{url}/branches" path << "/#{subdir}" if subdir path end |
#checkout(version = nil, to = nil) ⇒ Object
checkout to the workspace
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/svnauto/project.rb', line 181 def checkout (version=nil, to=nil) workspace = @repository.workspace url = trunk co_name = "#{@name}-trunk" Dir.mkdir(workspace) unless File.exist?(workspace) case version when String url = version co_name = "#{@name}-" + version.sub("#{self.url}/", '').gsub(/\//, '-') co_name.sub!(/branches-/, '') co_name.sub!(/releases/, 'rel') when Version url = version.macro.nil? ? release(version.to_s) : ("rel/#{version.to_s}") co_name = "#{@name}-rel-#{version}" end co_name = to if to local_dir = File.join(workspace, co_name) Svn.checkout(url, local_dir) unless File.exist?(local_dir) local_dir end |
#create ⇒ Object
create the necessary project directories in the repository
141 142 143 144 145 146 147 |
# File 'lib/svnauto/project.rb', line 141 def create directories.each do |dir| unless Svn.has_path(dir) Svn.mkdir('-m', "#{Constants::ME}: creating #{dir} for project #{name}.", dir) end end end |
#directories ⇒ Object
get a list of the directories that SvnAuto uses
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/svnauto/project.rb', line 124 def directories [ url, trunk, branches, branches('rel'), branches('bug'), branches('exp'), , ('rel'), ('bug'), ('exp'), ] end |
#latest_release_branch ⇒ Object
get the latest release branch version
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/svnauto/project.rb', line 151 def latest_release_branch @versions ||= [] if @versions.empty? Svn.list(release) do |line| next if line.match(/^svn:/) @versions << Version.new(line.sub(/\/$/, '').strip) end end @versions.sort.last end |
#latest_release_tag(branch_version) ⇒ Object
get the latest release tag for the given branch version
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/svnauto/project.rb', line 166 def latest_release_tag (branch_version) = [] branch_version_str = branch_version.major_minor Svn.list(('rel')) do |line| tag = line.sub(/\/$/, '').strip next unless tag[0, branch_version_str.length] == branch_version_str << Version.new(tag) end .sort.last end |
#merge(version, start_tag, end_tag, &error_block) ⇒ Object
do some common stuff for merging
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/svnauto/project.rb', line 208 def merge (version, start_tag, end_tag, &error_block) tmp_checkout = "#{@name}-merge-tmp-#{$$}" dir = self.checkout(version, tmp_checkout) base = self.url start_tag = self.(start_tag) unless start_tag[0, base.length] == base end_tag = self.(end_tag) unless end_tag[0, base.length] == base Dir.chdir(dir) do conflicts = false Svn.merge(start_tag, end_tag) # test to make sure there are no conflicts Svn.status do |line| if line.match(/^\s*C/) conflicts = true Constants::TERMINAL.say(Constants::TERMINAL.color("MERGE CONFLICT: #{line.chomp}", :red)) end end if conflicts = "merge failed, you need to resolve conflicts in #{dir} " << "(use 'svn status' to see files with conflicts) " << yield if block_given? raise end Svn.commit('-m', "#{Constants::ME}: merging branch using tags #{start_tag} and #{end_tag}") end # clean up after merge begin FileUtils.rm_r(dir) rescue # turn the error message into something the user will understand raise "failed to remove tmp merge directory: #{dir}" end end |
#prepare(force) ⇒ Object
make sure the project is ready to be used
77 78 79 |
# File 'lib/svnauto/project.rb', line 77 def prepare (force) @repository.prepare(force) if @repository end |
#prompt_for_name ⇒ Object
prompt the user to pick a project name from the repository
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/svnauto/project.rb', line 95 def prompt_for_name names = [] if URI.parse(@repository.url).scheme != 'file' puts "Fetching project list from repository, please wait..." $stdout.flush end Svn.list(@repository.url) do |line| next if line.match(/^svn:/) names << line.sub(/\/$/, '').strip end if names.empty? raise "there are no projects in the repository #{@repository.url}" end @name = Constants::TERMINAL.choose do || .header = "Projects" .prompt = "Please choose a project: " names.each do |name| .choice(name) {name} end end end |
#release(version = nil) ⇒ Object
get the full URL to the release branch
272 273 274 275 276 |
# File 'lib/svnauto/project.rb', line 272 def release (version=nil) path = branches('rel') path << "/#{version}" if version path end |
#tags(subdir = nil) ⇒ Object
get the full URL path for tags
264 265 266 267 268 |
# File 'lib/svnauto/project.rb', line 264 def (subdir=nil) path = "#{url}/tags" path << "/#{subdir}" if subdir path end |
#to_s ⇒ Object
convert to a string
89 90 91 |
# File 'lib/svnauto/project.rb', line 89 def to_s @name end |
#trunk ⇒ Object
get the full URL to the trunk for this repository and project
250 251 252 |
# File 'lib/svnauto/project.rb', line 250 def trunk "#{url}/trunk" end |
#url ⇒ Object
get the URL to this project
83 84 85 |
# File 'lib/svnauto/project.rb', line 83 def url "#{@repository.url}/#{@name}" end |