[refs #461] Merge master into 461-rename_is_rpm_to_is_package

This commit is contained in:
konstantin.grabar 2012-05-16 14:37:35 +04:00
commit 1385133ed5
17 changed files with 253 additions and 70 deletions

View File

@ -112,6 +112,8 @@ class Projects::BuildListsController < Projects::BaseController
@build_list.container_path = params[:container_path] @build_list.container_path = params[:container_path]
@build_list.save @build_list.save
@build_list.set_packages(ActiveSupport::JSON.decode(params[:pkg_info])) if params[:status].to_i == BuildServer::SUCCESS and params[:pkg_info].present?
render :nothing => true, :status => 200 render :nothing => true, :status => 200
end end

View File

@ -64,7 +64,8 @@ class Ability
can [:read, :related], BuildList, :project => {:owner_type => 'User', :owner_id => user.id} can [:read, :related], BuildList, :project => {:owner_type => 'User', :owner_id => user.id}
can [:read, :related], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids} can [:read, :related], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids}
can(:read, BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project} can(:read, BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
can(:create, BuildList) {|build_list| build_list.project.is_package && can?(:write, build_list.project)} can([:create, :update], BuildList) {|build_list| build_list.project.is_rpm && can?(:write, build_list.project)}
can(:publish, BuildList) do |build_list| can(:publish, BuildList) do |build_list|
build_list.can_publish? and build_list.save_to_platform.released ? local_admin?(build_list.save_to_platform) : can?(:write, build_list.project) build_list.can_publish? and build_list.save_to_platform.released ? local_admin?(build_list.save_to_platform) : can?(:write, build_list.project)
end end

View File

@ -5,16 +5,15 @@ class BuildList < ActiveRecord::Base
belongs_to :save_to_platform, :class_name => 'Platform' belongs_to :save_to_platform, :class_name => 'Platform'
belongs_to :build_for_platform, :class_name => 'Platform' belongs_to :build_for_platform, :class_name => 'Platform'
belongs_to :user belongs_to :user
has_many :items, :class_name => "BuildList::Item", :dependent => :destroy
belongs_to :advisory belongs_to :advisory
has_many :items, :class_name => "BuildList::Item", :dependent => :destroy
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
validates :project_id, :project_version, :arch, :include_repos, :presence => true
validates_numericality_of :priority, :greater_than_or_equal_to => 0
UPDATE_TYPES = %w[security bugfix enhancement recommended newpackage] UPDATE_TYPES = %w[security bugfix enhancement recommended newpackage]
RELEASE_UPDATE_TYPES = %w[security bugfix] RELEASE_UPDATE_TYPES = %w[security bugfix]
validates :project_id, :project_version, :arch, :include_repos, :presence => true
validates_numericality_of :priority, :greater_than_or_equal_to => 0
validates :update_type, :inclusion => UPDATE_TYPES, validates :update_type, :inclusion => UPDATE_TYPES,
:unless => Proc.new { |b| b.save_to_platform.released } :unless => Proc.new { |b| b.save_to_platform.released }
validates :update_type, :inclusion => RELEASE_UPDATE_TYPES, validates :update_type, :inclusion => RELEASE_UPDATE_TYPES,
@ -71,7 +70,6 @@ class BuildList < ActiveRecord::Base
} }
scope :recent, order("#{table_name}.updated_at DESC") scope :recent, order("#{table_name}.updated_at DESC")
scope :for_status, lambda {|status| where(:status => status) } scope :for_status, lambda {|status| where(:status => status) }
scope :for_user, lambda { |user| where(:user_id => user.id) } scope :for_user, lambda { |user| where(:user_id => user.id) }
scope :scoped_to_arch, lambda {|arch| where(:arch_id => arch) } scope :scoped_to_arch, lambda {|arch| where(:arch_id => arch) }
@ -90,7 +88,6 @@ class BuildList < ActiveRecord::Base
s s
} }
scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%")} scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%")}
scope :outdated, where('updated_at < ? AND status <> ?', Time.now - LIVE_TIME, BUILD_PUBLISHED) scope :outdated, where('updated_at < ? AND status <> ?', Time.now - LIVE_TIME, BUILD_PUBLISHED)
serialize :additional_repos serialize :additional_repos
@ -117,6 +114,13 @@ class BuildList < ActiveRecord::Base
end end
end end
def set_packages(pkg_hash)
build_package(pkg_hash['srpm'], 'source') {|p| p.save!}
pkg_hash['rpm'].each do |rpm_hash|
build_package(rpm_hash, 'binary') {|p| p.save!}
end
end
def publish def publish
return false unless can_publish? return false unless can_publish?
has_published = BuildServer.publish_container bs_id has_published = BuildServer.publish_container bs_id
@ -170,18 +174,26 @@ class BuildList < ActiveRecord::Base
#[WAITING_FOR_RESPONSE, BuildServer::BUILD_PENDING, BuildServer::BUILD_STARTED].include?(status) #[WAITING_FOR_RESPONSE, BuildServer::BUILD_PENDING, BuildServer::BUILD_STARTED].include?(status)
end end
private protected
def set_default_status
self.status = WAITING_FOR_RESPONSE unless self.status.present?
return true
end
def place_build def set_default_status
#XML-RPC params: project_name, project_version, plname, arch, bplname, update_type, build_requires, id_web, include_repos, priority self.status = WAITING_FOR_RESPONSE unless self.status.present?
self.status = BuildServer.add_build_list project.name, project_version, save_to_platform.name, arch.name, (save_to_platform_id == build_for_platform_id ? '' : build_for_platform.name), update_type, build_requires, id, include_repos, priority return true
self.status = BUILD_PENDING if self.status == 0 end
save
end
#handle_asynchronously :place_build
def place_build
#XML-RPC params: project_name, project_version, plname, arch, bplname, update_type, build_requires, id_web, include_repos, priority
self.status = BuildServer.add_build_list project.name, project_version, save_to_platform.name, arch.name, (save_to_platform_id == build_for_platform_id ? '' : build_for_platform.name), update_type, build_requires, id, include_repos, priority
self.status = BUILD_PENDING if self.status == 0
save
end
def build_package(pkg_hash, package_type)
packages.create(pkg_hash) do |p|
p.project = Project.joins(:repositories => :platform).where('platforms.id = ?', save_to_platform.id).find_by_name!(pkg_hash['name'])
p.platform = save_to_platform
p.package_type = package_type
yield p
end
end
end end

