debian-mirror-gitlab/lib/gitlab/quick_actions/relate_actions.rb

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

52 lines
1.5 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
module Gitlab
module QuickActions
module RelateActions
extend ActiveSupport::Concern
include ::Gitlab::QuickActions::Dsl
included do
2022-07-23 23:45:48 +05:30
desc { _('Mark this issue as related to another issue') }
2023-07-09 08:55:56 +05:30
explanation do |target_issues|
_('Marks this issue as related to %{issue_ref}.') % { issue_ref: target_issues.to_sentence }
2020-11-24 15:15:51 +05:30
end
2023-07-09 08:55:56 +05:30
execution_message do |target_issues|
_('Marked this issue as related to %{issue_ref}.') % { issue_ref: target_issues.to_sentence }
2020-11-24 15:15:51 +05:30
end
2023-07-09 08:55:56 +05:30
params '<#issue | group/project#issue | issue URL>'
2020-11-24 15:15:51 +05:30
types Issue
2023-07-09 08:55:56 +05:30
condition { can_relate_issues? }
parse_params { |issues| format_params(issues) }
command :relate do |target_issues|
create_links(target_issues)
2020-11-24 15:15:51 +05:30
end
2023-07-09 08:55:56 +05:30
private
def create_links(references, type: 'relates_to')
service = IssueLinks::CreateService.new(
quick_action_target,
current_user, { issuable_references: references, link_type: type }
)
2021-11-18 22:05:49 +05:30
create_issue_link = proc { service.execute }
if quick_action_target.persisted?
create_issue_link.call
else
quick_action_target.run_after_commit(&create_issue_link)
end
2020-11-24 15:15:51 +05:30
end
2023-07-09 08:55:56 +05:30
def can_relate_issues?
current_user.can?(:admin_issue_link, quick_action_target)
end
def format_params(issue_references)
issue_references.split(' ')
end
2020-11-24 15:15:51 +05:30
end
end
end
end