From 5acc13e9a69e2dcd4c61a582390292d347b97aaa Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 14 Jun 2012 17:36:40 +0400 Subject: [PATCH] [ref #505] Refactor set_version_and_tag. Rename success and error events --- app/controllers/projects/build_lists_controller.rb | 3 +-- app/models/build_list.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index b039daef5..1ac234c24 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -95,7 +95,6 @@ class Projects::BuildListsController < Projects::BaseController def publish_build if params[:status].to_i == 0 # ok @build_list.published - @build_list.set_version_and_tag params[:version], params[:release] else @build_list.failed_publish end @@ -123,7 +122,7 @@ class Projects::BuildListsController < Projects::BaseController end def post_build - params[:status] == BuildServer::SUCCESS ? @build_list.success : @build_list.error + params[:status] == BuildServer::SUCCESS ? @build_list.build_success : @build_list.build_error @build_list.container_path = params[:container_path] @build_list.save diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 96d1cb018..a13ec28f7 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -105,6 +105,8 @@ class BuildList < ActiveRecord::Base state_machine :status, :initial => :waiting_for_response do + after_transition :on => :published, :do => :set_version_and_tag + event :place_build do transition :waiting_for_response => :build_pending, :if => lambda { |build_list| build_list.add_to_queue == BUILD_PENDING @@ -156,11 +158,11 @@ class BuildList < ActiveRecord::Base transition :success => :rejected_publish, :if => :can_reject_publish? end - event :success do + event :build_success do transition [:build_started, :build_canceled] => :success end - event :error do + event :build_error do transition [:build_started, :build_canceled] => :build_error end @@ -185,8 +187,9 @@ class BuildList < ActiveRecord::Base @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 end - def set_version_and_tag(version, release) - self.package_version = "#{version}-#{release}" + def set_version_and_tag + pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first + self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit save end