debian-mirror-gitlab/app/services/issues/create_service.rb

80 lines
2.3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module Issues
class CreateService < Issues::BaseService
2017-08-17 22:00:37 +05:30
include ResolveDiscussions
2020-11-24 15:15:51 +05:30
def execute(skip_system_notes: false)
2021-03-11 19:13:27 +05:30
@request = params.delete(:request)
@spam_params = Spam::SpamActionService.filter_spam_params!(params)
2017-08-17 22:00:37 +05:30
@issue = BuildService.new(project, current_user, params).execute
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
filter_resolve_discussion_params
2014-09-02 18:07:02 +05:30
2020-11-24 15:15:51 +05:30
create(@issue, skip_system_notes: skip_system_notes)
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
def before_create(issue)
2021-03-11 19:13:27 +05:30
Spam::SpamActionService.new(
spammable: issue,
request: request,
user: current_user,
action: :create
).execute(spam_params: spam_params)
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
# current_user (defined in BaseService) is not available within run_after_commit block
2017-09-10 17:25:29 +05:30
user = current_user
issue.run_after_commit do
NewIssueWorker.perform_async(issue.id, user.id)
2020-11-24 15:15:51 +05:30
IssuePlacementWorker.perform_async(nil, issue.project_id)
2017-09-10 17:25:29 +05:30
end
2016-09-13 17:45:13 +05:30
end
2020-11-24 15:15:51 +05:30
def after_create(issue)
add_incident_label(issue)
todo_service.new_issue(issue, current_user)
2016-09-13 17:45:13 +05:30
user_agent_detail_service.create
2020-11-24 15:15:51 +05:30
resolve_discussions_with_issue(issue)
delete_milestone_total_issue_counter_cache(issue.milestone)
track_incident_action(current_user, issue, :incident_created)
2018-03-17 18:26:18 +05:30
super
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
def resolve_discussions_with_issue(issue)
return if discussions_to_resolve.empty?
2016-09-13 17:45:13 +05:30
2017-08-17 22:00:37 +05:30
Discussions::ResolveService.new(project, current_user,
2020-06-23 00:09:42 +05:30
one_or_more_discussions: discussions_to_resolve,
follow_up_issue: issue).execute
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
private
2021-03-11 19:13:27 +05:30
attr_reader :request, :spam_params
2016-09-13 17:45:13 +05:30
def user_agent_detail_service
2021-03-11 19:13:27 +05:30
UserAgentDetailService.new(@issue, request)
2014-09-02 18:07:02 +05:30
end
2021-02-22 17:27:13 +05:30
# Applies label "incident" (creates it if missing) to incident issues.
# For use in "after" hooks only to ensure we are not appyling
# labels prematurely.
def add_incident_label(issue)
return unless issue.incident?
label = ::IncidentManagement::CreateIncidentLabelService
.new(project, current_user)
.execute
.payload[:label]
return if issue.label_ids.include?(label.id)
issue.labels << label
end
2014-09-02 18:07:02 +05:30
end
end
2019-12-04 20:38:33 +05:30
Issues::CreateService.prepend_if_ee('EE::Issues::CreateService')