Commit 4bfd54f3 authored by Bart Libert's avatar Bart Libert

Import bitbucket issues that are reported by an anonymous user

For these kind of issues, the "reporter" field is present but zero.
In such a case, "fetch" will not return the default value, but it will
return nil.
Hence, importing fails, because the "username" field of nil is referenced

Fixes issue #44381
parent 942fe5fe
---
title: Import bitbucket issues that are reported by an anonymous user
merge_request: 18199
author: bartl
type: fixed
...@@ -12,7 +12,7 @@ module Bitbucket ...@@ -12,7 +12,7 @@ module Bitbucket
end end
def author def author
raw.fetch('reporter', {}).fetch('username', nil) raw.dig('reporter', 'username')
end end
def description def description
......
...@@ -9,6 +9,7 @@ module Gitlab ...@@ -9,6 +9,7 @@ module Gitlab
end end
def author_line(author) def author_line(author)
author ||= "Anonymous"
"*Created by: #{author}*\n\n" "*Created by: #{author}*\n\n"
end end
end end
......
...@@ -19,6 +19,18 @@ describe Gitlab::BitbucketImport::Importer do ...@@ -19,6 +19,18 @@ describe Gitlab::BitbucketImport::Importer do
] ]
end end
let(:reporters) do
[
nil,
{ "username" => "reporter1" },
nil,
{ "username" => "reporter2" },
{ "username" => "reporter1" },
nil,
{ "username" => "reporter3" }
]
end
let(:sample_issues_statuses) do let(:sample_issues_statuses) do
issues = [] issues = []
...@@ -36,6 +48,10 @@ describe Gitlab::BitbucketImport::Importer do ...@@ -36,6 +48,10 @@ describe Gitlab::BitbucketImport::Importer do
} }
end end
reporters.map.with_index do |reporter, index|
issues[index]['reporter'] = reporter
end
issues issues
end end
...@@ -147,5 +163,19 @@ describe Gitlab::BitbucketImport::Importer do ...@@ -147,5 +163,19 @@ describe Gitlab::BitbucketImport::Importer do
expect(importer.errors).to be_empty expect(importer.errors).to be_empty
end end
end end
describe 'issue import' do
it 'maps reporters to anonymous if bitbucket reporter is nil' do
allow(importer).to receive(:import_wiki)
importer.execute
expect(project.issues.size).to eq(7)
expect(project.issues.where("description LIKE ?", '%Anonymous%').size).to eq(3)
expect(project.issues.where("description LIKE ?", '%reporter1%').size).to eq(2)
expect(project.issues.where("description LIKE ?", '%reporter2%').size).to eq(1)
expect(project.issues.where("description LIKE ?", '%reporter3%').size).to eq(1)
expect(importer.errors).to be_empty
end
end
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