Class: Issues::BuildService

Inherits:
BaseService show all
Includes:
ResolveDiscussions
Defined in:
app/services/issues/build_service.rb

Constant Summary

Constants inherited from BaseService

Issues::BaseService::NO_REBALANCING_NEEDED

Constants included from Gitlab::Utils::UsageData

Gitlab::Utils::UsageData::FALLBACK

Instance Attribute Summary

Attributes included from ResolveDiscussions

#discussion_to_resolve_id, #merge_request_to_resolve_discussions_of_iid

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from ResolveDiscussions

#discussions_to_resolve, #filter_resolve_discussion_params, #merge_request_to_resolve_discussions_of

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from BaseService

#close_service, #hook_data, #rebalance_if_needed, #reopen_service

Methods included from IncidentManagement::UsageData

#track_event, #track_incident_action

Methods included from Gitlab::Utils::UsageData

#alt_usage_data, #count, #distinct_count, #measure_duration, #redis_usage_data, #sum, #track_usage_event, #with_finished_at, #with_prometheus_client

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Instance Method Details

#description_for_discussionsObject


24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/issues/build_service.rb', line 24

def description_for_discussions
  if discussions_to_resolve.empty?
    return "There are no unresolved discussions. "\
           "Review the conversation in #{merge_request_to_resolve_discussions_of.to_reference}"
  end

  description = "The following #{'discussion'.pluralize(discussions_to_resolve.size)} "\
                "from #{merge_request_to_resolve_discussions_of.to_reference} "\
                "should be addressed:"

  [description, *items_for_discussions].join("\n\n")
end

#executeObject


7
8
9
10
11
12
# File 'app/services/issues/build_service.rb', line 7

def execute
  filter_resolve_discussion_params
  @issue = project.issues.new(issue_params).tap do |issue|
    ensure_milestone_available(issue)
  end
end

#issue_paramsObject


61
62
63
# File 'app/services/issues/build_service.rb', line 61

def issue_params
  @issue_params ||= build_issue_params
end

#issue_params_with_info_from_discussionsObject


14
15
16
17
18
# File 'app/services/issues/build_service.rb', line 14

def issue_params_with_info_from_discussions
  return {} unless merge_request_to_resolve_discussions_of

  { title: title_from_merge_request, description: description_for_discussions }
end

#item_for_discussion(discussion) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/services/issues/build_service.rb', line 41

def item_for_discussion(discussion)
  first_note_to_resolve = discussion.first_note_to_resolve || discussion.first_note

  is_very_first_note = first_note_to_resolve == discussion.first_note
  action = is_very_first_note ? "started" : "commented on"

  note_url = Gitlab::UrlBuilder.build(first_note_to_resolve)

  other_note_count = discussion.notes.size - 1

  discussion_info = ["- [ ] #{first_note_to_resolve.author.to_reference} #{action} a [discussion](#{note_url}): "]
  discussion_info << "(+#{other_note_count} #{'comment'.pluralize(other_note_count)})" if other_note_count > 0

  note_without_block_quotes = Banzai::Filter::BlockquoteFenceFilter.new(first_note_to_resolve.note).call
  spaces = ' ' * 4
  quote = note_without_block_quotes.lines.map { |line| "#{spaces}> #{line}" }.join

  [discussion_info.join(' '), quote].join("\n\n")
end

#items_for_discussionsObject


37
38
39
# File 'app/services/issues/build_service.rb', line 37

def items_for_discussions
  discussions_to_resolve.map { |discussion| item_for_discussion(discussion) }
end

#title_from_merge_requestObject


20
21
22
# File 'app/services/issues/build_service.rb', line 20

def title_from_merge_request
  "Follow-up from \"#{merge_request_to_resolve_discussions_of.title}\""
end