[issue #64] Merge branch 'master' into 64-project_wiki

Conflicts:
	Gemfile.lock
	app/models/project.rb
	db/schema.rb
This commit is contained in:
George Vinogradov 2012-01-30 13:27:22 +04:00
commit 2f315f869d
21 changed files with 235 additions and 92 deletions

View File

@ -4,6 +4,7 @@ gem 'rails', '3.0.11' #, :git => 'git://github.com/rails/rails.git'
gem 'pg', '~> 0.11.0' gem 'pg', '~> 0.11.0'
gem 'silent-postgres', '~> 0.1.1' gem 'silent-postgres', '~> 0.1.1'
gem 'schema_plus', '~> 0.2.1'
gem 'devise', '~> 1.5.2' gem 'devise', '~> 1.5.2'
gem 'omniauth', '~> 1.0.1' gem 'omniauth', '~> 1.0.1'

View File

@ -209,6 +209,9 @@ GEM
i18n (>= 0.5.0) i18n (>= 0.5.0)
sanitize (2.0.3) sanitize (2.0.3)
nokogiri (>= 1.4.4, < 1.6) nokogiri (>= 1.4.4, < 1.6)
schema_plus (0.2.1)
rails
valuable
sexp_processor (3.0.8) sexp_processor (3.0.8)
silent-postgres (0.1.1) silent-postgres (0.1.1)
sinatra (1.2.7) sinatra (1.2.7)
@ -225,6 +228,7 @@ GEM
kgio (~> 2.4) kgio (~> 2.4)
rack rack
raindrops (~> 0.6) raindrops (~> 0.6)
valuable (0.9.2)
warden (1.1.0) warden (1.1.0)
rack (>= 1.0) rack (>= 1.0)
web-app-theme (0.7.0) web-app-theme (0.7.0)
@ -281,6 +285,7 @@ DEPENDENCIES
ruby-debug ruby-debug
ruby_parser ruby_parser
russian russian
schema_plus (~> 0.2.1)
silent-postgres (~> 0.1.1) silent-postgres (~> 0.1.1)
unicorn (~> 4.1.1) unicorn (~> 4.1.1)
web-app-theme web-app-theme

View File

@ -7,7 +7,7 @@ class PersonalRepositoriesController < ApplicationController
def show def show
if params[:query] if params[:query]
@projects = @repository.projects.recent.by_name(params[:query]).paginate :page => params[:project_page], :per_page => 30 @projects = @repository.projects.recent.by_name("%#{params[:query]}%").paginate :page => params[:project_page], :per_page => 30
else else
@projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30 @projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30
end end

View File

@ -17,13 +17,13 @@ class ProjectsController < ApplicationController
end.accessible_by(current_ability) end.accessible_by(current_ability)
@projects = if params[:query] @projects = if params[:query]
@projects.by_name(params[:query]).order("CHAR_LENGTH(name) ASC") @projects.by_name("%#{params[:query]}%").order("CHAR_LENGTH(name) ASC")
else else
@projects @projects
end.paginate(:page => params[:project_page]) end.paginate(:page => params[:project_page])
@own_projects = current_user.own_projects @own_projects = current_user.own_projects
@part_projects = current_user.projects + current_user.groups.map(&:projects).flatten.uniq - @own_projects #@part_projects = current_user.projects + current_user.groups.map(&:projects).flatten.uniq - @own_projects
end end
def show def show

View File

@ -19,7 +19,7 @@ class RepositoriesController < ApplicationController
def show def show
if params[:query] if params[:query]
@projects = @repository.projects.recent.by_name(params[:query]).paginate :page => params[:project_page], :per_page => 30 @projects = @repository.projects.recent.by_name("%#{params[:query]}%").paginate :page => params[:project_page], :per_page => 30
else else
@projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30 @projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30
end end

View File

@ -21,6 +21,7 @@ class Group < ActiveRecord::Base
delegate :ssh_key, :to => :owner delegate :ssh_key, :to => :owner
after_create :add_owner_to_members after_create :add_owner_to_members
after_initialize lambda {|r| r.name ||= r.uname } # default
include Modules::Models::PersonalRepository include Modules::Models::PersonalRepository
# include Modules::Models::Owner # include Modules::Models::Owner

View File

@ -14,7 +14,7 @@ class Platform < ActiveRecord::Base
has_many :groups, :through => :objects, :source => :object, :source_type => 'Group' has_many :groups, :through => :objects, :source => :object, :source_type => 'Group'
validates :description, :presence => true, :uniqueness => true validates :description, :presence => true, :uniqueness => true
validates :name, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ } validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']} validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']}
before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]}

