Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/quick_actions')
-rw-r--r--lib/gitlab/quick_actions/issue_actions.rb63
-rw-r--r--lib/gitlab/quick_actions/merge_request_actions.rb39
-rw-r--r--lib/gitlab/quick_actions/timeline_text_and_date_time_separator.rb58
3 files changed, 134 insertions, 26 deletions
diff --git a/lib/gitlab/quick_actions/issue_actions.rb b/lib/gitlab/quick_actions/issue_actions.rb
index 189627506f3..4883c649a62 100644
--- a/lib/gitlab/quick_actions/issue_actions.rb
+++ b/lib/gitlab/quick_actions/issue_actions.rb
@@ -207,19 +207,22 @@ module Gitlab
desc { _('Add Zoom meeting') }
explanation { _('Adds a Zoom meeting.') }
- params '<Zoom URL>'
+ params do
+ zoom_link_params
+ end
types Issue
condition do
@zoom_service = zoom_link_service
+
@zoom_service.can_add_link?
end
- parse_params do |link|
- @zoom_service.parse_link(link)
+ parse_params do |link_params|
+ @zoom_service.parse_link(link_params)
end
- command :zoom do |link|
- result = @zoom_service.add_link(link)
+ command :zoom do |link, link_text = nil|
+ result = add_zoom_link(link, link_text)
@execution_message[:zoom] = result.message
- @updates.merge!(result.payload) if result.payload
+ merge_updates(result, @updates)
end
desc { _('Remove Zoom meeting') }
@@ -315,12 +318,52 @@ module Gitlab
@updates[:remove_contacts] = contact_emails.split(' ')
end
- private
-
- def zoom_link_service
- ::Issues::ZoomLinkService.new(project: quick_action_target.project, current_user: current_user, params: { issue: quick_action_target })
+ desc { _('Add a timeline event to incident') }
+ explanation { _('Adds a timeline event to incident.') }
+ params '<timeline comment> | <date(YYYY-MM-DD)> <time(HH:MM)>'
+ types Issue
+ condition do
+ quick_action_target.incident? &&
+ current_user.can?(:admin_incident_management_timeline_event, quick_action_target)
+ end
+ parse_params do |event_params|
+ Gitlab::QuickActions::TimelineTextAndDateTimeSeparator.new(event_params).execute
+ end
+ command :timeline do |event_text, date_time|
+ if event_text && date_time
+ timeline_event = timeline_event_create_service(event_text, date_time).execute
+
+ @execution_message[:timeline] =
+ if timeline_event.success?
+ _('Timeline event added successfully.')
+ else
+ _('Something went wrong while adding timeline event.')
+ end
+ end
end
end
+
+ private
+
+ def zoom_link_service
+ ::Issues::ZoomLinkService.new(project: quick_action_target.project, current_user: current_user, params: { issue: quick_action_target })
+ end
+
+ def zoom_link_params
+ '<Zoom URL>'
+ end
+
+ def add_zoom_link(link, _link_text)
+ zoom_link_service.add_link(link)
+ end
+
+ def merge_updates(result, update_hash)
+ update_hash.merge!(result.payload) if result.payload
+ end
+
+ def timeline_event_create_service(event_text, event_date_time)
+ ::IncidentManagement::TimelineEvents::CreateService.new(quick_action_target, current_user, { note: event_text, occurred_at: event_date_time, editable: true })
+ end
end
end
end
diff --git a/lib/gitlab/quick_actions/merge_request_actions.rb b/lib/gitlab/quick_actions/merge_request_actions.rb
index 3cb01db1491..d38b81bff0b 100644
--- a/lib/gitlab/quick_actions/merge_request_actions.rb
+++ b/lib/gitlab/quick_actions/merge_request_actions.rb
@@ -88,33 +88,21 @@ module Gitlab
@execution_message[:rebase] = _('Scheduled a rebase of branch %{branch}.') % { branch: branch }
end
- desc { _('Toggle the Draft status') }
+ desc { _('Set the Draft status') }
explanation do
- noun = quick_action_target.to_ability_name.humanize(capitalize: false)
- if quick_action_target.draft?
- _("Marks this %{noun} as ready.")
- else
- _("Marks this %{noun} as a draft.")
- end % { noun: noun }
+ draft_action_message(_("Marks"))
end
execution_message do
- noun = quick_action_target.to_ability_name.humanize(capitalize: false)
- if quick_action_target.draft?
- _("Marked this %{noun} as ready.")
- else
- _("Marked this %{noun} as a draft.")
- end % { noun: noun }
+ draft_action_message(_("Marked"))
end
types MergeRequest
condition do
quick_action_target.respond_to?(:draft?) &&
- # Allow it to mark as draft on MR creation page or through MR notes
- #
(quick_action_target.new_record? || current_user.can?(:"update_#{quick_action_target.to_ability_name}", quick_action_target))
end
command :draft do
- @updates[:wip_event] = quick_action_target.draft? ? 'ready' : 'draft'
+ @updates[:wip_event] = draft_action_command
end
desc { _('Set the Ready status') }
@@ -317,6 +305,25 @@ module Gitlab
end
end
+ def draft_action_message(verb)
+ noun = quick_action_target.to_ability_name.humanize(capitalize: false)
+ if !quick_action_target.draft?
+ _("%{verb} this %{noun} as a draft.")
+ elsif Feature.disabled?(:draft_quick_action_non_toggle, quick_action_target.project)
+ _("%{verb} this %{noun} as ready.")
+ else
+ _("No change to this %{noun}'s draft status.")
+ end % { verb: verb, noun: noun }
+ end
+
+ def draft_action_command
+ if Feature.disabled?(:draft_quick_action_non_toggle, quick_action_target.project)
+ quick_action_target.draft? ? 'ready' : 'draft'
+ else
+ 'draft'
+ end
+ end
+
def merge_orchestration_service
@merge_orchestration_service ||= ::MergeRequests::MergeOrchestrationService.new(project, current_user)
end
diff --git a/lib/gitlab/quick_actions/timeline_text_and_date_time_separator.rb b/lib/gitlab/quick_actions/timeline_text_and_date_time_separator.rb
new file mode 100644
index 00000000000..e8002656ff5
--- /dev/null
+++ b/lib/gitlab/quick_actions/timeline_text_and_date_time_separator.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module QuickActions
+ class TimelineTextAndDateTimeSeparator
+ DATETIME_REGEX = %r{(\d{2,4}[\-.]\d{1,2}[\-.]\d{1,2} \d{1,2}:\d{2})}.freeze
+ MIXED_DELIMITER = %r{([/.])}.freeze
+ TIME_REGEX = %r{(\d{1,2}:\d{2})}.freeze
+
+ def initialize(timeline_event_arg)
+ @timeline_event_arg = timeline_event_arg
+ @timeline_text = get_text
+ @timeline_date_string = get_raw_date_string
+ end
+
+ def execute
+ return if @timeline_event_arg.blank?
+ return if date_contains_mixed_delimiters?
+ return [@timeline_text, get_current_date_time] unless date_time_present?
+ return unless valid_date?
+
+ [@timeline_text, get_actual_date_time]
+ end
+
+ private
+
+ def get_text
+ @timeline_event_arg.split('|')[0]&.strip
+ end
+
+ def get_raw_date_string
+ @timeline_event_arg.split('|')[1]&.strip
+ end
+
+ def get_current_date_time
+ DateTime.current.strftime("%Y-%m-%d %H:%M:00 UTC")
+ end
+
+ def get_actual_date_time
+ DateTime.parse(@timeline_date_string)
+ end
+
+ def date_time_present?
+ DATETIME_REGEX =~ @timeline_date_string || TIME_REGEX =~ @timeline_date_string
+ end
+
+ def date_contains_mixed_delimiters?
+ MIXED_DELIMITER =~ @timeline_date_string
+ end
+
+ def valid_date?
+ get_actual_date_time
+ rescue Date::Error
+ nil
+ end
+ end
+ end
+end