debian-mirror-gitlab/app/services/quick_actions/target_service.rb

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

41 lines
1 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# 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-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-11-20 20:47:30 +05:30
def issue(type_id)
2021-01-03 14:25:43 +05:30
return project.issues.build if type_id.nil?
2018-11-20 20:47:30 +05:30
IssuesFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.issues.build
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-11-20 20:47:30 +05:30
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-11-20 20:47:30 +05:30
def merge_request(type_id)
2021-01-03 14:25:43 +05:30
return project.merge_requests.build if type_id.nil?
2018-11-20 20:47:30 +05:30
MergeRequestsFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.merge_requests.build
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-11-20 20:47:30 +05:30
def commit(type_id)
project.commit(type_id)
end
end
end
2019-12-26 22:10:19 +05:30
2021-06-08 01:23:25 +05:30
QuickActions::TargetService.prepend_mod_with('QuickActions::TargetService')