View File

@ -9,7 +9,7 @@ class Project < ActiveRecord::Base
has_many :build_lists, :dependent => :destroy has_many :build_lists, :dependent => :destroy
has_many :auto_build_lists, :dependent => :destroy has_many :auto_build_lists, :dependent => :destroy
# has_many :project_imports, :dependent => :destroy has_many :project_imports, :dependent => :destroy
has_many :project_to_repositories, :dependent => :destroy has_many :project_to_repositories, :dependent => :destroy
has_many :repositories, :through => :project_to_repositories has_many :repositories, :through => :project_to_repositories
@ -17,18 +17,18 @@ class Project < ActiveRecord::Base
has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User' has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User'
has_many :groups, :through => :relations, :source => :object, :source_type => 'Group' has_many :groups, :through => :relations, :source => :object, :source_type => 'Group'
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ } validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ }
validates :owner, :presence => true validates :owner, :presence => true
validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS } validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS }
# validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?} # validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?}
validates_attachment_size :srpm, :less_than => 500.megabytes validates_attachment_size :srpm, :less_than => 500.megabytes
validates_attachment_content_type :srpm, :content_type => ['application/octet-stream'], :message => I18n.t('layout.invalid_content_type') # "application/x-rpm", "application/x-redhat-package-manager" ? validates_attachment_content_type :srpm, :content_type => ['application/octet-stream', "application/x-rpm", "application/x-redhat-package-manager"], :message => I18n.t('layout.invalid_content_type')
#attr_accessible :category_id, :name, :description, :visibility #attr_accessible :category_id, :name, :description, :visibility
attr_readonly :name attr_readonly :name
scope :recent, order("name ASC") scope :recent, order("name ASC")
scope :by_name, lambda { |name| where('name like ?', "%#{ name }%") } scope :by_name, lambda {|name| where('projects.name ILIKE ?', name)}
scope :by_visibilities, lambda {|v| {:conditions => ['visibility in (?)', v.join(',')]}} scope :by_visibilities, lambda {|v| {:conditions => ['visibility in (?)', v.join(',')]}}
scope :addable_to_repository, lambda { |repository_id| where("projects.id NOT IN (SELECT project_to_repositories.project_id FROM project_to_repositories WHERE (project_to_repositories.repository_id = #{ repository_id }))") } scope :addable_to_repository, lambda { |repository_id| where("projects.id NOT IN (SELECT project_to_repositories.project_id FROM project_to_repositories WHERE (project_to_repositories.repository_id = #{ repository_id }))") }
scope :automateable, where("projects.id NOT IN (SELECT auto_build_lists.project_id FROM auto_build_lists)") scope :automateable, where("projects.id NOT IN (SELECT auto_build_lists.project_id FROM auto_build_lists)")
@ -39,7 +39,7 @@ class Project < ActiveRecord::Base
after_destroy :destroy_git_repo after_destroy :destroy_git_repo
after_destroy :destroy_wiki after_destroy :destroy_wiki
after_save {|p| p.delay.import_srpm if p.srpm?} # should be after create_git_repo after_save {|p| p.delay.import_attached_srpm if p.srpm?} # should be after create_git_repo
# after_rollback lambda { destroy_git_repo rescue true if new_record? } # after_rollback lambda { destroy_git_repo rescue true if new_record? }
has_ancestry has_ancestry
@ -152,11 +152,8 @@ class Project < ActiveRecord::Base
@platforms ||= repositories.map(&:platform).uniq @platforms ||= repositories.map(&:platform).uniq
end end
def import_srpm(branch_name = 'import') def import_srpm(srpm_path = srpm.path, branch_name = 'import')
if srpm? system("#{Rails.root.join('bin', 'import_srpm.sh')} #{srpm_path} #{path} #{branch_name} >> /dev/null 2>&1")
system("#{Rails.root.join('bin', 'import_srpm.sh')} #{srpm.path} #{path} #{branch_name} >> /dev/null 2>&1")
self.srpm = nil; save # clear srpm
end
end end
class << self class << self
@ -168,36 +165,43 @@ class Project < ActiveRecord::Base
protected protected
def build_path(dir) def build_path(dir)
File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.git") File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.git")
end end
def build_wiki_path(dir) def build_wiki_path(dir)
File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.wiki.git") File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.wiki.git")
end end
def attach_to_personal_repository def attach_to_personal_repository
repositories << self.owner.personal_repository if !repositories.exists?(:id => self.owner.personal_repository) repositories << self.owner.personal_repository if !repositories.exists?(:id => self.owner.personal_repository)
end end
def create_git_repo def create_git_repo
is_root? ? Grit::Repo.init_bare(path) : parent.git_repository.repo.delay.fork_bare(path) is_root? ? Grit::Repo.init_bare(path) : parent.git_repository.repo.delay.fork_bare(path)
end end
def destroy_git_repo def destroy_git_repo
FileUtils.rm_rf path FileUtils.rm_rf path
end end
def create_wiki def import_attached_srpm
if has_wiki && !FileTest.exist?(wiki_path) if srpm?
Grit::Repo.init_bare(wiki_path) import_srpm # srpm.path
wiki = Gollum::Wiki.new(wiki_path, {:base_path => Rails.application.routes.url_helpers.project_wiki_index_path(self)}) self.srpm = nil; save # clear srpm
wiki.write_page('Home', :markdown, I18n.t("wiki.seed.welcome_content"),
{:name => owner.name, :email => owner.email, :message => 'Initial commit'})
end
end end
end
def destroy_wiki def create_wiki
FileUtils.rm_rf wiki_path if has_wiki && !FileTest.exist?(wiki_path)
Grit::Repo.init_bare(wiki_path)
wiki = Gollum::Wiki.new(wiki_path, {:base_path => Rails.application.routes.url_helpers.project_wiki_index_path(self)})
wiki.write_page('Home', :markdown, I18n.t("wiki.seed.welcome_content"),
{:name => owner.name, :email => owner.email, :message => 'Initial commit'})
end end
end
def destroy_wiki
FileUtils.rm_rf wiki_path
end
end end