View File

@ -0,0 +1,12 @@
class BuildList::Package < ActiveRecord::Base
PACKAGE_TYPES = %w(source binary)
belongs_to :build_list
belongs_to :project
belongs_to :platform
attr_accessible :fullname, :name, :release, :version
validates :build_list_id, :project_id, :platform_id, :fullname, :package_type, :name, :release, :version, :presence => true
validates :package_type, :inclusion => PACKAGE_TYPES
end

View File

@ -15,6 +15,8 @@ class Platform < ActiveRecord::Base
has_and_belongs_to_many :advisories has_and_belongs_to_many :advisories
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
validates :description, :presence => true validates :description, :presence => true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES} validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ } validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }

View File

@ -2,6 +2,7 @@
class Project < ActiveRecord::Base class Project < ActiveRecord::Base
VISIBILITIES = ['open', 'hidden'] VISIBILITIES = ['open', 'hidden']
MAX_OWN_PROJECTS = 32000 MAX_OWN_PROJECTS = 32000
NAME_REGEXP = /[a-zA-Z0-9_\-\+\.]+/
belongs_to :owner, :polymorphic => true, :counter_cache => :own_projects_count belongs_to :owner, :polymorphic => true, :counter_cache => :own_projects_count
@ -17,9 +18,10 @@ class Project < ActiveRecord::Base
has_many :collaborators, :through => :relations, :source => :actor, :source_type => 'User' has_many :collaborators, :through => :relations, :source => :actor, :source_type => 'User'
has_many :groups, :through => :relations, :source => :actor, :source_type => 'Group' has_many :groups, :through => :relations, :source => :actor, :source_type => 'Group'
has_many :advisories has_many :advisories # should be without :dependent => :destroy
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^[a-zA-Z0-9_\-\+\.]+$/} validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^#{NAME_REGEXP}$/}
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 }

