2020-05-22 08:08:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ResourceEvents
|
|
|
|
class ChangeStateService
|
|
|
|
attr_reader :resource, :user
|
|
|
|
|
|
|
|
def initialize(user:, resource:)
|
2021-04-19 17:09:27 -04:00
|
|
|
@user = user
|
|
|
|
@resource = resource
|
2020-05-22 08:08:15 -04:00
|
|
|
end
|
|
|
|
|
2020-07-15 08:09:26 -04:00
|
|
|
def execute(params)
|
|
|
|
@params = params
|
|
|
|
|
2020-05-22 08:08:15 -04:00
|
|
|
ResourceStateEvent.create(
|
|
|
|
user: user,
|
2022-01-31 19:14:06 -05:00
|
|
|
resource.noteable_target_type_name => resource,
|
2020-07-15 08:09:26 -04:00
|
|
|
source_commit: commit_id_of(mentionable_source),
|
|
|
|
source_merge_request_id: merge_request_id_of(mentionable_source),
|
2020-05-22 08:08:15 -04:00
|
|
|
state: ResourceStateEvent.states[state],
|
2020-07-15 08:09:26 -04:00
|
|
|
close_after_error_tracking_resolve: close_after_error_tracking_resolve,
|
|
|
|
close_auto_resolve_prometheus_alert: close_auto_resolve_prometheus_alert,
|
2021-01-12 16:10:47 -05:00
|
|
|
created_at: resource.system_note_timestamp
|
2020-09-17 08:09:37 -04:00
|
|
|
)
|
2020-05-22 08:08:15 -04:00
|
|
|
|
|
|
|
resource.expire_note_etag_cache
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-07-15 08:09:26 -04:00
|
|
|
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-05-22 08:08:15 -04:00
|
|
|
end
|
|
|
|
end
|