diff options
author | Peter Leitzen <pl@neopoly.de> | 2018-08-09 12:04:12 +0300 |
---|---|---|
committer | Peter Leitzen <pl@neopoly.de> | 2018-08-10 17:45:11 +0300 |
commit | 82337dd684d88ec38285d51cfb1180b1a1057b95 (patch) | |
tree | 98f698c00a86926c21dc74c08cbfb12ca2e21678 /app/services/quick_actions | |
parent | 2881886417ba08fb4a47fb95f43678578454766d (diff) |
Implement QuickActions::TargetService
Diffstat (limited to 'app/services/quick_actions')
-rw-r--r-- | app/services/quick_actions/target_service.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/app/services/quick_actions/target_service.rb b/app/services/quick_actions/target_service.rb new file mode 100644 index 00000000000..b29b141a309 --- /dev/null +++ b/app/services/quick_actions/target_service.rb @@ -0,0 +1,32 @@ +# 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 + + def issue(type_id) + IssuesFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.issues.build + end + + def merge_request(type_id) + MergeRequestsFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.merge_requests.build + end + + def commit(type_id) + return nil unless type_id + + project.commit(type_id) + end + end +end |