Class: ResourceEvents::ChangeStateService

Inherits:
Object
  • Object
show all
Defined in:
app/services/resource_events/change_state_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user:, resource:) ⇒ ChangeStateService

Returns a new instance of ChangeStateService.


7
8
9
10
# File 'app/services/resource_events/change_state_service.rb', line 7

def initialize(user:, resource:)
  @user = user
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.


5
6
7
# File 'app/services/resource_events/change_state_service.rb', line 5

def resource
  @resource
end

#userObject (readonly)

Returns the value of attribute user.


5
6
7
# File 'app/services/resource_events/change_state_service.rb', line 5

def user
  @user
end

Instance Method Details

#execute(params) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/resource_events/change_state_service.rb', line 12

def execute(params)
  @params = params

  ResourceStateEvent.create(
    user: user,
    resource.noteable_target_type_name => resource,
    source_commit: commit_id_of(mentionable_source),
    source_merge_request_id: merge_request_id_of(mentionable_source),
    state: ResourceStateEvent.states[state],
    close_after_error_tracking_resolve: close_after_error_tracking_resolve,
    close_auto_resolve_prometheus_alert: close_auto_resolve_prometheus_alert,
    created_at: resource.system_note_timestamp
  )

  resource.expire_note_etag_cache
end