View File

@ -18,11 +18,11 @@
.rightlist .rightlist
= link_to @build_list.user.try(:fullname), @build_list.user = link_to @build_list.user.try(:fullname), @build_list.user
.both .both
.leftlist= t("activerecord.attributes.build_list.bpl") .leftlist= t("activerecord.attributes.build_list.build_for_platform")
.rightlist .rightlist
= link_to @build_list.build_for_platform.name, @build_list.build_for_platform = link_to @build_list.build_for_platform.name, @build_list.build_for_platform
.both .both
.leftlist= t("activerecord.attributes.build_list.pl") .leftlist= t("activerecord.attributes.build_list.save_to_platform")
.rightlist .rightlist
= link_to @build_list.save_to_platform.name, @build_list.save_to_platform = link_to @build_list.save_to_platform.name, @build_list.save_to_platform
.both .both
@ -102,6 +102,25 @@
%td= item.human_status %td= item.human_status
.both .both
- if @build_list.packages.present?
.hr
%h3= t("layout.build_lists.packages_header")
%table.tablesorter.width565{:cellpadding => "0", :cellspacing => "0"}
%thead
%tr
%th= t("activerecord.attributes.build_list/package.fullname")
%th= t("activerecord.attributes.build_list/package.name")
%th= t("activerecord.attributes.build_list/package.version")
%th= t("activerecord.attributes.build_list/package.release")
%tbody
- @build_list.packages.each do |package|
%tr
%td= package.fullname
%td= package.name
%td= package.version
%td= package.release
.both
:javascript :javascript
$('article .all').addClass('bigpadding'); $('article .all').addClass('bigpadding');

View File

@ -36,6 +36,12 @@ en:
version: Version version: Version
build_list: Build list build_list: Build list
build_list/package:
name: Name
fullname: Fullname
release: Release
version: Version
layout: layout:
build_lists: build_lists:
filter_header: Filter filter_header: Filter
@ -48,6 +54,7 @@ en:
project_name_search: Search by project name project_name_search: Search by project name
bs_id_not_set: Id has not been configured yet bs_id_not_set: Id has not been configured yet
items_header: Build items items_header: Build items
packages_header: Container data
no_items_data: No data no_items_data: No data
show: Show show: Show
cancel_success: 'Build canceled' cancel_success: 'Build canceled'

View File

@ -35,6 +35,12 @@ ru:
version: Версия version: Версия
build_list: Сборочный лист build_list: Сборочный лист
build_list/package:
name: Название
fullname: Полное имя
release: Релиз
version: Версия
layout: layout:
build_lists: build_lists:
filter_header: Фильтр filter_header: Фильтр
@ -47,6 +53,7 @@ ru:
project_name_search: Поиск по названию проекта project_name_search: Поиск по названию проекта
bs_id_not_set: Id еще не присвоен bs_id_not_set: Id еще не присвоен
items_header: Элементы сборки items_header: Элементы сборки
packages_header: Данные о контейнере
no_items_data: Данных нет no_items_data: Данных нет
show: Просмотр show: Просмотр
cancel_success: 'Сборка отменена.' cancel_success: 'Сборка отменена.'

View File

@ -3,23 +3,26 @@ en:
'Editing' 'Editing'
at: at at: at
users: users:
profile: settings:
title: 'Your Profile' profile:
build_lists: title: 'Your Profile'
index: projects:
title: 'Projects Monitoring' build_lists:
product_build_lists:
index:
title: 'Products Monitoring'
git:
commits:
index: index:
title: 'Commit History' title: 'Projects Monitoring'
issues: git:
index: commits:
title: 'Tracker' index:
wiki: title: 'Commit History'
compare: issues:
title: 'Compare Revisions' index:
searching: title: 'Tracker'
title: 'Search in Wiki' wiki:
compare:
title: 'Compare Revisions'
searching:
title: 'Search in Wiki'
platforms:
product_build_lists:
index:
title: 'Products Monitoring'

