debian-mirror-gitlab/app/services/resource_events/change_state_service.rb

61 lines
1.4 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module ResourceEvents
class ChangeStateService
attr_reader :resource, :user
def initialize(user:, resource:)
@user, @resource = user, resource
end
2020-07-28 23:09:34 +05:30
def execute(params)
@params = params
2020-06-23 00:09:42 +05:30
ResourceStateEvent.create(
user: user,
2020-11-24 15:15:51 +05:30
resource.class.underscore => resource,
2020-07-28 23:09:34 +05:30
source_commit: commit_id_of(mentionable_source),
source_merge_request_id: merge_request_id_of(mentionable_source),
2020-06-23 00:09:42 +05:30
state: ResourceStateEvent.states[state],
2020-07-28 23:09:34 +05:30
close_after_error_tracking_resolve: close_after_error_tracking_resolve,
close_auto_resolve_prometheus_alert: close_auto_resolve_prometheus_alert,
2020-11-24 15:15:51 +05:30
created_at: Time.zone.now
)
2020-06-23 00:09:42 +05:30
resource.expire_note_etag_cache
end
private
2020-07-28 23:09:34 +05:30
attr_reader :params
def close_auto_resolve_prometheus_alert
params[:close_auto_resolve_prometheus_alert] || false
end
def close_after_error_tracking_resolve
params[:close_after_error_tracking_resolve] || false
end
def state
params[:status]
end
def mentionable_source
params[:mentionable_source]
end
def commit_id_of(mentionable_source)
return unless mentionable_source.is_a?(Commit)
mentionable_source.id[0...40]
end
def merge_request_id_of(mentionable_source)
return unless mentionable_source.is_a?(MergeRequest)
mentionable_source.id
end
2020-06-23 00:09:42 +05:30
end
end