gitlab-org--gitlab-foss/app/services/quick_actions/target_service.rb
Yorick Peterse 2039c8280d
Disable existing offenses for the CodeReuse cops
This whitelists all existing offenses for the various CodeReuse cops, of
which most are triggered by the CodeReuse/ActiveRecord cop.
2018-09-11 17:32:00 +02:00

34 lines
874 B
Ruby

# 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
# rubocop: disable CodeReuse/ActiveRecord
def issue(type_id)
IssuesFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.issues.build
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def merge_request(type_id)
MergeRequestsFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.merge_requests.build
end
# rubocop: enable CodeReuse/ActiveRecord
def commit(type_id)
project.commit(type_id)
end
end
end