debian-mirror-gitlab/app/services/merge_requests/assign_issues_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
1,020 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-11-03 12:29:30 +05:30
module MergeRequests
2021-06-08 01:23:25 +05:30
class AssignIssuesService < BaseProjectService
2016-11-03 12:29:30 +05:30
def assignable_issues
2023-03-04 22:38:38 +05:30
@assignable_issues ||= if current_user == merge_request.author
closes_issues.select do |issue|
!issue.is_a?(ExternalIssue) && !issue.assignees.present? && can?(current_user, :admin_issue, issue)
end
else
[]
end
2016-11-03 12:29:30 +05:30
end
def execute
assignable_issues.each do |issue|
2021-06-08 01:23:25 +05:30
Issues::UpdateService.new(project: issue.project, current_user: current_user, params: { assignee_ids: [current_user.id] }).execute(issue)
2016-11-03 12:29:30 +05:30
end
{
count: assignable_issues.count
}
end
private
def merge_request
params[:merge_request]
end
def closes_issues
@closes_issues ||= params[:closes_issues] || merge_request.closes_issues(current_user)
end
end
end