diff --git a/Gemfile b/Gemfile index 859535768..dcea2c372 100644 --- a/Gemfile +++ b/Gemfile @@ -29,7 +29,7 @@ gem 'unicorn' # XML-RPC support # gem 'actionwebservice' #, :git => 'git://github.com/ywen/actionwebservice.git' -gem "rails-xmlrpc" +gem "rails-xmlrpc", :git => 'git://github.com/chipiga/rails-xmlrpc.git' group :production do gem "airbrake" diff --git a/Gemfile.lock b/Gemfile.lock index 308de2191..2e7293c13 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,9 @@ +GIT + remote: git://github.com/chipiga/rails-xmlrpc.git + revision: 3cf79e062c65447809209724a0cb8d1ea5af2e57 + specs: + rails-xmlrpc (0.3.1) + GIT remote: git@github.com:warpc/gitolito.git revision: 8608b9bdfd33e961d9f9d71dd594e62780c074f6 @@ -189,7 +195,6 @@ GEM activesupport (= 3.0.10) bundler (~> 1.0) railties (= 3.0.10) - rails-xmlrpc (0.3.2) rails3-generators (0.17.4) railties (>= 3.0.0) railties (3.0.10) @@ -280,7 +285,7 @@ DEPENDENCIES paperclip (~> 2.3) pg (~> 0.11.0) rails (= 3.0.10) - rails-xmlrpc + rails-xmlrpc! rails3-generators rspec-rails (~> 2.7.0) ruby-debug diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a457c45f3..0833c9dc0 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -63,7 +63,7 @@ class ProjectsController < ApplicationController :pl_id => auto_build_list.pl_id, :bpl_id => auto_build_list.bpl_id, :arch_id => auto_build_list.arch_id, - :project_version => project.project_versions.last.try(:name), + :project_version => project.collected_project_versions.last.try(:first), :build_requires => true, :update_type => 'bugfix') if auto_build_list @@ -74,7 +74,7 @@ class ProjectsController < ApplicationController @arches = Arch.recent @bpls = Platform.main @pls = @project.repositories.collect { |rep| ["#{rep.platform.name}/#{rep.unixname}", rep.platform.id] } - @project_versions = @project.project_versions.collect { |tag| [tag.name, tag.name.gsub(/^\w+\./, "")] } + @project_versions = @project.collected_project_versions end def process_build @@ -90,7 +90,7 @@ class ProjectsController < ApplicationController update_type = params[:build][:update_type] build_requires = params[:build][:build_requires] - @project_versions = @project.project_versions.collect { |tag| [tag.name, tag.name.gsub(/^\w+\./, "")] }.select { |pv| pv[0] =~ /^v\./ } + @project_versions = @project.collected_project_versions if !check_arches || !check_project_versions @arches = Arch.recent diff --git a/app/controllers/rpc_controller.rb b/app/controllers/rpc_controller.rb index d7c3ffd7f..f0e29ef3f 100644 --- a/app/controllers/rpc_controller.rb +++ b/app/controllers/rpc_controller.rb @@ -3,7 +3,8 @@ class RpcController < ApplicationController before_filter :authenticate_user! before_filter :check_global_access - + before_filter lambda { EventLog.current_controller = self }, :only => :xe_index # should be after auth callback + ## Usage example: # # require 'xmlrpc/client' @@ -11,27 +12,30 @@ class RpcController < ApplicationController # client.call("project_versions", 1) def platforms - return Platform.select('id, unixname').where("platform_type = ?", 'main').map(&:attributes) + ActiveSupport::Notifications.instrument("event_log.observer", :message => 'список платформ') + Platform.select('unixname').where("platform_type = ?", 'main').map(&:unixname) end - - def user_projects - current_user.projects.map{|pr| { :id => pr.id, :unixname => pr.unixname } } - end - - def project_versions id - pr = Project.findby_id(id) - return nil if pr.blank? - pr.project_versions.collect { |tag| [tag.name.gsub(/^\w+\./, ""), tag.name] }.select { |pv| pv[1] =~ /^v\./ } - end - - def build_status id - BuildList.find_by_id(id).try(:status) - end - - def build_packet project_id, repo_id - # TODO: build packet - end - - + def user_projects + ActiveSupport::Notifications.instrument("event_log.observer", :message => 'список пользовательских проектов') + current_user.projects.map{|p| { :id => p.id, :unixname => p.unixname } } + end + + def project_versions id + p = Project.find_by_id(id) + ActiveSupport::Notifications.instrument("event_log.observer", :object => p, :message => "список версий") + p.project_versions.collect {|tag| tag.name.gsub(/^\w+\./, "")} rescue 'not found' + end + + def build_status id + bl = BuildList.find_by_id(id) + ActiveSupport::Notifications.instrument("event_log.observer", :object => bl, :message => 'статус сборки') + bl.try(:status) || 'not found' + end + + def build_packet project_id, repo_id + # p = Project.find_by_id(project_id); r = Repository.find_by_id(repo_id) + ActiveSupport::Notifications.instrument("event_log.observer", :message => 'сборка пакета') + 'unknown' # TODO: build packet + end end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index b90d28a51..9c49d7ee6 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -32,6 +32,7 @@ class BuildList < ActiveRecord::Base BuildServer::PLATFORM_PENDING, BuildServer::PROJECT_NOT_FOUND, BuildServer::PROJECT_VERSION_NOT_FOUND, + BUILD_CANCELED, TEST_FAILD] HUMAN_STATUSES = { BuildServer::BUILD_ERROR => :build_error, @@ -43,7 +44,8 @@ class BuildList < ActiveRecord::Base BuildServer::PLATFORM_PENDING => :platform_pending, BuildServer::PROJECT_NOT_FOUND => :project_not_found, BuildServer::PROJECT_VERSION_NOT_FOUND => :project_version_not_found, - TEST_FAILD => :testing_faild + TEST_FAILD => :testing_faild, + BUILD_CANCELED => :build_canceled } scope :recent, order("created_at DESC") @@ -110,7 +112,7 @@ class BuildList < ActiveRecord::Base def delete_build_list has_canceled = BuildServer.delete_build_list bs_id - update_attribute(:status, BUILD_CANCELED) if has_canceled + update_attribute(:status, BUILD_CANCELED) if has_canceled == 0 return has_canceled == 0 end diff --git a/app/models/event_log.rb b/app/models/event_log.rb index feda49658..e69226f6c 100644 --- a/app/models/event_log.rb +++ b/app/models/event_log.rb @@ -18,9 +18,9 @@ class EventLog < ActiveRecord::Base create(attributes) do |el| el.user = current_controller.current_user el.ip = current_controller.request.remote_ip - el.protocol = 'web' # TODO pass protocol through controller or calculate by name el.controller = current_controller.class.to_s el.action = current_controller.action_name + el.protocol = (el.controller == 'RpcController' ? 'api' : 'web') end end diff --git a/app/models/personal_repository.rb b/app/models/personal_repository.rb index c9d276429..9e40975f9 100644 --- a/app/models/personal_repository.rb +++ b/app/models/personal_repository.rb @@ -14,13 +14,13 @@ module PersonalRepository pl.platform_type = 'personal' pl.distrib_type = 'mandriva2011' pl.visibility = 'open' - pl.save + pl.save! rep = pl.repositories.build rep.owner = pl.owner rep.name = 'main' rep.unixname = 'main' - rep.save + rep.save! end def personal_platform diff --git a/app/models/platform.rb b/app/models/platform.rb index e9360220a..91d2a4644 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -1,6 +1,6 @@ #require 'lib/build_server.rb' class Platform < ActiveRecord::Base - DOWNLOADS_PATH = RAILS_ROOT + '/public/downloads' + DOWNLOADS_PATH = Rails.root + '/public/downloads' VISIBILITIES = ['open', 'hidden'] relationable :as => :target diff --git a/app/models/project.rb b/app/models/project.rb index 51ea6dd79..3d3b95739 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -17,7 +17,7 @@ class Project < ActiveRecord::Base has_many :auto_build_lists, :dependent => :destroy validates :name, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :allow_nil => false, :allow_blank => false - validates :unixname, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false + validates :unixname, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ }, :allow_nil => false, :allow_blank => false validates :owner, :presence => true validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?} @@ -36,11 +36,15 @@ class Project < ActiveRecord::Base after_create :create_git_repo before_update :update_git_repo after_destroy :destroy_git_repo + after_rollback lambda { destroy_git_repo rescue true if new_record? } def project_versions - #tags.collect { |tag| [tag.name, tag.name.gsub(/^\w+\./, "")] }.select { |pv| pv[0] =~ /^v\./ } tags.select { |tag| tag.name =~ /^v\./ } end + + def collected_project_versions + project_versions.collect { |tag| new_tag = tag.name.gsub(/^\w+\./, ""); [new_tag, new_tag] } + end def tags self.git_repository.tags diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index 649f2655c..f8caddff8 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -8,14 +8,10 @@ class ProjectToRepository < ActiveRecord::Base #before_save :add_compability_link #after_destroy :remove_link #after_destroy :remove_compability_link - - after_create lambda { - project.xml_rpc_create(repository) - } - - after_destroy lambda { - project.xml_rpc_destroy(repository) - } + + after_create lambda { project.xml_rpc_create(repository) } + after_destroy lambda { project.xml_rpc_destroy(repository) } + after_rollback lambda { project.xml_rpc_destroy(repository) rescue true if new_record? } #def path # build_path(project.unixname) diff --git a/app/views/build_lists/index.html.haml b/app/views/build_lists/index.html.haml index ffde34897..9fe414890 100644 --- a/app/views/build_lists/index.html.haml +++ b/app/views/build_lists/index.html.haml @@ -11,13 +11,13 @@ %h2= t('layout.build_lists.build_server_status.header') .field %span= t('layout.build_lists.build_server_status.client_count') + ":" - %span= @build_server_status[:client_count] + %span= @build_server_status['client_count'] .field %span= t('layout.build_lists.build_server_status.count_new_task') + ":" - %span= @build_server_status[:count_new_task] + %span= @build_server_status['count_new_task'] .field %span= t('layout.build_lists.build_server_status.count_build_task') + ":" - %span= @build_server_status[:count_build_task] + %span= @build_server_status['count_build_task'] .inner = render :partial => "build_lists/filter", :action_url => @action_url diff --git a/app/views/personal_repositories/settings.html.haml b/app/views/personal_repositories/settings.html.haml index 87d73291f..13363cccb 100644 --- a/app/views/personal_repositories/settings.html.haml +++ b/app/views/personal_repositories/settings.html.haml @@ -3,13 +3,14 @@ %ul.wat-cf %li.first= link_to t("layout.personal_repositories.show"), personal_repository_path(@repository) %li.active= link_to t("layout.personal_repositories.settings"), settings_personal_repository_path(@repository) + %li= link_to t("layout.personal_repositories.private_users"), platform_private_users_path(@repository.platform) if @repository.platform.hidden? .content %h2.title= t("layout.personal_repositories.settings_header") .inner .group - %span= t("activerecord.attributes.repository.visibility") + ":" + %span= t("activerecord.attributes.platform.visibility") + ":" %span - %i= t("activerecord.attributes.repository.visibility_types.#{ @repository.platform.visibility }") + %i= t("activerecord.attributes.platform.visibility_types.#{ @repository.platform.visibility }") .group = link_to t("layout.personal_repositories.change_visibility_from_#{ @repository.platform.visibility }"), change_visibility_personal_repository_path(@repository) diff --git a/app/views/personal_repositories/show.html.haml b/app/views/personal_repositories/show.html.haml index cc705d444..a78d62d8d 100644 --- a/app/views/personal_repositories/show.html.haml +++ b/app/views/personal_repositories/show.html.haml @@ -3,6 +3,7 @@ %ul.wat-cf %li.first.active= link_to t("layout.personal_repositories.show"), personal_repository_path(@repository) %li= link_to t("layout.personal_repositories.settings"), settings_personal_repository_path(@repository) + %li= link_to t("layout.personal_repositories.private_users"), platform_private_users_path(@repository.platform) if @repository.platform.hidden? .content .inner %p @@ -19,7 +20,7 @@ %ul.wat-cf %li.first.active= link_to t("layout.projects.list"), personal_repository_path(@repository) + "#projects" %li= link_to t("layout.projects.add"), add_project_personal_repository_path(@repository) - %li= link_to t("layout.products.new"), new_platform_product_path(@repository.platform) + %li= link_to t("layout.projects.new"), new_project_path(@repository.platform) .content %h2.title = t("layout.projects.list_header") diff --git a/bin/xml-client-demo.rb b/bin/xml-client-demo.rb index f4f4ec056..056f2a9a4 100644 --- a/bin/xml-client-demo.rb +++ b/bin/xml-client-demo.rb @@ -2,36 +2,36 @@ require 'rubygems' require 'xmlrpc/client' -require 'ap' # awesome_print +require 'pp' # Please correctly fill following vars @host = 'localhost' @port = 3000 -@user = 'user@email' -@password = '' +@user = 'pchipiga@ya.ru' +@password = '123456' puts 'PLATFORMS' client = XMLRPC::Client.new(@host, '/api/xmlrpc', @port, nil, nil, @user, @password, false, 900) -ap client.call("platforms") +pp client.call("platforms") puts 'USER PROJECTS' client = XMLRPC::Client.new(@host, '/api/xmlrpc', @port, nil, nil, @user, @password, false, 900) -ap client.call("user_projects") +pp client.call("user_projects") puts 'PROJECT VERSIONS' client = XMLRPC::Client.new(@host, '/api/xmlrpc', @port, nil, nil, @user, @password, false, 900) project_id = 1 # FIXME! -ap client.call("project_versions", project_id) +pp client.call("project_versions", project_id) puts 'BUILD STATUS' client = XMLRPC::Client.new(@host, '/api/xmlrpc', @port, nil, nil, @user, @password, false, 900) build_list_id = 1 # FIXME -ap client.call("build_status", build_list_id) +pp client.call("build_status", build_list_id) puts 'BUILD PACKET' client = XMLRPC::Client.new(@host, '/api/xmlrpc', @port, nil, nil, @user, @password, false, 900) project_id = 1 # FIXME repo_id = 1 # FIXME -ap client.call("build_packet", project_id, repo_id) +pp client.call("build_packet", project_id, repo_id) puts 'DONE' \ No newline at end of file diff --git a/config/deploy.rb b/config/deploy.rb index bd1f9f48f..56d70a19b 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -18,8 +18,8 @@ set :branch, "master" set :scm, "git" set :user, "rosa" -set :domain, "195.19.76.12" # "abs.rosalab.ru" -set :port, 1822 # 222 +set :domain, "195.19.76.12" # "npp-build.rosalab.ru" +set :port, 1822 set :use_sudo, false set :deploy_to, "/srv/#{application}" @@ -43,14 +43,13 @@ end task :generate_roles do run "cd #{deploy_to}/current ; RAILS_ENV=production bundle exec rake rights:generate" - run "cd #{deploy_to}/current ; RAILS_ENV=production bundle exec rake roles:load" + #run "cd #{deploy_to}/current ; RAILS_ENV=production bundle exec rake roles:load" run "cd #{deploy_to}/current ; RAILS_ENV=production bundle exec rake roles:apply" end namespace :deploy do task :restart, :roles => :app, :except => { :no_release => true } do - ## DISABLED: run "cd #{deploy_to}/current ; ([ -f tmp/pids/unicorn.pid ] && kill -USR2 `cat tmp/pids/unicorn.pid`); true" - run ["#{current_path}/script/unicorn reload"].join("; ") + run "touch #{current_release}/tmp/restart.txt" restart_dj end @@ -61,21 +60,7 @@ namespace :deploy do run "cd #{deploy_to}/current ; RAILS_ENV=production ./script/delayed_job stop; RAILS_ENV=production ./script/delayed_job start; true" end -# desc 'Bundle and minify the JS and CSS files' -# task :build_assets, :roles => :app do -# root_path = File.expand_path(File.dirname(__FILE__) + '/..') -# assets_path = "#{root_path}/public/assets" -# envs = "RAILS_ENV=production" -# -# # Precaching assets -# run_locally "bash -c '#{envs} jammit'" -# -# # Uploading prechached assets -# top.upload assets_path, "#{current_release}/public", :via => :scp, :recursive => true -# end - after "deploy:update_code", :roles => :web do -# build_assets symlink_config_files generate_roles end diff --git a/config/locales/event_log.ru.yml b/config/locales/event_log.ru.yml index 4c90558c7..dda6cc2ef 100644 --- a/config/locales/event_log.ru.yml +++ b/config/locales/event_log.ru.yml @@ -10,6 +10,7 @@ ru: 'devise/sessions_controller': 'Аутентификация пользователей' 'devise/passwords_controller': 'Восстановление пароля' 'users/omniauth_callbacks_controller': 'Внешняя аутентификация пользователей' + rpc_controller: XML RPC actions: 'devise/sessions_controller': create: 'вход' @@ -22,6 +23,8 @@ ru: build_lists_controller: cancel: 'сборка отменена' publish: 'сборка опубликована' + rpc_controller: + xe_index: запрос create: 'создано' update: 'обновлено' destroy: 'удалено' diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 5c3c47afb..66b301db2 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -146,6 +146,7 @@ ru: change_visibility_from_open: Сменить статус на "Приватный" settings: Настройки show: Мой репозиторий + private_users: Пользователи приватного репозитория products: list: Список @@ -263,6 +264,7 @@ ru: waiting_for_response: ожидает ответа build_pending: ожидает сборку testing_faild: тестирование не пройдено + build_canceled: сборка отменена success: собран build_started: собирается platform_not_found: платформа не найдена @@ -359,6 +361,7 @@ ru: build_list: Сборочный лист build_list_item: Элемент сборочного листа download: Статистика + auto_build_list: Автоматическая пересборка пакетов attributes: auto_build_list: @@ -429,6 +432,9 @@ ru: updated_at: Обновлена distrib_type: Тип дистрибутива visibility: Статус + visibility_types: + open: Открытый + hidden: Закрытый event_log: kind: Тип события diff --git a/db/schema.rb b/db/schema.rb index 7cfc9f335..0ab0ec49d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -271,11 +271,10 @@ ActiveRecord::Schema.define(:version => 20111029150934) do create_table "users", :force => true do |t| t.string "name" - t.string "email", :default => "", :null => false - t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "reset_password_token" - t.string "remember_token" + t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" diff --git a/lib/ext/active_support/object.rb b/lib/ext/active_support/object.rb index 2f30548e0..2cbbd4918 100644 --- a/lib/ext/active_support/object.rb +++ b/lib/ext/active_support/object.rb @@ -2,7 +2,8 @@ require 'gitolito' class Object def with_ga(&block) - ::Gitolito::GitoliteAdmin.thread_safe(File.join(APP_CONFIG['root_path'], 'gitolite-admin'), {:wait_lock => true, :seconds => 30}) do |ga| + Grit::Git.git_timeout = 60 + ::Gitolito::GitoliteAdmin.thread_safe(File.join(APP_CONFIG['root_path'], 'gitolite-admin'), {:wait_lock => true, :seconds => 60}) do |ga| block.call(ga) end # ga = Gitolito::GitoliteAdmin.new File.join(APP_CONFIG['root_path'], 'gitolite-admin'); block.call(ga) diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 5591dd6a0..51b26e19b 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -6,8 +6,10 @@ namespace :import do print "Import #{name}..." owner = User.find(2) # vsharshov@gmail.com # owner = Group.find(1) # Core Team - puts Project.create(:name => name, :unixname => name) {|p| p.owner = owner} ? "Ok!" : "Fail!" - sleep 1 + # puts Project.create(:name => name, :unixname => name) {|p| p.owner = owner} ? "Ok!" : "Fail" + p = Project.find_or_create_by_name_and_unixname(name, name) {|p| p.owner = owner} + puts p.persisted? ? "Ok!" : "Fail!" + # sleep 1 end puts 'DONE' end