View File

@ -0,0 +1,9 @@
class ProjectImport < ActiveRecord::Base
belongs_to :project
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true
scope :by_name, lambda {|name| where('project_imports.name ILIKE ?', name)}
after_initialize lambda {|r| r.file_mtime ||= Time.current - 10.years } # default
end

View File

@ -13,8 +13,7 @@ class ProjectToRepository < ActiveRecord::Base
protected protected
def one_project_in_platform_repositories def one_project_in_platform_repositories
c = Platform.scoped.select('projects.*').joins(:repositories => :projects).where( errors.add(:project, 'should be one in platform') if Project.joins(:repositories => :platform).
:projects => {:name => project.name}, :id => repository.platform_id).count where('platforms.id = ?', repository.platform_id).by_name(project.name).count > 0
errors.add(:project, 'should be one in platform') if c > 0
end end
end end

View File

@ -11,7 +11,7 @@ class Repository < ActiveRecord::Base
has_many :groups, :through => :objects, :source => :object, :source_type => 'Group' has_many :groups, :through => :objects, :source => :object, :source_type => 'Group'
validates :description, :uniqueness => {:scope => :platform_id}, :presence => true validates :description, :uniqueness => {:scope => :platform_id}, :presence => true
validates :name, :uniqueness => {:scope => :platform_id}, :presence => true, :format => { :with => /^[a-z0-9_\-]+$/ } validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => { :with => /^[a-z0-9_\-]+$/ }
# validates :platform_id, :presence => true # if you uncomment this platform clone will not work # validates :platform_id, :presence => true # if you uncomment this platform clone will not work
scope :recent, order("name ASC") scope :recent, order("name ASC")

View File

@ -6,11 +6,11 @@
- @own_projects.each do |project| - @own_projects.each do |project|
%li %li
= link_to project.name, project_path(project) = link_to project.name, project_path(project)
.block.notice -#.block.notice
%h3= t("layout.users.part_projects") -# %h3= t("layout.users.part_projects")
.content -# .content
%p -# %p
%ul -# %ul
- @part_projects.each do |project| -# - @part_projects.each do |project|
%li -# %li
= link_to project.owner.uname + '/' + project.name, project_path(project) -# = link_to project.owner.uname + '/' + project.name, project_path(project)

