debian-mirror-gitlab/app/services/packages/create_event_service.rb

50 lines
1.2 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
module Packages
class CreateEventService < BaseService
def execute
2021-04-17 20:07:23 +05:30
::Packages::Event.unique_counters_for(event_scope, event_name, originator_type).each do |event_name|
::Gitlab::UsageDataCounters::HLLRedisCounter.track_event(event_name, values: current_user.id)
end
::Packages::Event.counters_for(event_scope, event_name, originator_type).each do |event_name|
::Gitlab::UsageDataCounters::PackageEventCounter.count(event_name)
2021-01-29 00:20:46 +05:30
end
if Feature.enabled?(:collect_package_events) && Gitlab::Database.read_write?
::Packages::Event.create!(
event_type: event_name,
originator: current_user&.id,
originator_type: originator_type,
event_scope: event_scope
)
end
2021-01-03 14:25:43 +05:30
end
2023-04-23 21:23:45 +05:30
def originator_type
case current_user
when User
:user
when DeployToken
:deploy_token
else
:guest
end
end
2021-01-03 14:25:43 +05:30
private
2021-01-29 00:20:46 +05:30
def event_scope
@event_scope ||= scope.is_a?(::Packages::Package) ? scope.package_type : scope
end
2021-01-03 14:25:43 +05:30
def scope
params[:scope]
end
def event_name
params[:event_name]
end
end
end