Commit 9202b1f4 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extract CI/CD build retry code to separate service

parent 4e3fc212
......@@ -63,32 +63,7 @@ module Ci
end
def retry(build, user = nil)
new_build = Ci::Build.create(
ref: build.ref,
tag: build.tag,
options: build.options,
commands: build.commands,
tag_list: build.tag_list,
project: build.project,
pipeline: build.pipeline,
name: build.name,
allow_failure: build.allow_failure,
stage: build.stage,
stage_idx: build.stage_idx,
trigger_request: build.trigger_request,
yaml_variables: build.yaml_variables,
when: build.when,
user: user,
environment: build.environment,
status_event: 'enqueue'
)
MergeRequests::AddTodoWhenBuildFailsService
.new(build.project, nil)
.close(new_build)
build.pipeline.mark_as_processable_after_stage(build.stage_idx)
new_build
Ci::RetryBuildService.new(build, user).retry!
end
end
......
module Ci
class RetryBuildService
def initialize(build, user)
@build = build
@user = user
@pipeline = build.pipeline
end
def retry!
clone_build.tap do |new_build|
new_build.enqueue!
MergeRequests::AddTodoWhenBuildFailsService
.new(@build.project, @user)
.close(new_build)
@pipeline.mark_as_processable_after_stage(@build.stage_idx)
end
end
private
def clone_build
Ci::Build.create(
ref: @build.ref,
tag: @build.tag,
options: @build.options,
commands: @build.commands,
tag_list: @build.tag_list,
project: @build.project,
pipeline: @build.pipeline,
name: @build.name,
allow_failure: @build.allow_failure,
stage: @build.stage,
stage_idx: @build.stage_idx,
trigger_request: @build.trigger_request,
yaml_variables: @build.yaml_variables,
when: @build.when,
environment: @build.environment,
user: @user)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment