2021-12-11 22:18:48 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module TasksToBeDone
|
2023-06-20 00:43:36 +05:30
|
|
|
class BaseService < ::BaseContainerService
|
2021-12-11 22:18:48 +05:30
|
|
|
LABEL_PREFIX = 'tasks to be done'
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def initialize(container:, current_user:, assignee_ids: [])
|
2021-12-11 22:18:48 +05:30
|
|
|
params = {
|
|
|
|
assignee_ids: assignee_ids,
|
|
|
|
title: title,
|
|
|
|
description: description,
|
|
|
|
add_labels: label_name
|
|
|
|
}
|
2023-05-27 22:25:52 +05:30
|
|
|
super(container: container, current_user: current_user, params: params)
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
if (issue = existing_task_issue)
|
2023-04-23 21:23:45 +05:30
|
|
|
update_service = Issues::UpdateService.new(container: project, current_user: current_user, params: { add_assignee_ids: params[:assignee_ids] })
|
2021-12-11 22:18:48 +05:30
|
|
|
update_service.execute(issue)
|
|
|
|
else
|
2023-06-20 00:43:36 +05:30
|
|
|
create_service = Issues::CreateService.new(container: project, current_user: current_user, params: params, spam_params: nil)
|
|
|
|
create_service.execute
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def existing_task_issue
|
|
|
|
IssuesFinder.new(
|
|
|
|
current_user,
|
|
|
|
project_id: project.id,
|
|
|
|
state: 'opened',
|
|
|
|
non_archived: true,
|
|
|
|
label_name: label_name
|
|
|
|
).execute.last
|
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def label_suffix
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def label_name
|
|
|
|
"#{LABEL_PREFIX}:#{label_suffix}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|