Apply basic build list packages store functionality. Display build list package content. Write specs. Refactor. Refs #444

This commit is contained in:
Pavel Chipiga 2012-05-14 22:08:31 +03:00
parent b7dee0b6af
commit 8470674c62
11 changed files with 141 additions and 23 deletions

View File

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

View File

@ -5,16 +5,15 @@ class BuildList < ActiveRecord::Base
belongs_to :save_to_platform, :class_name => 'Platform'
belongs_to :build_for_platform, :class_name => 'Platform'
belongs_to :user
has_many :items, :class_name => "BuildList::Item", :dependent => :destroy
belongs_to :advisory
validates :project_id, :project_version, :arch, :include_repos, :presence => true
validates_numericality_of :priority, :greater_than_or_equal_to => 0
has_many :items, :class_name => "BuildList::Item", :dependent => :destroy
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
UPDATE_TYPES = %w[security bugfix enhancement recommended newpackage]
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,
:unless => Proc.new { |b| b.save_to_platform.released }
validates :update_type, :inclusion => RELEASE_UPDATE_TYPES,
@ -71,7 +70,6 @@ class BuildList < ActiveRecord::Base
}
scope :recent, order("#{table_name}.updated_at DESC")
scope :for_status, lambda {|status| where(:status => status) }
scope :for_user, lambda { |user| where(:user_id => user.id) }
scope :scoped_to_arch, lambda {|arch| where(:arch_id => arch) }
@ -90,7 +88,6 @@ class BuildList < ActiveRecord::Base
s
}
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)
serialize :additional_repos
@ -117,6 +114,13 @@ class BuildList < ActiveRecord::Base
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
return false unless can_publish?
has_published = BuildServer.publish_container bs_id
@ -170,18 +174,27 @@ class BuildList < ActiveRecord::Base
#[WAITING_FOR_RESPONSE, BuildServer::BUILD_PENDING, BuildServer::BUILD_STARTED].include?(status)
end
private
def set_default_status
self.status = WAITING_FOR_RESPONSE unless self.status.present?
return true
end
protected
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
#handle_asynchronously :place_build
def set_default_status
self.status = WAITING_FOR_RESPONSE unless self.status.present?
return true
end
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
#handle_asynchronously :place_build
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

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_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
validates :description, :presence => true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }

View File

@ -18,7 +18,8 @@ class Project < ActiveRecord::Base
has_many :collaborators, :through => :relations, :source => :actor, :source_type => 'User'
has_many :groups, :through => :relations, :source => :actor, :source_type => 'Group'
has_many :advisories
has_many :advisories, :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 => /^#{NAME_REGEXP}$/}
validates :owner, :presence => true

View File

@ -102,6 +102,25 @@
%td= item.human_status
.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
$('article .all').addClass('bigpadding');

View File

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

View File

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

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

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120505101650) do
ActiveRecord::Schema.define(:version => 20120512102707) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -75,6 +75,23 @@ ActiveRecord::Schema.define(:version => 20120505101650) do
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|
t.integer "bs_id"
t.string "container_path"

View File

@ -344,10 +344,28 @@ describe Projects::BuildListsController do
end
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
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
@item.reload
end
@ -356,6 +374,7 @@ describe Projects::BuildListsController do
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, :updated_at) }
it('should create packages for build list') { lambda{ do_get }.should change(build_list.packages, :count).to(3) }
end
describe 'pre_build' do