View File

@ -3,23 +3,26 @@ ru:
'Редактирование' 'Редактирование'
at: at at: at
users: users:
profile: settings:
title: 'Ваш профиль' profile:
build_lists: title: 'Ваш профиль'
index: projects:
title: 'Мониторинг проектов' build_lists:
product_build_lists:
index:
title: 'Мониторинг продуктов'
git:
commits:
index: index:
title: 'История коммитов' title: 'Мониторинг проектов'
issues: git:
index: commits:
title: 'Трекер' index:
wiki: title: 'История коммитов'
compare: issues:
title: 'Сравнение версий' index:
searching: title: 'Трекер'
title: 'Поиск в вики' wiki:
compare:
title: 'Сравнение версий'
searching:
title: 'Поиск в вики'
platforms:
product_build_lists:
index:
title: 'Мониторинг продуктов'

View File

@ -118,7 +118,7 @@ Rosa::Application.routes.draw do
resources :projects, :only => [:index, :new, :create] resources :projects, :only => [:index, :new, :create]
scope ':owner_name/:project_name' do # project scope ':owner_name/:project_name', :constraints => {:project_name => Project::NAME_REGEXP} do # project
scope :as => 'project' do scope :as => 'project' do
resources :wiki do resources :wiki do
collection do collection do

View File

@ -0,0 +1,19 @@
class CreateBuildListPackages < ActiveRecord::Migration
def change
create_table :build_list_packages do |t|
t.references :build_list
t.references :project
t.references :platform
t.string :fullname
t.string :name
t.string :version
t.string :release
t.string :package_type
t.timestamps
end
add_index :build_list_packages, :build_list_id
add_index :build_list_packages, :project_id
add_index :build_list_packages, :platform_id
end
end

View File

@ -75,6 +75,23 @@ ActiveRecord::Schema.define(:version => 20120515095324) do
add_index "build_list_items", ["build_list_id"], :name => "index_build_list_items_on_build_list_id" add_index "build_list_items", ["build_list_id"], :name => "index_build_list_items_on_build_list_id"
create_table "build_list_packages", :force => true do |t|
t.integer "build_list_id"
t.integer "project_id"
t.integer "platform_id"
t.string "fullname"
t.string "name"
t.string "version"
t.string "release"
t.string "package_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "build_list_packages", ["build_list_id"], :name => "index_build_list_packages_on_build_list_id"
add_index "build_list_packages", ["platform_id"], :name => "index_build_list_packages_on_platform_id"
add_index "build_list_packages", ["project_id"], :name => "index_build_list_packages_on_project_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"

View File

@ -344,10 +344,28 @@ describe Projects::BuildListsController do
end end
describe 'status_build' do describe 'status_build' do
before { @item = build_list.items.create(:name => build_list.project.name, :version => build_list.project_version, :level => 0) } before do
@item = build_list.items.create(:name => build_list.project.name, :version => build_list.project_version, :level => 0)
repo = build_list.save_to_platform.repositories.first
repo.projects << build_list.project
@project2 = FactoryGirl.create(:project)
repo.projects << @project2
end
def do_get def do_get
get :status_build, :id => build_list.bs_id, :package_name => build_list.project.name, :status => BuildServer::SUCCESS, :container_path => '/path/to' get :status_build, :id => build_list.bs_id, :package_name => build_list.project.name, :status => BuildServer::SUCCESS, :container_path => '/path/to',
:pkg_info => ActiveSupport::JSON.encode({'srpm' => {'fullname' => 'srpm_filename.srpm',
'name' => build_list.project.name,
'version' => 'version1',
'release' => 'release1'},
'rpm' => [{'fullname' => 'filename1.rpm',
'name' => build_list.project.name,
'version' => 'version2',
'release' => 'release2'},
{'fullname' => 'filename2.rpm',
'name' => @project2.name,
'version' => 'version2',
'release' => 'release2'}]})
build_list.reload build_list.reload
@item.reload @item.reload
end end
@ -356,6 +374,19 @@ describe Projects::BuildListsController do
it { lambda{ do_get }.should change(@item, :status) } it { lambda{ do_get }.should change(@item, :status) }
it { lambda{ do_get }.should change(build_list, :container_path) } it { lambda{ do_get }.should change(build_list, :container_path) }
it { lambda{ do_get }.should change(build_list, :updated_at) } it { lambda{ do_get }.should change(build_list, :updated_at) }
it('should create packages for build list') { lambda{ do_get }.should change(build_list.packages, :count).to(3) }
it 'should create correct packages for build list' do
do_get
package = build_list.packages.order('created_at ASC').first
package.fullname.should == 'srpm_filename.srpm'
package.name.should == build_list.project.name
package.version.should == 'version1'
package.release.should == 'release1'
package.package_type == 'source'
package.build_list.should == build_list
package.platform.should == build_list.save_to_platform
package.project.should == build_list.project
end
end end
describe 'pre_build' do describe 'pre_build' do

