rosa-build/app/models/repository.rb

61 lines
1.6 KiB
Ruby
Raw Normal View History

class Repository < ActiveRecord::Base
belongs_to :platform
has_many :projects, :dependent => :destroy
2011-04-28 11:16:31 +01:00
validates :name, :uniqueness => {:scope => :platform_id}, :presence => true
2011-04-20 08:04:22 +01:00
validates :unixname, :uniqueness => {:scope => :platform_id}, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }
scope :recent, order("name ASC")
2011-04-07 10:27:50 +01:00
before_create :xml_rpc_create
before_destroy :xml_rpc_destroy
def path
build_path(unixname)
end
2011-03-11 17:38:28 +00:00
def clone
r = Repository.new
r.name = name
r.unixname = unixname
r.projects = projects.map(&:clone)
return r
end
protected
def build_path(dir)
File.join(platform.path, dir)
end
def create_directory
exists = File.exists?(path) && File.directory?(path)
raise "Directory #{path} already exists" if exists
if new_record?
FileUtils.mkdir_p(path)
2011-03-11 17:25:08 +00:00
%w(release updates).each { |subrep| FileUtils.mkdir_p(path + subrep) }
elsif unixname_changed?
FileUtils.mv(build_path(unixname_was), buildpath(unixname))
end
end
2011-04-07 10:27:50 +01:00
def xml_rpc_create
2011-04-14 12:24:41 +01:00
result = BuildServer.create_repo unixname, platform.unixname
2011-04-07 10:27:50 +01:00
if result == BuildServer::SUCCESS
return true
else
raise "Failed to create repository #{name} inside platform #{platform.name}."
end
end
def xml_rpc_destroy
2011-04-14 12:24:41 +01:00
result = BuildServer.delete_repo unixname, platform.unixname
2011-04-07 10:27:50 +01:00
if result == BuildServer::SUCCESS
return true
else
raise "Failed to delete repository #{name} inside platform #{platform.name}."
end
end
end