Commit 3f9a3565 authored by Jarka Košanová's avatar Jarka Košanová

Fix assigning issues to users for Jira import

parent 0138ae8a
......@@ -29,9 +29,11 @@ module Gitlab
def create_issue(issue_attributes, project_id)
label_ids = issue_attributes.delete('label_ids')
assignee_ids = issue_attributes.delete('assignee_ids')
issue_id = insert_and_return_id(issue_attributes, Issue)
label_issue(project_id, issue_id, label_ids)
assign_issue(project_id, issue_id, assignee_ids)
issue_id
end
......@@ -49,6 +51,14 @@ module Gitlab
Gitlab::Database.bulk_insert(LabelLink.table_name, label_link_attrs)
end
def assign_issue(project_id, issue_id, assignee_ids)
return if assignee_ids.blank?
assignee_attrs = assignee_ids.map { |user_id| { issue_id: issue_id, user_id: user_id } }
Gitlab::Database.bulk_insert(IssueAssignee.table_name, assignee_attrs)
end
def build_label_attrs(issue_id, label_id)
time = Time.now
{
......
......@@ -19,9 +19,12 @@ describe Gitlab::JiraImport::ImportIssueWorker do
subject { described_class.new }
describe '#perform', :clean_gitlab_redis_cache do
let(:assignee_ids) { [user.id] }
let(:issue_attrs) do
build(:issue, project_id: project.id, title: 'jira issue')
.as_json.merge('label_ids' => [jira_issue_label_1.id, jira_issue_label_2.id]).compact
.as_json.merge(
'label_ids' => [jira_issue_label_1.id, jira_issue_label_2.id], 'assignee_ids' => assignee_ids
).compact
end
context 'when any exception raised while inserting to DB' do
......@@ -67,6 +70,23 @@ describe Gitlab::JiraImport::ImportIssueWorker do
expect(issue.title).to eq('jira issue')
expect(issue.project).to eq(project)
expect(issue.labels).to match_array([label, jira_issue_label_1, jira_issue_label_2])
expect(issue.assignees).to eq([user])
end
context 'when assignee_ids is nil' do
let(:assignee_ids) { nil }
it 'creates an issue without assignee' do
expect(Issue.last.assignees).to be_empty
end
end
context 'when assignee_ids is an empty array' do
let(:assignee_ids) { [] }
it 'creates an issue without assignee' do
expect(Issue.last.assignees).to be_empty
end
end
end
end
......
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