diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-24 21:09:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-24 21:09:05 +0300 |
commit | c2367afbf57ebc65d5b78a743b5d6a91f0aece9f (patch) | |
tree | 165c2c54bf72ab3a3a9417d97f63ece5c9eba9f5 /app/services/resource_events | |
parent | 51a9512965d86e3094968fa514e4ae8a96d38cf3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/resource_events')
-rw-r--r-- | app/services/resource_events/change_milestone_service.rb | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/app/services/resource_events/change_milestone_service.rb b/app/services/resource_events/change_milestone_service.rb index bad7d002c65..dd637bcc765 100644 --- a/app/services/resource_events/change_milestone_service.rb +++ b/app/services/resource_events/change_milestone_service.rb @@ -2,49 +2,35 @@ module ResourceEvents class ChangeMilestoneService - attr_reader :resource, :user, :event_created_at, :resource_args + attr_reader :resource, :user, :event_created_at, :milestone def initialize(resource:, user:, created_at: Time.now) @resource = resource @user = user @event_created_at = created_at - - @resource_args = { - user_id: user.id, - created_at: event_created_at - } + @milestone = resource&.milestone end def execute - args = build_resource_args - - action = if milestone.nil? - :remove - else - :add - end + ResourceMilestoneEvent.create(build_resource_args) - record = args.merge(milestone_id: milestone&.id, action: ResourceMilestoneEvent.actions[action]) - - create_event(record) + resource.expire_note_etag_cache end private - def milestone - resource&.milestone - end - - def create_event(record) - ResourceMilestoneEvent.create(record) - - resource.expire_note_etag_cache - end - def build_resource_args - key = resource.class.name.underscore.foreign_key + action = milestone.blank? ? :remove : :add + key = resource.class.name.foreign_key - resource_args.merge(key => resource.id, state: ResourceMilestoneEvent.states[resource.state]) + { + user_id: user.id, + created_at: event_created_at, + milestone_id: milestone&.id, + state: ResourceMilestoneEvent.states[resource.state], + action: ResourceMilestoneEvent.actions[action], + key => resource.id + } end end end |