Commit 4095185d authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'fix-jira-labels' into 'master'

Fix creating labels for Jira import

See merge request gitlab-org/gitlab!30697
parents 6ddd51f8 a0904651
......@@ -28,19 +28,25 @@ module Gitlab
private
def create_issue(issue_attributes, project_id)
label_ids = issue_attributes.delete('label_ids')
issue_id = insert_and_return_id(issue_attributes, Issue)
label_issue(project_id, issue_id)
label_issue(project_id, issue_id, label_ids)
issue_id
end
def label_issue(project_id, issue_id)
label_id = JiraImport.get_import_label_id(project_id)
return unless label_id
def label_issue(project_id, issue_id, label_ids)
label_link_attrs = label_ids.to_a.map do |label_id|
build_label_attrs(issue_id, label_id.to_i)
end
label_link_attrs = build_label_attrs(issue_id, label_id.to_i)
insert_and_return_id(label_link_attrs, LabelLink)
import_label_id = JiraImport.get_import_label_id(project_id)
return unless import_label_id
label_link_attrs << build_label_attrs(issue_id, import_label_id.to_i)
Gitlab::Database.bulk_insert(LabelLink.table_name, label_link_attrs)
end
def build_label_attrs(issue_id, label_id)
......
......@@ -5,6 +5,8 @@ require 'spec_helper'
describe Gitlab::JiraImport::ImportIssueWorker do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:jira_issue_label_1) { create(:label, project: project) }
let_it_be(:jira_issue_label_2) { create(:label, project: project) }
let(:some_key) { 'some-key' }
describe 'modules' do
......@@ -17,7 +19,10 @@ describe Gitlab::JiraImport::ImportIssueWorker do
subject { described_class.new }
describe '#perform', :clean_gitlab_redis_cache do
let(:issue_attrs) { build(:issue, project_id: project.id).as_json.compact }
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
end
context 'when any exception raised while inserting to DB' do
before do
......@@ -47,14 +52,22 @@ describe Gitlab::JiraImport::ImportIssueWorker do
context 'when import label exists' do
before do
Gitlab::JiraImport.cache_import_label_id(project.id, label.id)
end
it 'does not record import failure' do
subject.perform(project.id, 123, issue_attrs, some_key)
end
it 'does not record import failure' do
expect(label.issues.count).to eq(1)
expect(Gitlab::Cache::Import::Caching.read(Gitlab::JiraImport.failed_issues_counter_cache_key(project.id)).to_i).to eq(0)
end
it 'creates an issue with the correct attributes' do
issue = Issue.last
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])
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