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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-07-19 17:16:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-19 17:16:28 +0300
commite4384360a16dd9a19d4d2d25d0ef1f2b862ed2a6 (patch)
tree2fcdfa7dcdb9db8f5208b2562f4b4e803d671243 /app/services/ci
parentffda4e7bcac36987f936b4ba515995a6698698f0 (diff)
Add latest changes from gitlab-org/gitlab@16-2-stable-eev16.2.0-rc42
Diffstat (limited to 'app/services/ci')
-rw-r--r--app/services/ci/create_pipeline_schedule_service.rb1
-rw-r--r--app/services/ci/create_pipeline_service.rb30
-rw-r--r--app/services/ci/destroy_pipeline_service.rb2
-rw-r--r--app/services/ci/pipeline_processing/atomic_processing_service.rb14
-rw-r--r--app/services/ci/pipeline_schedules/create_service.rb47
-rw-r--r--app/services/ci/pipeline_schedules/update_service.rb19
6 files changed, 83 insertions, 30 deletions
diff --git a/app/services/ci/create_pipeline_schedule_service.rb b/app/services/ci/create_pipeline_schedule_service.rb
index 0d5f50c26a1..4fdd65bcdb4 100644
--- a/app/services/ci/create_pipeline_schedule_service.rb
+++ b/app/services/ci/create_pipeline_schedule_service.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
module Ci
+ # This class is deprecated and will be removed with the FF ci_refactoring_pipeline_schedule_create_service
class CreatePipelineScheduleService < BaseService
def execute
project.pipeline_schedules.create(pipeline_schedule_params)
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb
index a8da83e84a1..fe0e842f542 100644
--- a/app/services/ci/create_pipeline_service.rb
+++ b/app/services/ci/create_pipeline_service.rb
@@ -40,22 +40,22 @@ module Ci
# Create a new pipeline in the specified project.
#
- # @param [Symbol] source What event (Ci::Pipeline.sources) triggers the pipeline
- # creation.
- # @param [Boolean] ignore_skip_ci Whether skipping a pipeline creation when `[skip ci]` comment
- # is present in the commit body
- # @param [Boolean] save_on_errors Whether persisting an invalid pipeline when it encounters an
- # error during creation (e.g. invalid yaml)
- # @param [Ci::TriggerRequest] trigger_request The pipeline trigger triggers the pipeline creation.
- # @param [Ci::PipelineSchedule] schedule The pipeline schedule triggers the pipeline creation.
- # @param [MergeRequest] merge_request The merge request triggers the pipeline creation.
- # @param [ExternalPullRequest] external_pull_request The external pull request triggers the pipeline creation.
- # @param [Ci::Bridge] bridge The bridge job that triggers the downstream pipeline creation.
- # @param [String] content The content of .gitlab-ci.yml to override the default config
- # contents (e.g. .gitlab-ci.yml in repostiry). Mainly used for
- # generating a dangling pipeline.
+ # @param [Symbol] source What event (Ci::Pipeline.sources) triggers the pipeline
+ # creation.
+ # @param [Boolean] ignore_skip_ci Whether skipping a pipeline creation when `[skip ci]` comment
+ # is present in the commit body
+ # @param [Boolean] save_on_errors Whether persisting an invalid pipeline when it encounters an
+ # error during creation (e.g. invalid yaml)
+ # @param [Ci::TriggerRequest] trigger_request The pipeline trigger triggers the pipeline creation.
+ # @param [Ci::PipelineSchedule] schedule The pipeline schedule triggers the pipeline creation.
+ # @param [MergeRequest] merge_request The merge request triggers the pipeline creation.
+ # @param [Ci::ExternalPullRequest] external_pull_request The external pull request triggers the pipeline creation.
+ # @param [Ci::Bridge] bridge The bridge job that triggers the downstream pipeline creation.
+ # @param [String] content The content of .gitlab-ci.yml to override the default config
+ # contents (e.g. .gitlab-ci.yml in repostiry). Mainly used for
+ # generating a dangling pipeline.
#
- # @return [Ci::Pipeline] The created Ci::Pipeline object.
+ # @return [Ci::Pipeline] The created Ci::Pipeline object.
# rubocop: disable Metrics/ParameterLists
def execute(source, ignore_skip_ci: false, save_on_errors: true, trigger_request: nil, schedule: nil, merge_request: nil, external_pull_request: nil, bridge: nil, **options, &block)
@logger = build_logger
diff --git a/app/services/ci/destroy_pipeline_service.rb b/app/services/ci/destroy_pipeline_service.rb
index bdec13f98a7..a9d2e17657e 100644
--- a/app/services/ci/destroy_pipeline_service.rb
+++ b/app/services/ci/destroy_pipeline_service.rb
@@ -7,7 +7,7 @@ module Ci
Ci::ExpirePipelineCacheService.new.execute(pipeline, delete: true)
- # ensure cancellation happens sync so we accumulate compute credits successfully
+ # ensure cancellation happens sync so we accumulate compute minutes successfully
# before deleting the pipeline.
::Ci::CancelPipelineService.new(
pipeline: pipeline,
diff --git a/app/services/ci/pipeline_processing/atomic_processing_service.rb b/app/services/ci/pipeline_processing/atomic_processing_service.rb
index c0ffbb401f6..8211507fb95 100644
--- a/app/services/ci/pipeline_processing/atomic_processing_service.rb
+++ b/app/services/ci/pipeline_processing/atomic_processing_service.rb
@@ -23,14 +23,12 @@ module Ci
success = try_obtain_lease { process! }
if success
- if ::Feature.enabled?(:ci_reset_skipped_jobs_in_atomic_processing, project)
- # If any jobs changed from stopped to alive status during pipeline processing, we must
- # re-reset their dependent jobs; see https://gitlab.com/gitlab-org/gitlab/-/issues/388539.
- new_alive_jobs.group_by(&:user).each do |user, jobs|
- log_running_reset_skipped_jobs_service(jobs)
-
- ResetSkippedJobsService.new(project, user).execute(jobs)
- end
+ # If any jobs changed from stopped to alive status during pipeline processing, we must
+ # re-reset their dependent jobs; see https://gitlab.com/gitlab-org/gitlab/-/issues/388539.
+ new_alive_jobs.group_by(&:user).each do |user, jobs|
+ log_running_reset_skipped_jobs_service(jobs)
+
+ ResetSkippedJobsService.new(project, user).execute(jobs)
end
# Re-schedule if we need further processing
diff --git a/app/services/ci/pipeline_schedules/create_service.rb b/app/services/ci/pipeline_schedules/create_service.rb
new file mode 100644
index 00000000000..c1825865bc0
--- /dev/null
+++ b/app/services/ci/pipeline_schedules/create_service.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+module Ci
+ module PipelineSchedules
+ class CreateService
+ def initialize(project, user, params)
+ @project = project
+ @user = user
+ @params = params
+
+ @schedule = project.pipeline_schedules.new
+ end
+
+ def execute
+ return forbidden unless allowed?
+
+ schedule.assign_attributes(params.merge(owner: user))
+
+ if schedule.save
+ ServiceResponse.success(payload: schedule)
+ else
+ ServiceResponse.error(payload: schedule, message: schedule.errors.full_messages)
+ end
+ end
+
+ private
+
+ attr_reader :project, :user, :params, :schedule
+
+ def allowed?
+ user.can?(:create_pipeline_schedule, schedule)
+ end
+
+ def forbidden
+ # We add the error to the base object too
+ # because model errors are used in the API responses and the `form_errors` helper.
+ schedule.errors.add(:base, forbidden_message)
+
+ ServiceResponse.error(payload: schedule, message: [forbidden_message], reason: :forbidden)
+ end
+
+ def forbidden_message
+ _('The current user is not authorized to create the pipeline schedule')
+ end
+ end
+ end
+end
diff --git a/app/services/ci/pipeline_schedules/update_service.rb b/app/services/ci/pipeline_schedules/update_service.rb
index 2412b5cbd81..28c22e0a868 100644
--- a/app/services/ci/pipeline_schedules/update_service.rb
+++ b/app/services/ci/pipeline_schedules/update_service.rb
@@ -12,7 +12,9 @@ module Ci
def execute
return forbidden unless allowed?
- if schedule.update(@params)
+ schedule.assign_attributes(params)
+
+ if schedule.save
ServiceResponse.success(payload: schedule)
else
ServiceResponse.error(message: schedule.errors.full_messages)
@@ -21,17 +23,22 @@ module Ci
private
- attr_reader :schedule, :user
+ attr_reader :schedule, :user, :params
def allowed?
user.can?(:update_pipeline_schedule, schedule)
end
def forbidden
- ServiceResponse.error(
- message: _('The current user is not authorized to update the pipeline schedule'),
- reason: :forbidden
- )
+ # We add the error to the base object too
+ # because model errors are used in the API responses and the `form_errors` helper.
+ schedule.errors.add(:base, forbidden_message)
+
+ ServiceResponse.error(message: [forbidden_message], reason: :forbidden)
+ end
+
+ def forbidden_message
+ _('The current user is not authorized to update the pipeline schedule')
end
end
end