summaryrefslogtreecommitdiff
path: root/app/services/ci/play_build_service.rb
blob: 9f922ffde815b1b3f4138ea1075614478f95371e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

module Ci
  class PlayBuildService < ::BaseService
    def execute(build, job_variables_attributes = nil)
      unless can?(current_user, :update_build, build)
        raise Gitlab::Access::AccessDeniedError
      end

      # Try to enqueue the build, otherwise create a duplicate.
      #
      if build.enqueue
        build.tap { |action| action.update(user: current_user, job_variables_attributes: job_variables_attributes || []) }
      else
        Ci::Build.retry(build, current_user)
      end
    end
  end
end