[refs #1832] Build Lists updates. Project updates and fixes.

This commit is contained in:
konstantin.grabar 2011-10-22 19:28:41 +04:00
parent 310f588621
commit c24a9fae1b
18 changed files with 284 additions and 149 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ config/initializers/local.rb
public/system/*
.rvmrc
*.swp
*.tmproj

View File

@ -4,19 +4,43 @@ class BuildListsController < ApplicationController
before_filter :find_platform, :only => [:index, :filter, :show, :publish]
before_filter :find_repository, :only => [:index, :filter, :show, :publish]
before_filter :find_project, :only => [:index, :filter, :show, :publish]
before_filter :find_arches, :only => [:index, :filter]
before_filter :find_arches, :only => [:index, :filter, :all]
before_filter :find_branches, :only => [:index, :filter]
before_filter :find_build_list_by_bs, :only => [:status_build, :pre_build, :post_build]
def all
if params[:filter]
@filter = BuildList::Filter.new(nil, params[:filter])
@build_lists = @filter.find.paginate :page => params[:page]
else
@filter = BuildList::Filter.new(nil)
@build_lists = BuildList.paginate :page => params[:page]
end
@action_url = all_build_lists_path
render :action => 'index'
end
def cancel
build_list = BuildList.find(params[:id])
if build_list.delete_build_list
redirect_to :back, :notice => t('layout.build_lists.cancel_successed')
else
redirect_to :back, :notice => t('layout.build_lists.cancel_failed')
end
end
def index
@build_lists = @project.build_lists.recent.paginate :page => params[:page]
@filter = BuildList::Filter.new(@project)
@action_url = filter_platform_repository_project_build_lists_path(@platform, @repository, @project)
end
def filter
@filter = BuildList::Filter.new(@project, params[:filter])
@build_lists = @filter.find.paginate :page => params[:page]
@action_url = filter_platform_repository_project_build_lists_path(@platform, @repository, @project)
render :action => "index"
end

View File

@ -16,6 +16,8 @@ class ProjectsController < ApplicationController
def build
@branches = @project.git_repository.branches
@arches = Arch.recent
@pls = Platform.main
@bpls = @project.repositories.collect { |rep| ["#{rep.platform.name}/#{rep.unixname}", rep.platform.id] }
end
def process_build
@ -25,22 +27,29 @@ class ProjectsController < ApplicationController
@branches = @project.git_repository.branches
@branch = @branches.select{|branch| branch.name == params[:build][:branch] }.first
@pls_ids = params[:build][:pls].select{|_,v| v == "1"}.collect{|x| x[0].to_i }
@pls = Platform.where(:id => @pls_ids)
@bpl = Platform.find params[:bpl]
if !check_arches || !check_branches
@arches = Arch.recent
render :action => "build"
else
flash[:notice], flash[:error] = "", ""
@arches.each do |arch|
build_list = @project.build_lists.new(:arch => arch, :branch_name => @branch.name)
@pls.each do |pl|
build_list = @project.build_lists.new(:arch => arch, :project_version => @branch.name, :pl => pl, :bpl => @bpl)
if build_list.save
flash[:notice] += t("flash.build_list.saved", :branch_name => @branch.name, :arch => arch.name)
flash[:notice] += t("flash.build_list.saved", :branch_name => @branch.name, :arch => arch.name, :pl => pl, :bpl => @bpl)
else
flash[:error] += t("flash.build_list.save_error", :branch_name => @branch.name, :arch => arch.name)
flash[:error] += t("flash.build_list.save_error", :branch_name => @branch.name, :arch => arch.name, :pl => pl, :bpl => @bpl)
end
end
end
redirect_to platform_repository_project_path(@platform, @repository, @project)
redirect_to project_path(@project)
end
end
@ -62,7 +71,8 @@ class ProjectsController < ApplicationController
@project.destroy
flash[:notice] = t("flash.project.destroyed")
redirect_to platform_repository_path(@platform, @repository)
#redirect_to platform_repository_path(@platform, @repository)
redirect_to root_path
end
protected
@ -82,14 +92,6 @@ class ProjectsController < ApplicationController
end
end
def find_platform
@platform = Platform.find params[:platform_id]
end
def find_repository
@repository = @platform.repositories.find(params[:repository_id])
end
def find_project
@project = Project.find params[:id]
end

View File

@ -1,11 +1,23 @@
class BuildList < ActiveRecord::Base
belongs_to :project
belongs_to :arch
belongs_to :pl, :class_name => 'Platform'
belongs_to :bpl, :class_name => 'Platform'
has_many :items, :class_name => "BuildList::Item", :dependent => :destroy
validates :project_id, :presence => true
validates :branch_name, :presence => true
validates :project_version, :presence => true
#validates_inclusion_of :update_type, :in => UPDATE_TYPES#, :message => "extension %s is not included in the list"
UPDATE_TYPES = %w[security bugfix enhancement recommended newpackage]
validates :update_type, :inclusion => UPDATE_TYPES
validate lambda {
errors.add(:pl, I18n.t('flash.build_list.wrong_platform')) if bpl.platform_type == 'main' && pl_id != bpl_id
}
BUILD_CANCELED = 5000
WAITING_FOR_RESPONSE = 4000
BUILD_PENDING = 2000
BUILD_STARTED = 3000
@ -38,7 +50,7 @@ class BuildList < ActiveRecord::Base
}
scope :for_status, lambda {|status| where(:status => status) }
scope :scoped_to_arch, lambda {|arch| where(:arch_id => arch) }
scope :scoped_to_branch, lambda {|branch| where(:branch_name => branch) }
scope :scoped_to_branch, lambda {|branch| where(:project_version => branch) }
scope :scoped_to_is_circle, lambda {|is_circle| where(:is_circle => is_circle) }
scope :for_creation_date_period, lambda{|start_date, end_date|
if start_date && end_date
@ -93,6 +105,18 @@ class BuildList < ActiveRecord::Base
self.status == BuildServer::SUCCESS
end
def delete_build_list
has_canceled = BuildServer.delete_build_list bs_id
update_attribute(:status, BUILD_CANCELED) if has_canceled
return has_canceled == 0
end
#TODO: Share this checking on product owner.
def can_canceled?
self.status == BUILD_PENDING
end
private
def set_default_status
self.status = WAITING_FOR_RESPONSE unless self.status.present?
@ -100,7 +124,8 @@ class BuildList < ActiveRecord::Base
end
def place_build
self.status = BuildServer.add_build_list project.name, branch_name, project.repository.platform.name, arch.name, id
#XML-RPC params: project_name, project_version, plname, arch, bplname, update_type, build_requires, id_web
self.status = BuildServer.add_build_list project.name, project_version, pl.unixname, arch.name, bpl.unixname, update_type, build_requires, id
self.status = BUILD_PENDING if self.status == 0
save
end

View File

@ -7,11 +7,15 @@ class BuildList::Filter
end
def find
if @project.nil?
build_lists = BuildList.scoped
else
build_lists = @project.build_lists.recent
end
build_lists = build_lists.for_status(@options[:status]) if @options[:status]
build_lists = build_lists.scoped_to_arch(@options[:arch_id]) if @options[:arch_id]
build_lists = build_lists.scoped_to_branch(@options[:branch_name]) if @options[:branch_name]
build_lists = build_lists.scoped_to_branch(@options[:project_version]) if @options[:project_version]
build_lists = build_lists.scoped_to_is_circle(@options[:is_circle]) if @options[:is_circle].present?
if @options[:created_at_start] || @options[:created_at_end]
@ -44,7 +48,7 @@ class BuildList::Filter
:notified_at_end => nil,
:arch_id => nil,
:is_circle => nil,
:branch_name => nil
:project_version => nil
}))
@options[:status] = @options[:status].present? ? @options[:status].to_i : nil
@ -52,7 +56,7 @@ class BuildList::Filter
@options[:created_at_end] = build_date_from_params(:created_at_end, @options)
@options[:notified_at_start] = build_date_from_params(:notified_at_start, @options)
@options[:notified_at_end] = build_date_from_params(:notified_at_end, @options)
@options[:branch_name] = @options[:branch_name].present? ? @options[:branch_name] : nil
@options[:project_version] = @options[:project_version].present? ? @options[:project_version] : nil
@options[:arch_id] = @options[:arch_id].present? ? @options[:arch_id].to_i : nil
@options[:is_circle] = @options[:is_circle].present? ? @options[:is_circle] == "1" : nil
end

View File

@ -21,6 +21,7 @@ class Platform < ActiveRecord::Base
# before_destroy :xml_rpc_destroy
# before_update :check_freezing
scope :main, where(:platform_type => 'main')
def path
build_path(unixname)

View File

@ -32,7 +32,7 @@ class Project < ActiveRecord::Base
# Redefining a method from Project::HasRepository module to reflect current situation
def git_repo_path
@git_repo_path ||= File.join(repository.platform.path, "projects", unixname + ".git")
@git_repo_path ||= File.join("#{APP_CONFIG['git_projects_path']}/#{owner.uname}/#{self.unixname}.git")
end
def path
@ -64,8 +64,10 @@ class Project < ActiveRecord::Base
end
end
#TODO: Remove it from code if git_repo_path and build_path (or path) have the same purpose
def build_path(dir)
File.join(APP_CONFIG['root_path'], 'projects', dir)
#File.join(APP_CONFIG['root_path'], 'projects', dir)
File.join("#{APP_CONFIG['git_projects_path']}/#{owner.uname}/#{dir}.git")
end
def create_directory

View File

@ -2,20 +2,24 @@
%tr
%th.first= t("activerecord.attributes.build_list.bs_id")
%th= t("activerecord.attributes.build_list.status")
%th= t("activerecord.attributes.build_list.branch_name")
%th= t("activerecord.attributes.build_list.project_version")
%th= t("activerecord.attributes.build_list.project")
%th= t("activerecord.attributes.build_list.arch")
%th= t("activerecord.attributes.build_list.is_circle")
- if controller.action_name = 'all'
%th= t("layout.build_lists.cancel_button_header")
%th.last= t("activerecord.attributes.build_list.notified_at")
- build_lists.each do |build_list|
%tr{:class => cycle("odd", "even")}
%td= link_to (build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")), platform_repository_project_build_list_path(@platform, @repository, @project, build_list)
%td= link_to (build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")), project_build_list_path(build_list.project, build_list)
%td= build_list.human_status
%td= link_to build_list.branch_name, "#"
%td= link_to build_list.project.name, platform_repository_project_path(@platform, @repository, @project)
%td= link_to build_list.project_version, "#"
%td= link_to build_list.project.name, project_path(build_list.project)
%td= build_list.arch.name
%td= t("layout.#{build_list.is_circle?}_")
- if controller.action_name = 'all'
%td= link_to t("layout.build_lists.cancel_button"), build_list_cancel_path(build_list) if build_list.can_canceled?
%td.last= build_list.notified_at
= will_paginate build_lists

View File

@ -1,6 +1,6 @@
%h2.title= t("layout.build_lists.filter_header")
= form_for :filter, :url => filter_platform_repository_project_build_lists_path(@platform, @repository, @project) , :html => { :method => :post, :class => :form } do |f|
= form_for :filter, :url => @action_url, :html => { :method => :post, :class => :form } do |f|
.columns.wat-cf
.column.left
@ -13,10 +13,10 @@
= f.select :arch_id, @arches.collect{|arch| [arch.name, arch.id]}, :include_blank => true, :selected => @filter.arch_id
.column.right
- if @branches
.group
= f.label :branch_name, "Branch", :class => :label
= f.select :branch_name, @branches.collect{|branch| [branch.name, branch.name]}, :include_blank => true, :selected => @filter.branch_name
= f.label :project_version, "Branch", :class => :label
= f.select :project_version, @branches.collect{|branch| [branch.name, branch.name]}, :include_blank => true, :selected => @filter.project_version
.group
= f.label :is_circle, t("activerecord.attributes.build_list.is_circle"), :class => :label

View File

@ -1,4 +1,5 @@
.block
- if controller.action_name != 'all'
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.build_lists.current"), platform_repository_project_path(@platform, @repository, @project) + "#build_lists"
@ -7,9 +8,9 @@
.content
.inner
= render :partial => "build_lists/filter"
= render :partial => "build_lists/filter", :action_url => @action_url
.inner
= render :partial => "build_lists/build_lists", :object => @build_lists
- content_for :sidebar, render(:partial => 'sidebar')
- content_for :sidebar, render(:partial => 'sidebar') if controller.action_name != 'all'

View File

@ -29,9 +29,9 @@
= @build_list.human_status
%p
%b
= t("activerecord.attributes.build_list.branch_name")
= t("activerecord.attributes.build_list.project_version")
\:
= @build_list.branch_name
= @build_list.project_version
%p
%b
= t("activerecord.attributes.build_list.project")

View File

@ -1,23 +1,39 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.projects.list"), platform_repository_path(@platform, @repository) + "#projects"
%li= link_to t("layout.projects.new"), new_platform_repository_project_path(@platform, @repository)
%li= link_to t("layout.projects.show"), platform_repository_project_path(@platform, @repository, @project)
%li= link_to "git-repo", platform_repository_project_repo_path(@platform, @repository, @project)
%li.active= link_to t("layout.projects.build"), build_platform_repository_project_path(@platform, @repository, @project)
%li.first=# link_to t("layout.projects.list"), platform_repository_path(@platform, @repository) + "#projects"
%li= link_to t("layout.projects.new"), new_project_path
%li= link_to t("layout.projects.show"), project_path(@project)
%li=# link_to "git-repo", project_repo_path(@platform, @repository, @project)
%li.active= link_to t("layout.projects.build"), build_project_path(@project)
.content
%h2.title= t("layout.projects.new_build")
.inner
= form_for :build, :url => process_build_platform_repository_project_path(@platform, @repository, @project), :html => { :class => :form, :method => :post } do |f|
= form_for :build, :url => process_build_project_path(@project), :html => { :class => :form, :method => :post } do |f|
.columns.wat-cf
.column.left
.group
= f.label :branch, "Branch", :class => :label
= f.select :branch, @branches.collect{|branch| [branch.name, branch.name]}
.group
= f.label :pl, t("activerecord.attributes.build_list.pl"), :class => :label
- @pls.each do |pl|
= f.check_box "pl[#{pl.id}]", :pl_id => pl.id, :class => 'build_pl_ids'
= pl.name
%br
.group
= f.label :update_type, t("activerecord.attributes.build_list.update_type"), :class => :label
= f.select :update_type, BuildList::UPDATE_TYPES.collect { |ut| [ut, ut] }
.group
= f.check_box :build_requires
= t("activerecord.attributes.build_list.build_requires")
.column.right
.group
= f.label :arches, t("activerecord.attributes.build_list.arch"), :class => :label
@ -26,12 +42,23 @@
= arch.name
%br
.group
= f.label :bpl, t("activerecord.attributes.build_list.bpl"), :class => :label
= f.select :bpl, @bpls
.group.navform.wat-cf
%button.button{:type => "submit"}
= image_tag("web-app-theme/icons/tick.png", :alt => t("layout.projects.build_button"))
= t("layout.projects.build_button")
%span.text_button_padding= t("layout.or")
= link_to t("layout.cancel"), platform_repository_path(@platform, @repository), :class => "text_button_padding link_button"
= link_to t("layout.cancel"), root_path, :class => "text_button_padding link_button"
-#
:javascript
var pl_counter = 0;
var bpl_id = $('select#build_bpl').val();
$('input.build_pl_ids').each(function(i,el) {
var pl_id = $(el).attr('pl_id');
});
- content_for :sidebar, render(:partial => 'sidebar')
-# content_for :sidebar, render(:partial => 'sidebar')

View File

@ -5,7 +5,7 @@
%li= link_to t("layout.projects.new"), new_project_path
%li.active= link_to t("layout.projects.show"), project_path(@project)
%li= link_to "git-repo", '#'#platform_repository_project_repo_path(@platform, @repository, @project)
%li= link_to t("layout.projects.build"), '#'#build_platform_repository_project_path(@platform, @repository, @project)
%li= link_to t("layout.projects.build"), build_project_path(@project)
.content
.inner

View File

@ -192,6 +192,10 @@ ru:
no_items_data: Данных нет
show: Просмотр
confirm_publish: Вы уверены, что хотите опубликовать контейнер?
cancel_button_header: Действие
cancel_button: Отмена
cancel_successed: 'Сборка отменена.'
cancel_failed: 'При отмене сборки произошла ошибка!'
items:
statuses:
@ -262,12 +266,13 @@ ru:
destroyed: Платформа успешно удалена
build_list:
saved: Билд лист для бранча '%{branch_name}' и архитектуры '%{arch}' создан успешно
save_error: Не удалось сохранить билд лист для бранча '%{branch_name}' и архитектуры '%{arch}'
saved: Билд лист для бранча '%{branch_name}', платформу '#{pl}' и архитектуры '%{arch}' создан успешно
save_error: Не удалось сохранить билд лист для бранча '%{branch_name}', платформу '#{pl}' и архитектуры '%{arch}'
no_branch_selected: Выберите какой-нибудь бранч
no_branch_found: Выбранный бранч '%{branch_name}' не найден
no_arch_selected: Выберите хотя бы одну ахритектуру
no_arch_found: Выбранные ахритектуры не найдены
wrong_platform: Для основного репозитория (main) может быть выбран только его же основная платформа!
attributes:
password: Пароль
@ -413,6 +418,12 @@ ru:
additional_repos: Дополнительные репозитории
updated_at: Обновлен
created_at: Создан
bpl: Репозиторий для сохранения пакетов
bpl_id: Репозиторий для сохранения пакетов
pl: Платформа
pl_id: Платформа
update_type: Критичность обновления
build_requires: Пересборка с зависимостями
build_list/item:
name: Название

View File

@ -14,6 +14,9 @@ Rosa::Application.routes.draw do
match '/private/:platform_name/*file_path' => 'privates#show'
match 'build_lists/' => 'build_lists#all', :as => :all_build_lists
match 'build_lists/:id/cancel/' => 'build_lists#cancel', :as => :build_list_cancel
resources :platforms do
resources :private_users
@ -46,6 +49,11 @@ Rosa::Application.routes.draw do
post :publish
end
end
member do
get :build
get :process_build
end
end
resources :repositories do

View File

@ -0,0 +1,17 @@
class AddNewFieldsToBuildLists < ActiveRecord::Migration
def self.up
add_column :build_lists, :build_requires, :boolean
add_column :build_lists, :update_type, :string
add_column :build_lists, :bpl_id, :integer
add_column :build_lists, :pl_id, :integer
rename_column :build_lists, :branch_name, :project_version
end
def self.down
rename_column :build_lists, :project_version, :branch_name
remove_column :build_lists, :bpl_id
remove_column :build_lists, :pl_id
remove_column :build_lists, :update_type
remove_column :build_lists, :build_requires
end
end

View File

@ -46,7 +46,7 @@ ActiveRecord::Schema.define(:version => 20111021164945) do
t.integer "bs_id"
t.string "container_path"
t.integer "status"
t.string "branch_name"
t.string "project_version"
t.integer "project_id"
t.integer "arch_id"
t.datetime "notified_at"
@ -55,6 +55,10 @@ ActiveRecord::Schema.define(:version => 20111021164945) do
t.boolean "is_circle", :default => false
t.text "additional_repos"
t.string "name"
t.boolean "build_requires"
t.string "update_type"
t.integer "bpl_id"
t.integer "pl_id"
end
add_index "build_lists", ["arch_id"], :name => "index_build_lists_on_arch_id"

View File

@ -68,8 +68,12 @@ class BuildServer
self.client.call('add_to_repo', name, repo_name)
end
def self.add_build_list project_name, branch_name, platform_name, arch_name, web_id
self.client.call('add_build_list', project_name, branch_name, platform_name, arch_name, web_id)
def self.add_build_list project_name, project_version, plname, arch, bplname, update_type, build_requires, id_web
self.client.call('add_build_list', project_name, project_version, plname, arch, bplname, update_type, build_requires, id_web)
end
def self.delete_build_list idlist
self.client.call('delete_build_list', idlist)
end
def self.freeze platform_name, new_repo_name = nil