[refs #374] added commit validation
This commit is contained in:
parent
0091e34298
commit
7f031ac688
|
@ -23,7 +23,6 @@ class Api::V1::BuildListsController < Api::V1::BaseController
|
|||
bl_params[:auto_publish] = false unless save_to_repository.publish_without_qa?
|
||||
|
||||
@build_list = project.build_lists.build(bl_params)
|
||||
@build_list.project_version = @build_list.commit_hash
|
||||
|
||||
@build_list.user = current_user
|
||||
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
|
||||
|
|
|
@ -57,8 +57,6 @@ class Projects::BuildListsController < Projects::BaseController
|
|||
Arch.where(:id => params[:arches]).each do |arch|
|
||||
Platform.main.where(:id => build_for_platforms).each do |build_for_platform|
|
||||
@build_list = @project.build_lists.build(params[:build_list])
|
||||
@build_list.commit_hash = @project.repo.commits(@build_list.project_version.match(/^latest_(.+)/).to_a.last ||
|
||||
@build_list.project_version).first.id if @build_list.project_version
|
||||
@build_list.build_for_platform = build_for_platform; @build_list.arch = arch; @build_list.user = current_user
|
||||
@build_list.include_repos = @build_list.include_repos.select {|ir| @build_list.build_for_platform.repository_ids.include? ir.to_i}
|
||||
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
|
||||
|
|
|
@ -32,6 +32,11 @@ class BuildList < ActiveRecord::Base
|
|||
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_include_repos')) unless build_for_platform.repository_ids.include? ir.to_i
|
||||
}
|
||||
}
|
||||
validate lambda {
|
||||
if commit_hash.blank? || project.repo.commit(commit_hash).blank?
|
||||
errors.add :commit_hash, I18n.t('flash.build_list.wrong_commit_hash', :commit_hash => commit_hash)
|
||||
end
|
||||
}
|
||||
|
||||
LIVE_TIME = 4.week # for unpublished
|
||||
MAX_LIVE_TIME = 3.month # for published
|
||||
|
@ -110,6 +115,7 @@ class BuildList < ActiveRecord::Base
|
|||
|
||||
after_commit :place_build
|
||||
after_destroy :delete_container
|
||||
before_validation :set_commit_and_version
|
||||
|
||||
@queue = :clone_and_build
|
||||
|
||||
|
@ -331,4 +337,13 @@ class BuildList < ActiveRecord::Base
|
|||
yield p
|
||||
end
|
||||
end
|
||||
|
||||
def set_commit_and_version
|
||||
if project_version.present? && commit_hash.blank?
|
||||
self.commit_hash = project.repo.commits(project_version.match(/^latest_(.+)/).to_a.last ||
|
||||
project_version).try(:first).try(:id)
|
||||
elsif project_version.blank? && commit_hash.present?
|
||||
self.project_version = commit_hash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,6 +29,7 @@ en:
|
|||
started_at: Build started at
|
||||
duration: Build duration in seconds
|
||||
mass_build_id: Mass build
|
||||
commit_hash: Commit hash
|
||||
|
||||
build_list/item:
|
||||
name: Name
|
||||
|
@ -147,3 +148,4 @@ en:
|
|||
can_not_published: Build can only be published with status "Build complete"
|
||||
frozen_platform: In case of a repository for package storage with frozen platform allowed only bugfix and security updates
|
||||
wrong_include_repos: Include repos have to belongs to build for platform
|
||||
wrong_commit_hash: Unable find commit '%{commit_hash}' in project
|
||||
|
|
|
@ -28,6 +28,7 @@ ru:
|
|||
preferences: Настройки
|
||||
duration: Длительность билда в секундах
|
||||
mass_build_id: Массовая сборка
|
||||
commit_hash: Хэш коммита
|
||||
|
||||
build_list/item:
|
||||
name: Название
|
||||
|
@ -144,3 +145,4 @@ ru:
|
|||
can_not_published: Опубликовать сборку можно только со статусом "Собран"
|
||||
frozen_platform: В случае выбора репозитория для сохранения пакетов из замороженнной платформы разрешены только bugfix и security обновления
|
||||
wrong_include_repos: Включаемые репозитории должны принадлежать платформе для сборки
|
||||
wrong_commit_hash: Невозможно найти коммит '%{commit_hash}' в проекте
|
||||
|
|
|
@ -47,6 +47,10 @@ shared_examples_for 'create build list via api' do
|
|||
#@project.build_lists.last.commit_hash.should == @project.repo.commits('4.7.5.3').last.id
|
||||
@project.build_lists.last.commit_hash.should == @params[:commit_hash]
|
||||
end
|
||||
|
||||
it 'should not create without existing commit hash in project' do
|
||||
lambda{ post :create, @create_params.deep_merge(:build_list => {:commit_hash => 'wrong'})}.should change{@project.build_lists.count}.by(0)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'not create build list via api' do
|
||||
|
|
|
@ -30,7 +30,6 @@ describe Projects::BuildListsController do
|
|||
shared_examples_for 'create build list' do
|
||||
before {
|
||||
@project.update_attribute(:repositories, @platform.repositories)
|
||||
test_git_commit(@project)
|
||||
}
|
||||
|
||||
it 'should be able to perform new action' do
|
||||
|
@ -53,12 +52,19 @@ describe Projects::BuildListsController do
|
|||
post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "4.7.5.3"})
|
||||
@project.build_lists.last.commit_hash.should == @project.repo.commits('4.7.5.3').last.id
|
||||
end
|
||||
|
||||
it 'should not be able to create with wrong project version' do
|
||||
lambda{ post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "latest_wrong", :commit_hash => nil})}.should change{@project.build_lists.count}.by(0)
|
||||
end
|
||||
|
||||
it 'should not be able to create with wrong git hash' do
|
||||
lambda{ post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:commit_hash => 'wrong'})}.should change{@project.build_lists.count}.by(0)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'not create build list' do
|
||||
before {
|
||||
@project.update_attribute(:repositories, @platform.repositories)
|
||||
test_git_commit(@project)
|
||||
}
|
||||
|
||||
it 'should not be able to perform new action' do
|
||||
|
|
|
@ -8,11 +8,11 @@ FactoryGirl.define do
|
|||
association :arch
|
||||
build_for_platform {|bl| bl.save_to_platform}
|
||||
save_to_repository {|bl| bl.save_to_platform.repositories.first}
|
||||
project_version "1.0"
|
||||
build_requires true
|
||||
update_type 'security'
|
||||
include_repos {|bl| bl.save_to_platform.repositories.map(&:id)}
|
||||
commit_hash '1234567890abcdef1234567890abcdef12345678'
|
||||
project_version 'latest_master'
|
||||
after(:build) {|bl| test_git_commit bl.project }
|
||||
end
|
||||
|
||||
factory :build_list_core, :parent => :build_list do
|
||||
|
|
Loading…
Reference in New Issue