View File

@ -13,6 +13,16 @@ Bluepill.application(app_name) do |app|
process.stop_command = "/usr/bin/env RAILS_ENV=production script/delayed_job stop" process.stop_command = "/usr/bin/env RAILS_ENV=production script/delayed_job stop"
process.pid_file = File.join(app.working_dir, 'tmp', 'pids', 'delayed_job.pid') process.pid_file = File.join(app.working_dir, 'tmp', 'pids', 'delayed_job.pid')
end end
app.process("newrelic") do |process|
process.start_grace_time = 10.seconds
process.stop_grace_time = 10.seconds
process.restart_grace_time = 10.seconds
path = File.join(app.working_dir, 'tmp', 'pids', 'newrelic.pid')
process.start_command = "/usr/bin/env /usr/local/bin/nrsysmond -c /etc/newrelic/nrsysmond.cfg -p #{path}"
process.pid_file = path
end
app.process("unicorn") do |process| app.process("unicorn") do |process|
process.start_grace_time = 8.seconds process.start_grace_time = 8.seconds

View File

@ -11,3 +11,7 @@ every 5.minutes do
runner "Download.rotate_nginx_log" runner "Download.rotate_nginx_log"
runner "Download.parse_and_remove_nginx_log" runner "Download.parse_and_remove_nginx_log"
end end
every 1.day, :at => '4:00 am' do
rake "import:sync:all", :output => 'log/sync.log'
end

View File

@ -0,0 +1,16 @@
class CreateProjectImports < ActiveRecord::Migration
def self.up
create_table :project_imports do |t|
t.references :project
t.string :name
t.string :version
t.datetime :file_mtime
t.timestamps
end
end
def self.down
drop_table :project_imports
end
end

View File

@ -0,0 +1,11 @@
class AddIndexForProjectsName < ActiveRecord::Migration
def self.up
add_index :projects, [:name, :owner_id, :owner_type], :unique => true, :case_sensitive => false
add_index :project_imports, :name, :unique => true, :case_sensitive => false
end
def self.down
remove_index :projects, [:name, :owner_id, :owner_type]
remove_index :project_imports, :name
end
end

View File

