Commit ffe135cc authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Bob Van Landuyt

Move functionality for resolving discussions into a concern

parent 6ffa988a
...@@ -64,16 +64,15 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -64,16 +64,15 @@ class Projects::IssuesController < Projects::ApplicationController
params[:issue] ||= ActionController::Parameters.new( params[:issue] ||= ActionController::Parameters.new(
assignee_id: "" assignee_id: ""
) )
build_params = issue_params.merge( build_params = issue_params.merge(
merge_request_for_resolving_discussions: params[:merge_request_for_resolving_discussions], merge_request_for_resolving_discussions: params[:merge_request_for_resolving_discussions],
discussion_to_resolve: params[:discussion_to_resolve] discussion_to_resolve: params[:discussion_to_resolve]
) )
service = Issues::BuildService.new(project, current_user, build_params) service = Issues::BuildService.new(project, current_user, build_params)
@merge_request_for_resolving_discussions = service.merge_request_for_resolving_discussions
@discussion_to_resolve = service.discussions_to_resolve.first if params[:discussion_to_resolve]
@issue = @noteable = service.execute @issue = @noteable = service.execute
@merge_request_for_resolving_discussions = service.merge_request_for_resolving_discussions
@discussion_to_resolve = service.discussions_to_resolve.first if params[:discussion_to_resolve]
respond_with(@issue) respond_with(@issue)
end end
......
module Issues module Issues
class BaseService < ::IssuableBaseService class BaseService < ::IssuableBaseService
attr_reader :merge_request_for_resolving_discussions_iid, :discussion_to_resolve_id
def initialize(*args)
super
@merge_request_for_resolving_discussions_iid ||= params.delete(:merge_request_for_resolving_discussions)
@discussion_to_resolve_id ||= params.delete(:discussion_to_resolve)
end
def hook_data(issue, action) def hook_data(issue, action)
issue_data = issue.to_hook_data(current_user) issue_data = issue.to_hook_data(current_user)
issue_url = Gitlab::UrlBuilder.build(issue) issue_url = Gitlab::UrlBuilder.build(issue)
...@@ -15,25 +7,6 @@ module Issues ...@@ -15,25 +7,6 @@ module Issues
issue_data issue_data
end end
def merge_request_for_resolving_discussions
@merge_request_for_resolving_discussions ||= MergeRequestsFinder.new(current_user, project_id: project.id).
execute.
find_by(iid: merge_request_for_resolving_discussions_iid)
end
def discussions_to_resolve
return [] unless merge_request_for_resolving_discussions
@discussions_to_resolve ||= NotesFinder.new(project, current_user, {
discussion_id: discussion_to_resolve_id,
target_type: MergeRequest.name.underscore,
target_id: merge_request_for_resolving_discussions.id
}).
execute.
discussions.
select(&:to_be_resolved?)
end
private private
def execute_hooks(issue, action = 'open') def execute_hooks(issue, action = 'open')
......
module Issues module Issues
class BuildService < Issues::BaseService class BuildService < Issues::BaseService
include ResolveDiscussions
def execute def execute
filter_resolve_discussion_params
@issue = project.issues.new(issue_params) @issue = project.issues.new(issue_params)
end end
......
module Issues module Issues
class CreateService < Issues::BaseService class CreateService < Issues::BaseService
include SpamCheckService include SpamCheckService
include ResolveDiscussions
def execute def execute
filter_spam_check_params filter_spam_check_params
filter_resolve_discussion_params
issue_attributes = params.merge( issue_attributes = params.merge(
merge_request_for_resolving_discussions: merge_request_for_resolving_discussions_iid, merge_request_for_resolving_discussions: merge_request_for_resolving_discussions_iid,
...@@ -28,15 +30,6 @@ module Issues ...@@ -28,15 +30,6 @@ module Issues
resolve_discussions_with_issue(issuable) resolve_discussions_with_issue(issuable)
end end
def resolve_discussions_with_issue(issue)
return if discussions_to_resolve.empty?
Discussions::ResolveService.new(project, current_user,
merge_request: merge_request_for_resolving_discussions,
follow_up_issue: issue).
execute(discussions_to_resolve)
end
private private
def user_agent_detail_service def user_agent_detail_service
......
module Issues
module ResolveDiscussions
attr_reader :merge_request_for_resolving_discussions_iid, :discussion_to_resolve_id
def filter_resolve_discussion_params
@merge_request_for_resolving_discussions_iid ||= params.delete(:merge_request_for_resolving_discussions)
@discussion_to_resolve_id ||= params.delete(:discussion_to_resolve)
end
def resolve_discussions_with_issue(issue)
return if discussions_to_resolve.empty?
Discussions::ResolveService.new(project, current_user,
merge_request: merge_request_for_resolving_discussions,
follow_up_issue: issue).
execute(discussions_to_resolve)
end
def merge_request_for_resolving_discussions
@merge_request_for_resolving_discussions ||= MergeRequestsFinder.new(current_user, project_id: project.id).
execute.
find_by(iid: merge_request_for_resolving_discussions_iid)
end
def discussions_to_resolve
return [] unless merge_request_for_resolving_discussions
@discussions_to_resolve ||= NotesFinder.new(project, current_user, {
discussion_id: discussion_to_resolve_id,
target_type: MergeRequest.name.underscore,
target_id: merge_request_for_resolving_discussions.id
}).execute.discussions.select(&:to_be_resolved?)
end
end
end
require 'spec_helper.rb' require 'spec_helper.rb'
describe Issues::BaseService, services: true do class DummyService < Issues::BaseService
include ::Issues::ResolveDiscussions
def initialize(*args)
super
filter_resolve_discussion_params
end
end
describe DummyService, services: true do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -46,11 +55,11 @@ describe Issues::BaseService, services: true do ...@@ -46,11 +55,11 @@ describe Issues::BaseService, services: true do
end end
it "contains only unresolved discussions" do it "contains only unresolved discussions" do
second_discussion = Discussion.new([create(:diff_note_on_merge_request, :resolved, _second_discussion = Discussion.new([create(:diff_note_on_merge_request, :resolved,
noteable: merge_request, noteable: merge_request,
project: merge_request.target_project, project: merge_request.target_project,
line_number: 15, line_number: 15,
)]) )])
service = described_class.new( service = described_class.new(
project, project,
user, user,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment