gitlab-org--gitlab-foss/app/services/ci/create_builds_service.rb

42 lines
1.3 KiB
Ruby
Raw Normal View History

2015-10-02 07:46:38 -04:00
module Ci
class CreateBuildsService
def execute(commit, stage, ref, tag, user, trigger_request, status)
2015-10-05 06:02:26 -04:00
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
2015-10-05 06:02:26 -04:00
builds_attrs.map do |build_attrs|
2015-10-05 07:12:00 -04:00
# 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)
2015-10-05 06:02:26 -04:00
2015-10-05 07:12:00 -04:00
build_attrs.merge!(ref: ref,
tag: tag,
trigger_request: trigger_request,
2015-12-04 06:55:23 -05:00
user: user,
2015-12-10 12:47:22 -05:00
project: commit.project)
2015-10-05 06:02:26 -04:00
build = commit.builds.create!(build_attrs)
build.execute_hooks
2015-10-05 07:12:00 -04:00
end
2015-10-02 07:46:38 -04:00
end
end
end
end