@ -10,27 +10,25 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120126214447) do ActiveRecord::Schema.define(:version => 20120127234602) do
create_table "arches", :force => true do |t| create_table "arches", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.index ["name"], :name => "index_arches_on_name", :unique => true
end end
add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true
create_table "authentications", :force => true do |t| create_table "authentications", :force => true do |t|
t.integer "user_id" t.integer "user_id"
t.string "provider" t.string "provider"
t.string "uid" t.string "uid"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.index ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true
t.index ["user_id"], :name => "index_authentications_on_user_id"
end end
add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true
add_index "authentications", ["user_id"], :name => "index_authentications_on_user_id"
create_table "auto_build_lists", :force => true do |t| create_table "auto_build_lists", :force => true do |t|
t.integer "project_id" t.integer "project_id"
t.integer "arch_id" t.integer "arch_id"
@ -48,10 +46,9 @@ ActiveRecord::Schema.define(:version => 20120126214447) do
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "version" t.string "version"
t.index ["build_list_id"], :name => "index_build_list_items_on_build_list_id"
end end
add_index "build_list_items", ["build_list_id"], :name => "index_build_list_items_on_build_list_id"
create_table "build_lists", :force => true do |t| create_table "build_lists", :force => true do |t|
t.integer "bs_id" t.integer "bs_id"
t.string "container_path" t.string "container_path"
@ -74,12 +71,11 @@ ActiveRecord::Schema.define(:version => 20120126214447) do
t.boolean "auto_publish", :default => true t.boolean "auto_publish", :default => true
t.string "package_version" t.string "package_version"
t.string "commit_hash" t.string "commit_hash"
t.index ["arch_id"], :name => "index_build_lists_on_arch_id"
t.index ["bs_id"], :name => "index_build_lists_on_bs_id", :unique => true
t.index ["project_id"], :name => "index_build_lists_on_project_id"
end end
add_index "build_lists", ["arch_id"], :name => "index_build_lists_on_arch_id"
add_index "build_lists", ["bs_id"], :name => "index_build_lists_on_bs_id", :unique => true
add_index "build_lists", ["project_id"], :name => "index_build_lists_on_project_id"
create_table "categories", :force => true do |t| create_table "categories", :force => true do |t|
t.string "name" t.string "name"
t.string "ancestry" t.string "ancestry"
@ -116,10 +112,9 @@ ActiveRecord::Schema.define(:version => 20120126214447) do
t.string "locked_by" t.string "locked_by"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.index ["priority", "run_at"], :name => "delayed_jobs_priority"
end end
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
create_table "downloads", :force => true do |t| create_table "downloads", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
t.string "version" t.string "version"
@ -164,10 +159,9 @@ ActiveRecord::Schema.define(:version => 20120126214447) do
t.string "status", :default => "open" t.string "status", :default => "open"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.index ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true
end end
add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true
create_table "platforms", :force => true do |t| create_table "platforms", :force => true do |t|
t.string "description" t.string "description"
t.string "name" t.string "name"
@ -197,10 +191,9 @@ ActiveRecord::Schema.define(:version => 20120126214447) do
t.datetime "notified_at" t.datetime "notified_at"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.index ["product_id"], :name => "index_product_build_lists_on_product_id"
end end
add_index "product_build_lists", ["product_id"], :name => "index_product_build_lists_on_product_id"
create_table "products", :force => true do |t| create_table "products", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
t.integer "platform_id", :null => false t.integer "platform_id", :null => false
@ -222,6 +215,15 @@ ActiveRecord::Schema.define(:version => 20120126214447) do
t.boolean "use_cron", :default => false t.boolean "use_cron", :default => false
end end
create_table "project_imports", :force => true do |t|
t.integer "project_id"
t.string "name"
t.string "version"
t.datetime "file_mtime"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "project_to_repositories", :force => true do |t| create_table "project_to_repositories", :force => true do |t|
t.integer "project_id" t.integer "project_id"
t.integer "repository_id" t.integer "repository_id"
@ -239,16 +241,17 @@ ActiveRecord::Schema.define(:version => 20120126214447) do
t.integer "category_id" t.integer "category_id"
t.text "description" t.text "description"
t.string "ancestry" t.string "ancestry"
<<<<<<< HEAD
t.boolean "has_wiki", :default => false t.boolean "has_wiki", :default => false
t.boolean "has_issues", :default => true t.boolean "has_issues", :default => true
t.integer "srpm_file_size" t.integer "srpm_file_size"
t.string "srpm_file_name" t.string "srpm_file_name"
t.string "srpm_content_type" t.string "srpm_content_type"
t.datetime "srpm_updated_at" t.datetime "srpm_updated_at"
t.index ["category_id"], :name => "index_projects_on_category_id"
t.index ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true
end end
add_index "projects", ["category_id"], :name => "index_projects_on_category_id"
create_table "relations", :force => true do |t| create_table "relations", :force => true do |t|
t.integer "object_id" t.integer "object_id"
t.string "object_type" t.string "object_type"
@ -269,30 +272,16 @@ ActiveRecord::Schema.define(:version => 20120126214447) do
t.string "owner_type" t.string "owner_type"
end end
create_table "role_lines", :force => true do |t|
t.integer "role_id"
t.integer "relation_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "roles", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "rpms", :force => true do |t| create_table "rpms", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
t.integer "arch_id", :null => false t.integer "arch_id", :null => false
t.integer "project_id", :null => false t.integer "project_id", :null => false
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.index ["project_id"], :name => "index_rpms_on_project_id"
t.index ["project_id", "arch_id"], :name => "index_rpms_on_project_id_and_arch_id"
end end
add_index "rpms", ["project_id", "arch_id"], :name => "index_rpms_on_project_id_and_arch_id"
add_index "rpms", ["project_id"], :name => "index_rpms_on_project_id"
create_table "settings_notifiers", :force => true do |t| create_table "settings_notifiers", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.boolean "can_notify", :default => true t.boolean "can_notify", :default => true
@ -327,10 +316,9 @@ ActiveRecord::Schema.define(:version => 20120126214447) do
t.string "role" t.string "role"
t.integer "own_projects_count", :default => 0, :null => false t.integer "own_projects_count", :default => 0, :null => false
t.string "language", :default => "en" t.string "language", :default => "en"
t.index ["email"], :name => "index_users_on_email", :unique => true
t.index ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
t.index ["uname"], :name => "index_users_on_uname", :unique => true
end end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
add_index "users", ["uname"], :name => "index_users_on_uname", :unique => true
end end

