gitlab-org--gitlab-foss/app/services/resource_events/change_milestone_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
736 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module ResourceEvents
class ChangeMilestoneService < BaseChangeTimeboxService
attr_reader :milestone, :old_milestone
def initialize(resource, user, old_milestone:)
super(resource, user)
@milestone = resource&.milestone
@old_milestone = old_milestone
end
private
def create_event
ResourceMilestoneEvent.create(build_resource_args)
end
def build_resource_args
action = milestone.blank? ? :remove : :add
super.merge({
state: ResourceMilestoneEvent.states[resource.state],
action: ResourceTimeboxEvent.actions[action],
milestone_id: milestone.blank? ? old_milestone&.id : milestone&.id
})
end
end
end