2018-08-09 05:04:12 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module QuickActions
|
|
|
|
class TargetService < BaseService
|
|
|
|
def execute(type, type_id)
|
|
|
|
case type&.downcase
|
|
|
|
when 'issue'
|
|
|
|
issue(type_id)
|
|
|
|
when 'mergerequest'
|
|
|
|
merge_request(type_id)
|
|
|
|
when 'commit'
|
|
|
|
commit(type_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-08-09 05:04:12 -04:00
|
|
|
def issue(type_id)
|
|
|
|
IssuesFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.issues.build
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-08-09 05:04:12 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-08-09 05:04:12 -04:00
|
|
|
def merge_request(type_id)
|
|
|
|
MergeRequestsFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.merge_requests.build
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-08-09 05:04:12 -04:00
|
|
|
|
|
|
|
def commit(type_id)
|
|
|
|
project.commit(type_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-10-29 08:06:40 -04:00
|
|
|
|
|
|
|
QuickActions::TargetService.prepend_if_ee('EE::QuickActions::TargetService')
|