View File

@ -37,7 +37,8 @@ module Grack
name.gsub! /\.git$/, '' name.gsub! /\.git$/, ''
name.gsub! /\.wiki$/, '' name.gsub! /\.wiki$/, ''
owner = User.find_by_uname(uname) || Group.find_by_uname(uname) owner = User.find_by_uname(uname) || Group.find_by_uname(uname)
Project.where(:owner_id => owner.id, :owner_type => owner.class).find_by_name(name) scoped = Project.where(:owner_id => owner.id, :owner_type => owner.class)
scoped.find_by_name(name) || scoped.by_name(name).first
end end
end end

View File

@ -25,4 +25,84 @@ namespace :import do
end end
say 'DONE' say 'DONE'
end end
namespace :sync do
desc "Sync all repos"
task :all do
system("bundle exec rake import:sync:run RELEASE=official/2011 PLATFORM=mandriva2011 REPOSITORY=main")
system("bundle exec rake import:sync:run RELEASE=official/2011 PLATFORM=mandriva2011 REPOSITORY=contrib")
system("bundle exec rake import:sync:run RELEASE=official/2011 PLATFORM=mandriva2011 REPOSITORY=non-free")
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=main")
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=contrib")
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=non-free")
end
task :run => [:rsync, :parse]
desc "Rsync with mirror.yandex.ru"
task :rsync => :environment do
release = ENV['RELEASE'] || 'official/2011'
repository = ENV['REPOSITORY'] || 'main'
source = "rsync://mirror.yandex.ru/mandriva/#{release}/SRPMS/#{repository}/"
destination = ENV['DESTINATION'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository)
say "START rsync projects (*.src.rpm) from '#{source}' to '#{destination}'"
if system "rsync -rtv --delete #{source} #{destination}" # TODO --include='*.src.rpm' --exclude='*'
say 'Rsync ok!'
else
say 'Rsync failed!'
end
say 'DONE'
end
desc "Parse repository for changes"
task :parse => :environment do
release = ENV['RELEASE'] || 'official/2011'
platform = Platform.find_by_name(ENV['PLATFORM'] || "mandriva2011")
repository = platform.repositories.find_by_name(ENV['REPOSITORY'] || 'main')
source = ENV['SOURCE'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository.name)
owner = Group.find_or_create_by_uname(ENV['OWNER'] || 'import') {|g| g.owner = User.first}
branch = "import_#{platform.name}"
say 'START'
Dir[File.join source, '{release,updates}', '*.src.rpm'].each do |srpm_file|
say "=== Processing '#{srpm_file}'..."
if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? and
version = `rpm -q --qf '[%{Version}]' -p #{srpm_file}` and $?.success? and version.present?
project_import = ProjectImport.find_by_name(name) || ProjectImport.by_name(name).first || ProjectImport.new(:name => name)
if version != project_import.version.to_s and File.mtime(srpm_file) > project_import.file_mtime
unless project = project_import.project
if project = repository.projects.find_by_name(name) || repository.projects.by_name(name).first # fallback to speedup
say "Found project '#{project.owner.uname}/#{project.name}'"
elsif scoped = Project.where(:owner_id => owner.id, :owner_type => owner.class) and
project = scoped.find_by_name(name) || scoped.by_name(name).first
repository.projects << project
say "Add project '#{project.owner.uname}/#{project.name}' to '#{platform.name}/#{repository.name}'"
else
description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`)
project = Project.create!(:name => name, :description => description) {|p| p.owner = owner}
repository.projects << project
say "Create project #{project.owner.uname}/#{project.name} in #{platform.name}/#{repository.name}"
end
end
project.import_srpm(srpm_file, branch)
say "New version (#{version}) for '#{project.owner.uname}/#{project.name}' successfully imported to branch '#{branch}'!"
project_import.project = project
project_import.version = version
project_import.file_mtime = File.mtime(srpm_file)
project_import.save!
# TODO notify import.members
say '=== Success!'
else
say '=== Not changed!'
end
else
say '=== Fail!'
end
end
say 'DONE'
end
end
end end

View File

@ -0,0 +1,9 @@
# Read about factories at http://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :project_import do
project nil
name "MyString"
version "MyString"
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe ProjectImport do
pending "add some examples to (or delete) #{__FILE__}"
end