debian-mirror-gitlab/app/services/ci/create_builds_service.rb

43 lines
1.4 KiB
Ruby
Raw Normal View History

2015-10-24 18:46:33 +05:30
module Ci
class CreateBuildsService
def execute(commit, stage, ref, tag, user, trigger_request, status)
builds_attrs = commit.config_processor.builds_for_stage_and_ref(stage, ref, tag)
# check when to create next build
builds_attrs = builds_attrs.select do |build_attrs|
case build_attrs[:when]
when 'on_success'
status == 'success'
when 'on_failure'
status == 'failed'
when 'always'
%w(success failed).include?(status)
end
end
builds_attrs.map do |build_attrs|
# don't create the same build twice
unless commit.builds.find_by(ref: ref, tag: tag, trigger_request: trigger_request, name: build_attrs[:name])
build_attrs.slice!(:name,
:commands,
:tag_list,
:options,
:allow_failure,
:stage,
:stage_idx)
build_attrs.merge!(ref: ref,
tag: tag,
trigger_request: trigger_request,
2015-12-23 02:04:40 +05:30
user: user,
project: commit.project)
2015-10-24 18:46:33 +05:30
2015-12-23 02:04:40 +05:30
build = commit.builds.create!(build_attrs)
build.execute_hooks
2016-04-02 18:10:28 +05:30
build
2015-10-24 18:46:33 +05:30
end
end
end
end
end