diff --git a/app/models/concerns/import/has_import_source.rb b/app/models/concerns/import/has_import_source.rb index e7be1200dec2b8908b2f87187889fa7f64c61cbd..fcbf6fe32a2cfc3012c1067ac993e1daa5a4b064 100644 --- a/app/models/concerns/import/has_import_source.rb +++ b/app/models/concerns/import/has_import_source.rb @@ -4,6 +4,7 @@ module Import SOURCE_DIRECT_TRANSFER = :gitlab_migration # aka BulkImports SOURCE_PROJECT_EXPORT_IMPORT = :gitlab_project SOURCE_GROUP_EXPORT_IMPORT = :gitlab_group + SOURCE_BITBUCKET_SERVER = :bitbucket_server module HasImportSource extend ActiveSupport::Concern @@ -15,7 +16,7 @@ module HasImportSource SOURCE_GROUP_EXPORT_IMPORT => 3, github: 4, bitbucket: 5, # aka bitbucket cloud - bitbucket_server: 6, + SOURCE_BITBUCKET_SERVER => 6, fogbugz: 7, gitea: 8, git: 9, # aka repository by url diff --git a/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb b/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb index 3aa1d88347a720be1868629c9de34a663db5fceb..198f0ed35615cf5bc78720f8b69c7ad5f2c16f79 100644 --- a/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb +++ b/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb @@ -34,7 +34,8 @@ def execute state_id: MergeRequest.available_states[object[:state]], author_id: user_finder.author_id(object), created_at: object[:created_at], - updated_at: object[:updated_at] + updated_at: object[:updated_at], + imported_from: ::Import::HasImportSource::IMPORT_SOURCES[:bitbucket_server] } creator = Gitlab::Import::MergeRequestCreator.new(project) diff --git a/lib/gitlab/bitbucket_server_import/importers/pull_request_notes/standalone_notes.rb b/lib/gitlab/bitbucket_server_import/importers/pull_request_notes/standalone_notes.rb index b3db7ff5075e06de6ad0be5c8145e76695fba889..fadddabd9edab9a8fcddaf1c4b4c1c5d5dcbb2d1 100644 --- a/lib/gitlab/bitbucket_server_import/importers/pull_request_notes/standalone_notes.rb +++ b/lib/gitlab/bitbucket_server_import/importers/pull_request_notes/standalone_notes.rb @@ -34,6 +34,10 @@ def execute(comment) comment_id: comment[:id] ) end + + def pull_request_comment_attributes(comment) + super(comment).merge(imported_from: ::Import::SOURCE_BITBUCKET_SERVER) + end end end end diff --git a/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer.rb b/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer.rb index 283c405eff21849bc9adb508b8c265435ac8f9c6..ef6715db3bef41f97780129c66779193c9317e97 100644 --- a/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer.rb +++ b/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer.rb @@ -217,7 +217,8 @@ def pull_request_comment_attributes(comment) note: note, author_id: author, created_at: comment.created_at, - updated_at: comment.updated_at + updated_at: comment.updated_at, + imported_from: ::Import::SOURCE_BITBUCKET_SERVER } end diff --git a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb index 9c11fb67f78bc1c7b2a5b049559aca65c2e712ec..24b867c475cab90a23f659bda4f69c40d564e602 100644 --- a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb @@ -33,7 +33,8 @@ reviewer_ids: match_array([reviewer_1.id, reviewer_2.id]), state: pull_request.state, author_id: project.creator_id, - description: "*Created by: #{pull_request.author}*\n\n#{pull_request.description}" + description: "*Created by: #{pull_request.author}*\n\n#{pull_request.description}", + imported_from: 'bitbucket_server' ) end diff --git a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes/standalone_notes_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes/standalone_notes_spec.rb index d0923687521a02b3a8e5d1213b76c54a00acd4f1..94a901f2d3b7508023492bf7cbaab0bd841e83d2 100644 --- a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes/standalone_notes_spec.rb +++ b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes/standalone_notes_spec.rb @@ -53,7 +53,8 @@ def expect_log(stage:, message:, iid:, comment_id:) note: end_with(pr_comment[:note]), author: note_author, created_at: pr_comment[:created_at], - updated_at: pr_comment[:created_at] + updated_at: pr_comment[:created_at], + imported_from: 'bitbucket_server' ) end @@ -67,7 +68,8 @@ def expect_log(stage:, message:, iid:, comment_id:) comments: [], created_at: now, updated_at: now, - parent_comment_note: nil + parent_comment_note: nil, + imported_from: 'bitbucket_server' } end @@ -80,7 +82,8 @@ def expect_log(stage:, message:, iid:, comment_id:) comments: [pr_comment_extra], created_at: now, updated_at: now, - parent_comment_note: nil + parent_comment_note: nil, + imported_from: 'bitbucket_server' } end @@ -94,13 +97,15 @@ def expect_log(stage:, message:, iid:, comment_id:) note: end_with(pr_comment[:note]), author: note_author, created_at: pr_comment[:created_at], - updated_at: pr_comment[:created_at] + updated_at: pr_comment[:created_at], + imported_from: 'bitbucket_server' ) expect(merge_request.notes.last).to have_attributes( note: end_with(pr_comment_extra[:note]), author: note_author, created_at: pr_comment_extra[:created_at], - updated_at: pr_comment_extra[:created_at] + updated_at: pr_comment_extra[:created_at], + imported_from: 'bitbucket_server' ) end end @@ -129,7 +134,8 @@ def expect_log(stage:, message:, iid:, comment_id:) comments: [], created_at: now, updated_at: now, - parent_comment_note: 'Parent note' + parent_comment_note: 'Parent note', + imported_from: 'bitbucket_server' } end diff --git a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer_spec.rb index 7f7d12eb8fcb72805e5f0c1d9e3f36765f9c638d..ee1b53b566fa869a9b6ed4acbdff351a8e70f5e6 100644 --- a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer_spec.rb @@ -127,7 +127,8 @@ def expect_log(stage:, message:) note: end_with(pr_note.note), author: note_author, created_at: pr_note.created_at, - updated_at: pr_note.created_at + updated_at: pr_note.created_at, + imported_from: 'bitbucket_server' ) end @@ -263,6 +264,7 @@ def expect_log(stage:, message:) expect(start_note.position.old_line).to be_nil expect(start_note.position.new_line).to eq(pr_inline_note.new_pos) expect(start_note.author).to eq(inline_note_author) + expect(start_note.imported_from).to eq('bitbucket_server') reply_note = notes.last expect(reply_note.note).to eq(reply.note) @@ -271,6 +273,7 @@ def expect_log(stage:, message:) expect(reply_note.updated_at).to eq(reply.created_at) expect(reply_note.position.old_line).to be_nil expect(reply_note.position.new_line).to eq(pr_inline_note.new_pos) + expect(reply_note.imported_from).to eq('bitbucket_server') end context 'when the `bitbucket_server_convert_mentions_to_users` flag is disabled' do