debian-mirror-gitlab/app/services/git/process_ref_changes_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

97 lines
2.9 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
module Git
class ProcessRefChangesService < BaseService
PIPELINE_PROCESS_LIMIT = 4
def execute
changes = params[:changes]
process_changes_by_action(:branch, changes.branch_changes)
process_changes_by_action(:tag, changes.tag_changes)
2022-01-26 12:08:38 +05:30
perform_housekeeping
2019-12-21 20:55:43 +05:30
end
private
def process_changes_by_action(ref_type, changes)
changes_by_action = group_changes_by_action(changes)
changes_by_action.each do |action, changes|
process_changes(ref_type, action, changes, execute_project_hooks: execute_project_hooks?(changes)) if changes.any?
end
end
def group_changes_by_action(changes)
changes.group_by do |change|
change_action(change)
end
end
def change_action(change)
return :created if Gitlab::Git.blank_ref?(change[:oldrev])
return :removed if Gitlab::Git.blank_ref?(change[:newrev])
:pushed
end
def execute_project_hooks?(changes)
2020-04-08 14:13:33 +05:30
changes.size <= Gitlab::CurrentSettings.push_event_hooks_limit
2019-12-21 20:55:43 +05:30
end
def process_changes(ref_type, action, changes, execute_project_hooks:)
push_service_class = push_service_class_for(ref_type)
create_bulk_push_event = changes.size > Gitlab::CurrentSettings.push_event_activities_limit
2020-10-24 23:57:45 +05:30
merge_request_branches = merge_request_branches_for(ref_type, changes)
2019-12-21 20:55:43 +05:30
changes.each do |change|
push_service_class.new(
project,
current_user,
change: change,
push_options: params[:push_options],
2020-04-22 19:07:51 +05:30
merge_request_branches: merge_request_branches,
2021-10-27 15:23:28 +05:30
create_pipelines: under_process_limit?(change),
2019-12-21 20:55:43 +05:30
execute_project_hooks: execute_project_hooks,
create_push_event: !create_bulk_push_event
).execute
end
create_bulk_push_event(ref_type, action, changes) if create_bulk_push_event
end
2021-10-27 15:23:28 +05:30
def under_process_limit?(change)
change[:index] < PIPELINE_PROCESS_LIMIT || Feature.enabled?(:git_push_create_all_pipelines, project)
end
2019-12-21 20:55:43 +05:30
def create_bulk_push_event(ref_type, action, changes)
EventCreateService.new.bulk_push(
project,
current_user,
Gitlab::DataBuilder::Push.build_bulk(action: action, ref_type: ref_type, changes: changes)
)
end
def push_service_class_for(ref_type)
return Git::TagPushService if ref_type == :tag
Git::BranchPushService
end
2020-04-22 19:07:51 +05:30
2020-10-24 23:57:45 +05:30
def merge_request_branches_for(ref_type, changes)
return [] if ref_type == :tag
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
MergeRequests::PushedBranchesService.new(project: project, current_user: current_user, params: { changes: changes }).execute
2020-04-22 19:07:51 +05:30
end
2022-01-26 12:08:38 +05:30
def perform_housekeeping
housekeeping = Repositories::HousekeepingService.new(project)
housekeeping.increment!
housekeeping.execute if housekeeping.needed?
rescue Repositories::HousekeepingService::LeaseTaken
end
2019-12-21 20:55:43 +05:30
end
end