View File

@ -12,20 +12,20 @@ describe Projects::Git::TreesController do
@project = FactoryGirl.create(:project) @project = FactoryGirl.create(:project)
@another_user = FactoryGirl.create(:user) @another_user = FactoryGirl.create(:user)
@params = {:owner_name => @project.owner.uname, :project_name => @project.name, :format => 'tar'} @params = {:owner_name => @project.owner.uname, :project_name => @project.name}
end end
context 'for guest' do context 'for guest' do
if APP_CONFIG['anonymous_access'] if APP_CONFIG['anonymous_access']
it 'should be able to perform archive action with anonymous acccess' do it 'should be able to perform archive action with anonymous acccess' do
fill_project fill_project
get :archive, @params get :archive, @params.merge(:format => 'tar')
response.should be_success response.should be_success
end end
else else
it 'should not be able to perform archive action without anonymous acccess' do it 'should not be able to perform archive action without anonymous acccess' do
fill_project fill_project
get :archive, @params get :archive, @params.merge(:format => 'tar')
response.code.should == '401' response.code.should == '401'
end end
end end
@ -35,7 +35,7 @@ describe Projects::Git::TreesController do
it 'should not be able to archive empty project' do it 'should not be able to archive empty project' do
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
set_session_for(@user) set_session_for(@user)
expect { get :archive, @params }.to raise_error(ActiveRecord::RecordNotFound) expect { get :archive, @params.merge(:format => 'tar') }.to raise_error(ActiveRecord::RecordNotFound)
end end
it 'should not be able to injection code with format' do it 'should not be able to injection code with format' do
@ -56,7 +56,7 @@ describe Projects::Git::TreesController do
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
set_session_for(@user) set_session_for(@user)
fill_project fill_project
get :archive, @params get :archive, @params.merge(:format => 'tar')
response.should be_success response.should be_success
end end
end end

View File

@ -0,0 +1,46 @@
# -*- encoding : utf-8 -*-
require "spec_helper"
describe Projects::ProjectsController do
describe "routing" do
it "routes to #index" do
get("/projects").should route_to("projects/projects#index")
end
it "routes to #new" do
get("/projects/new").should route_to("projects/projects#new")
end
it "routes to #edit" do
get("/import/glib2.0-mib/edit").should route_to("projects/projects#edit", :owner_name => 'import', :project_name => 'glib2.0-mib')
end
it "routes to #create" do
post("/projects").should route_to("projects/projects#create")
end
it "routes to #update" do
put("/import/glib2.0-mib").should route_to("projects/projects#update", :owner_name => 'import', :project_name => 'glib2.0-mib')
end
it "routes to #destroy" do
delete("/import/glib2.0-mib").should route_to("projects/projects#destroy", :owner_name => 'import', :project_name => 'glib2.0-mib')
end
end
end
describe Projects::Git::TreesController do
describe "routing" do
it "routes to #show" do
get("/import/glib2.0-mib").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib')
get("/import/glib2.0-mib/tree/branch").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch')
get("/import/glib2.0-mib/tree/branch/some/path.to").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch', :path => 'some/path.to')
end
# TODO write more specs also with slash in branch name!
end
end