Welcome to mirror list, hosted at ThFree Co, Russian Federation.

retry_pipeline_service.rb « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d40643e15134727b74da621035d75781128f6040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

module Ci
  class RetryPipelineService < ::BaseService
    include Gitlab::OptimisticLocking

    def execute(pipeline)
      access_response = check_access(pipeline)
      return access_response if access_response.error?

      pipeline.ensure_scheduling_type!

      builds_relation(pipeline).find_each do |build|
        next unless can_be_retried?(build)

        Ci::RetryBuildService.new(project, current_user).clone!(build)
      end

      pipeline.processables.latest.skipped.find_each do |skipped|
        retry_optimistic_lock(skipped, name: 'ci_retry_pipeline') { |build| build.process(current_user) }
      end

      pipeline.reset_source_bridge!(current_user)

      ::MergeRequests::AddTodoWhenBuildFailsService
        .new(project: project, current_user: current_user)
        .close_all(pipeline)

      Ci::ProcessPipelineService
        .new(pipeline)
        .execute

      ServiceResponse.success
    rescue Gitlab::Access::AccessDeniedError => e
      ServiceResponse.error(message: e.message, http_status: :forbidden)
    end

    def check_access(pipeline)
      if can?(current_user, :update_pipeline, pipeline)
        ServiceResponse.success
      else
        ServiceResponse.error(message: '403 Forbidden', http_status: :forbidden)
      end
    end

    private

    def builds_relation(pipeline)
      pipeline.retryable_builds.preload_needs
    end

    def can_be_retried?(build)
      can?(current_user, :update_build, build)
    end
  end
end

Ci::RetryPipelineService.prepend_mod_with('Ci::RetryPipelineService')