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
# File 'app/services/resource_events/change_state_service.rb', line 7

def initialize(user:, resource:)
  @user, @resource = user, 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


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

def execute(params)
  @params = params

  ResourceStateEvent.create(
    user: user,
    issue: issue,
    merge_request: merge_request,
    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: Time.zone.now)

  resource.expire_note_etag_cache
end