Skip to content
代码片段 群组 项目
未验证 提交 aff2bb07 编辑于 作者: Ivane Gkomarteli's avatar Ivane Gkomarteli 提交者: GitLab
浏览文件

Add importing: true to events created by FogBugz import

Adding importing: true ensure to skip validations and callbacks
that are not needed when importing.

Related:
  - https://gitlab.com/gitlab-org/gitlab/-/issues/441114
  - https://gitlab.com/gitlab-org/gitlab/-/issues/434114
上级 90b65a33
No related branches found
No related tags found
无相关合并请求
...@@ -158,42 +158,40 @@ def opened_content(comments) ...@@ -158,42 +158,40 @@ def opened_content(comments)
end end
def import_issue_comments(issue, comments) def import_issue_comments(issue, comments)
Note.transaction do while comment = comments.shift
while comment = comments.shift verb = comment['sVerb']
verb = comment['sVerb']
next if verb == 'Opened'
next if verb == 'Opened'
content = format_content(comment['s'])
content = format_content(comment['s']) attachments = format_attachments(comment['rgAttachments'])
attachments = format_attachments(comment['rgAttachments']) updates = format_updates(comment)
updates = format_updates(comment)
next if content.blank? && attachments.empty? && updates.empty?
next if content.blank? && attachments.empty? && updates.empty?
author = user_info(comment['ixPerson'])[:name]
author = user_info(comment['ixPerson'])[:name] author_id = user_info(comment['ixPerson'])[:gitlab_id] || project.creator_id
author_id = user_info(comment['ixPerson'])[:gitlab_id] || project.creator_id date = DateTime.parse(comment['dt'])
date = DateTime.parse(comment['dt'])
body = format_issue_comment_body(
body = format_issue_comment_body( comment['ixBugEvent'],
comment['ixBugEvent'], author,
author, date,
date, content,
content, attachments,
attachments, updates
updates )
)
Note.create!(
note = Note.create!( importing: true,
project_id: project.id, project_id: project.id,
noteable_type: "Issue", noteable_type: "Issue",
noteable_id: issue.id, noteable_id: issue.id,
author_id: author_id, author_id: author_id,
note: body note: body,
) created_at: date,
updated_at: date
note.update_attribute(:created_at, date) )
note.update_attribute(:updated_at, date)
end
end end
end end
......
...@@ -10,29 +10,20 @@ ...@@ -10,29 +10,20 @@
let(:token) { 'token' } let(:token) { 'token' }
let(:credentials) { { 'fb_session' => { 'uri' => base_url, 'token' => token } } } let(:credentials) { { 'fb_session' => { 'uri' => base_url, 'token' => token } } }
let(:closed_bug) do let(:bug_fopen) { 'false' }
let(:bug_events) { [] }
let(:bug) do
{ {
fOpen: 'false', fOpen: bug_fopen,
sTitle: 'Closed bug', sTitle: 'Bug title',
sLatestTextSummary: "", sLatestTextSummary: "",
dtOpened: Time.now.to_s, dtOpened: Time.now.to_s,
dtLastUpdated: Time.now.to_s, dtLastUpdated: Time.now.to_s,
events: { event: [] } events: { event: bug_events }
}.with_indifferent_access }.with_indifferent_access
end end
let(:opened_bug) do let(:fogbugz_bugs) { [bug] }
{
fOpen: 'true',
sTitle: 'Opened bug',
sLatestTextSummary: "",
dtOpened: Time.now.to_s,
dtLastUpdated: Time.now.to_s,
events: { event: [] }
}.with_indifferent_access
end
let(:fogbugz_bugs) { [opened_bug, closed_bug] }
subject(:importer) { described_class.new(project) } subject(:importer) { described_class.new(project) }
...@@ -44,24 +35,56 @@ ...@@ -44,24 +35,56 @@
stub_fogbugz('search', cases: { case: fogbugz_bugs, count: fogbugz_bugs.size }) stub_fogbugz('search', cases: { case: fogbugz_bugs, count: fogbugz_bugs.size })
end end
it 'imports bugs' do it 'imports the bug', :aggregate_failures do
expect { subject.execute }.to change { Issue.count }.by(2) expect { subject.execute }.to change { Issue.count }.by(1)
issue = Issue.where(project_id: project.id).find_by_title(bug[:sTitle])
expect(issue.state_id).to eq(Issue.available_states[:closed])
end end
it 'imports opened bugs' do context 'when importing an opened bug' do
subject.execute let(:bug_fopen) { 'true' }
it 'imports the bug' do
expect { subject.execute }.to change { Issue.count }.by(1)
issue = Issue.where(project_id: project.id).find_by_title(opened_bug[:sTitle]) issue = Issue.where(project_id: project.id).find_by_title(bug[:sTitle])
expect(issue.state_id).to eq(Issue.available_states[:opened]) expect(issue.state_id).to eq(Issue.available_states[:opened])
end
end end
it 'imports closed bugs' do context 'when importing multiple bugs' do
subject.execute let(:fogbugz_bugs) { [bug, bug] }
issue = Issue.where(project_id: project.id).find_by_title(closed_bug[:sTitle]) it 'imports the bugs' do
expect { subject.execute }.to change { Issue.count }.by(2)
end
end
expect(issue.state_id).to eq(Issue.available_states[:closed]) context 'when imported bug contains events' do
let(:event_time) { Time.now.to_s }
let(:bug_events) do
[
{ sVerb: 'Opened', s: 'First event', dt: event_time },
{ sVerb: 'Assigned', s: 'Second event', dt: event_time }
]
end
let(:expected_note_timestamp) { DateTime.parse(event_time) }
it 'imports the correct event', :aggregate_failures do
expect { subject.execute }.to change { Note.count }.by(1)
note = Note.where(project_id: project.id).last
expect(note).to have_attributes(
note: "*By on #{expected_note_timestamp} (imported from FogBugz)*\n\n---\n\n#{bug_events[1][:s]}",
created_at: expected_note_timestamp,
updated_at: expected_note_timestamp
)
end
end end
context 'verify url' do context 'verify url' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册