2011-03-10 11:35:46 +00:00
|
|
|
class ProjectsController < ApplicationController
|
2011-10-28 14:27:12 +01:00
|
|
|
before_filter :authenticate_user!, :except => :auto_build
|
2011-10-31 13:24:46 +00:00
|
|
|
before_filter :find_project, :only => [:show, :edit, :update, :destroy, :build, :process_build]
|
2011-10-26 21:57:51 +01:00
|
|
|
before_filter :get_paths, :only => [:new, :create, :edit, :update]
|
2011-10-31 21:55:56 +00:00
|
|
|
before_filter :check_global_access, :only => [:index, :new, :create]#:except => :auto_build
|
2011-03-10 13:38:50 +00:00
|
|
|
|
2011-10-26 21:57:51 +01:00
|
|
|
def index
|
2011-11-03 10:56:41 +00:00
|
|
|
@projects = Project.visible_to(current_user).where(:name => params[:query]).paginate(:page => params[:project_page])
|
2011-11-02 21:39:50 +00:00
|
|
|
@own_projects = current_user.own_projects
|
|
|
|
@part_projects = current_user.projects - @own_projects
|
2011-03-10 13:38:50 +00:00
|
|
|
end
|
|
|
|
|
2011-03-10 14:20:09 +00:00
|
|
|
def show
|
2011-10-31 18:14:25 +00:00
|
|
|
can_perform? @project if @project
|
2011-04-07 14:20:21 +01:00
|
|
|
@current_build_lists = @project.build_lists.current.recent.paginate :page => params[:page]
|
2011-03-10 14:20:09 +00:00
|
|
|
end
|
|
|
|
|
2011-10-26 21:57:51 +01:00
|
|
|
def new
|
|
|
|
@project = Project.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2011-10-31 18:14:25 +00:00
|
|
|
can_perform? @project if @project
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@project = Project.new params[:project]
|
|
|
|
@project.owner = get_owner
|
|
|
|
|
|
|
|
if @project.save
|
|
|
|
flash[:notice] = t('flash.project.saved')
|
2011-10-27 23:43:44 +01:00
|
|
|
redirect_to @project
|
2011-10-26 21:57:51 +01:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.project.save_error')
|
|
|
|
flash[:warning] = @project.errors[:base]
|
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2011-10-31 18:14:25 +00:00
|
|
|
can_perform? @project if @project
|
2011-10-26 21:57:51 +01:00
|
|
|
if @project.update_attributes(params[:project])
|
|
|
|
flash[:notice] = t('flash.project.saved')
|
2011-10-27 23:43:44 +01:00
|
|
|
redirect_to @project
|
2011-10-26 21:57:51 +01:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.project.save_error')
|
|
|
|
render :action => :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2011-10-31 18:14:25 +00:00
|
|
|
can_perform? @project if @project
|
2011-10-26 21:57:51 +01:00
|
|
|
@project.destroy
|
|
|
|
flash[:notice] = t("flash.project.destroyed")
|
2011-10-27 13:49:21 +01:00
|
|
|
redirect_to @project.owner
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
|
|
|
|
2011-10-31 00:11:49 +00:00
|
|
|
def auto_build
|
2011-11-02 20:27:47 +00:00
|
|
|
uname, unixname = params[:git_repo].split('/')
|
|
|
|
owner = User.find_by_uname(uname) || Group.find_by_uname(uname)
|
|
|
|
project = Project.where(:owner_id => owner.id, :owner_type => owner.class).find_by_unixname!(unixname)
|
2011-10-29 20:09:14 +01:00
|
|
|
auto_build_list = AutoBuildList.find_by_project_id(project.id)
|
2011-10-31 00:11:49 +00:00
|
|
|
|
2011-11-02 19:18:25 +00:00
|
|
|
# p = params.delete_if{|k,v| k == 'controller' or k == 'action'}
|
|
|
|
# ActiveSupport::Notifications.instrument("event_log.observer", :object => project, :message => p.inspect)
|
|
|
|
logger.info "Git hook recieved from #{params[:git_user]} to #{params[:git_repo]}"
|
2011-10-31 00:11:49 +00:00
|
|
|
|
2011-10-29 20:09:14 +01:00
|
|
|
BuildList.create!(
|
2011-11-02 19:18:25 +00:00
|
|
|
:project => project,
|
|
|
|
:pl => auto_build_list.pl,
|
|
|
|
:bpl => auto_build_list.bpl,
|
|
|
|
:arch => auto_build_list.arch,
|
2011-10-30 21:11:59 +00:00
|
|
|
:project_version => project.collected_project_versions.last.try(:first),
|
2011-10-29 20:09:14 +01:00
|
|
|
:build_requires => true,
|
2011-11-02 19:18:25 +00:00
|
|
|
:update_type => 'bugfix') if auto_build_list
|
|
|
|
|
2011-10-28 14:27:12 +01:00
|
|
|
render :nothing => true
|
|
|
|
end
|
|
|
|
|
2011-04-11 17:37:09 +01:00
|
|
|
def build
|
2011-10-31 18:14:25 +00:00
|
|
|
can_perform? @project if @project
|
2011-04-11 17:37:09 +01:00
|
|
|
@arches = Arch.recent
|
2011-10-29 13:18:41 +01:00
|
|
|
@bpls = Platform.main
|
|
|
|
@pls = @project.repositories.collect { |rep| ["#{rep.platform.name}/#{rep.unixname}", rep.platform.id] }
|
2011-10-30 21:11:59 +00:00
|
|
|
@project_versions = @project.collected_project_versions
|
2011-04-11 17:37:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def process_build
|
2011-10-31 18:14:25 +00:00
|
|
|
can_perform? @project if @project
|
2011-04-11 17:37:09 +01:00
|
|
|
@arch_ids = params[:build][:arches].select{|_,v| v == "1"}.collect{|x| x[0].to_i }
|
|
|
|
@arches = Arch.where(:id => @arch_ids)
|
|
|
|
|
2011-10-23 11:34:42 +01:00
|
|
|
@project_version = params[:build][:project_version]
|
2011-04-11 17:37:09 +01:00
|
|
|
|
2011-10-29 13:18:41 +01:00
|
|
|
bpls_ids = params[:build][:bpl].blank? ? [] : params[:build][:bpl].select{|_,v| v == "1"}.collect{|x| x[0].to_i }
|
|
|
|
bpls = Platform.where(:id => bpls_ids)
|
2011-10-22 16:28:41 +01:00
|
|
|
|
2011-10-29 13:18:41 +01:00
|
|
|
pl = Platform.find params[:build][:pl]
|
2011-10-23 12:24:46 +01:00
|
|
|
update_type = params[:build][:update_type]
|
|
|
|
build_requires = params[:build][:build_requires]
|
|
|
|
|
2011-10-30 21:11:59 +00:00
|
|
|
@project_versions = @project.collected_project_versions
|
2011-10-22 16:28:41 +01:00
|
|
|
|
2011-10-23 11:34:42 +01:00
|
|
|
if !check_arches || !check_project_versions
|
2011-04-11 17:37:09 +01:00
|
|
|
@arches = Arch.recent
|
2011-10-29 13:18:41 +01:00
|
|
|
@bpls = Platform.main
|
|
|
|
@pls = @project.repositories.collect { |rep| ["#{rep.platform.name}/#{rep.unixname}", rep.platform.id] }
|
2011-10-23 12:24:46 +01:00
|
|
|
|
2011-04-11 17:37:09 +01:00
|
|
|
render :action => "build"
|
|
|
|
else
|
|
|
|
flash[:notice], flash[:error] = "", ""
|
|
|
|
@arches.each do |arch|
|
2011-10-29 13:18:41 +01:00
|
|
|
bpls.each do |bpl|
|
2011-10-23 12:24:46 +01:00
|
|
|
build_list = @project.build_lists.new(:arch => arch, :project_version => @project_version, :pl => pl, :bpl => bpl, :update_type => update_type, :build_requires => build_requires)
|
2011-04-11 17:37:09 +01:00
|
|
|
|
2011-10-22 16:28:41 +01:00
|
|
|
if build_list.save
|
2011-10-29 13:18:41 +01:00
|
|
|
flash[:notice] += t("flash.build_list.saved", :project_version => @project_version, :arch => arch.name, :bpl => bpl.name, :pl => pl)
|
2011-10-22 16:28:41 +01:00
|
|
|
else
|
2011-10-29 13:18:41 +01:00
|
|
|
flash[:error] += t("flash.build_list.save_error", :project_version => @project_version, :arch => arch.name, :bpl => bpl.name, :pl => pl)
|
2011-10-22 16:28:41 +01:00
|
|
|
end
|
2011-04-11 17:37:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-22 16:28:41 +01:00
|
|
|
redirect_to project_path(@project)
|
2011-04-11 17:37:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-10 13:38:50 +00:00
|
|
|
protected
|
|
|
|
|
2011-10-17 15:21:29 +01:00
|
|
|
def get_paths
|
|
|
|
if params[:user_id]
|
|
|
|
@user = User.find params[:user_id]
|
2011-10-26 21:57:51 +01:00
|
|
|
@projects_path = user_path(@user) # user_projects_path @user
|
2011-10-17 15:21:29 +01:00
|
|
|
@new_project_path = new_user_project_path @user
|
|
|
|
elsif params[:group_id]
|
|
|
|
@group = Group.find params[:group_id]
|
2011-10-27 13:49:21 +01:00
|
|
|
@projects_path = group_path(@group) # group_projects_path @group
|
2011-10-17 15:21:29 +01:00
|
|
|
@new_projects_path = new_group_project_path @group
|
|
|
|
else
|
|
|
|
@projects_path = projects_path
|
|
|
|
@new_projects_path = new_project_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-10 14:20:09 +00:00
|
|
|
def find_project
|
2011-10-16 21:50:56 +01:00
|
|
|
@project = Project.find params[:id]
|
2011-03-10 14:20:09 +00:00
|
|
|
end
|
2011-04-11 17:37:09 +01:00
|
|
|
|
|
|
|
def check_arches
|
|
|
|
if @arch_ids.blank?
|
|
|
|
flash[:error] = t("flash.build_list.no_arch_selected")
|
|
|
|
false
|
|
|
|
elsif @arch_ids.length != @arches.length
|
|
|
|
flash[:error] = t("flash.build_list.no_arch_found")
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-23 11:34:42 +01:00
|
|
|
def check_project_versions
|
|
|
|
if @project_version.blank?
|
|
|
|
flash[:error] = t("flash.build_list.no_project_version_selected")
|
2011-04-11 17:37:09 +01:00
|
|
|
false
|
2011-10-23 12:24:46 +01:00
|
|
|
elsif !@project_versions.flatten.include?(@project_version)
|
|
|
|
flash[:error] = t("flash.build_list.no_project_version_found", :project_version => @project_version)
|
2011-04-11 17:37:09 +01:00
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2011-03-10 11:35:46 +00:00
|
|
|
end
|