diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 12:09:31 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 12:09:31 +0300 |
commit | 04baa85554ff13bdd4d6f4e6bb24119d17608fee (patch) | |
tree | 7cb9c0977e09d97da340f48703d79b2dbd3579a0 /spec/lib/gitlab | |
parent | 42f41de46525ce0065f02ee07c1a79f5669526a0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
6 files changed, 71 insertions, 9 deletions
diff --git a/spec/lib/gitlab/github_import/parallel_importer_spec.rb b/spec/lib/gitlab/github_import/parallel_importer_spec.rb index a9b7d3d388c..a8d5cc58bd5 100644 --- a/spec/lib/gitlab/github_import/parallel_importer_spec.rb +++ b/spec/lib/gitlab/github_import/parallel_importer_spec.rb @@ -27,7 +27,7 @@ describe Gitlab::GithubImport::ParallelImporter do end it 'sets the JID in Redis' do - expect(Gitlab::Import::SetAsyncJid).to receive(:set_jid).with(project).and_call_original + expect(Gitlab::Import::SetAsyncJid).to receive(:set_jid).with(project.import_state).and_call_original importer.execute end diff --git a/spec/lib/gitlab/import/set_async_jid_spec.rb b/spec/lib/gitlab/import/set_async_jid_spec.rb index 51397280138..f1ae23a4a6a 100644 --- a/spec/lib/gitlab/import/set_async_jid_spec.rb +++ b/spec/lib/gitlab/import/set_async_jid_spec.rb @@ -8,16 +8,16 @@ describe Gitlab::Import::SetAsyncJid do it 'sets the JID in Redis' do expect(Gitlab::SidekiqStatus) .to receive(:set) - .with("async-import/#{project.id}", StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION) + .with("async-import/project-import-state/#{project.id}", StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION) .and_call_original - described_class.set_jid(project) + described_class.set_jid(project.import_state) end it 'updates the import JID of the project' do - described_class.set_jid(project) + described_class.set_jid(project.import_state) - expect(project.import_state.reload.jid).to eq("async-import/#{project.id}") + expect(project.import_state.reload.jid).to eq("async-import/project-import-state/#{project.id}") end end end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 9abc8a5d88f..1579a6ce2df 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -38,6 +38,7 @@ issues: - vulnerability_links - related_vulnerabilities - user_mentions +- system_note_metadata events: - author - project @@ -152,6 +153,7 @@ merge_requests: - deployment_merge_requests - deployments - user_mentions +- system_note_metadata external_pull_requests: - project merge_request_diff: @@ -620,3 +622,6 @@ epic: epic_issue: - epic - issue +system_note_metadata: +- note +- description_version diff --git a/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb index e7edbc7690d..247d455fecc 100644 --- a/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb @@ -2,6 +2,10 @@ require 'spec_helper' +def match_mr1_note(content_regex) + MergeRequest.find_by(title: 'MR1').notes.select { |n| n.note.match(/#{content_regex}/)}.first +end + describe Gitlab::ImportExport::Project::TreeRestorer do include ImportExport::CommonUtil @@ -74,10 +78,30 @@ describe Gitlab::ImportExport::Project::TreeRestorer do context 'for a Merge Request' do it 'does not import note_html' do note_content = 'Sit voluptatibus eveniet architecto quidem' - merge_request_note = MergeRequest.find_by(title: 'MR1').notes.select { |n| n.note.match(/#{note_content}/)}.first + merge_request_note = match_mr1_note(note_content) expect(merge_request_note.note_html).to match(/#{note_content}/) end + + context 'merge request system note metadata' do + it 'restores title action for unmark wip' do + merge_request_note = match_mr1_note('unmarked as a \\*\\*Work In Progress\\*\\*') + + expect(merge_request_note.noteable_type).to eq('MergeRequest') + expect(merge_request_note.system).to eq(true) + expect(merge_request_note.system_note_metadata.action).to eq('title') + expect(merge_request_note.system_note_metadata.commit_count).to be_nil + end + + it 'restores commit action and commit count for pushing 3 commits' do + merge_request_note = match_mr1_note('added 3 commits') + + expect(merge_request_note.noteable_type).to eq('MergeRequest') + expect(merge_request_note.system).to eq(true) + expect(merge_request_note.system_note_metadata.action).to eq('commit') + expect(merge_request_note.system_note_metadata.commit_count).to eq(3) + end + end end end @@ -373,7 +397,8 @@ describe Gitlab::ImportExport::Project::TreeRestorer do context 'notes' do it 'has award emoji' do - award_emoji = MergeRequest.find_by_title('MR1').notes.first.award_emoji.first + merge_request_note = match_mr1_note('Sit voluptatibus eveniet architecto quidem') + award_emoji = merge_request_note.award_emoji.first expect(award_emoji.name).to eq('tada') end @@ -507,6 +532,16 @@ describe Gitlab::ImportExport::Project::TreeRestorer do first_issue_labels: 1, services: 1 + it 'issue system note metadata restored successfully' do + note_content = 'created merge request !1 to address this issue' + note = project.issues.first.notes.select { |n| n.note.match(/#{note_content}/)}.first + + expect(note.noteable_type).to eq('Issue') + expect(note.system).to eq(true) + expect(note.system_note_metadata.action).to eq('merge') + expect(note.system_note_metadata.commit_count).to be_nil + end + context 'when there is an existing build with build token' do before do create(:ci_build, token: 'abcd') diff --git a/spec/lib/gitlab/import_export/project/tree_saver_spec.rb b/spec/lib/gitlab/import_export/project/tree_saver_spec.rb index 23360b725b9..c910ee5430b 100644 --- a/spec/lib/gitlab/import_export/project/tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/project/tree_saver_spec.rb @@ -113,6 +113,12 @@ describe Gitlab::ImportExport::Project::TreeSaver do expect(saved_project_json['issues'].first['notes'].first['author']).not_to be_empty end + it 'has system note metadata on issue comments' do + metadata = saved_project_json['issues'].first['notes'].first['system_note_metadata'] + + expect(metadata['action']).to eq('description') + end + it 'has project members' do expect(saved_project_json['project_members']).not_to be_empty end @@ -137,6 +143,13 @@ describe Gitlab::ImportExport::Project::TreeSaver do expect(saved_project_json['merge_requests'].first['notes'].first['author']).not_to be_empty end + it 'has system note metadata on merge requests comments' do + metadata = saved_project_json['merge_requests'].first['notes'].first['system_note_metadata'] + + expect(metadata['commit_count']).to eq(1) + expect(metadata['action']).to eq('commit') + end + it 'has pipeline stages' do expect(saved_project_json.dig('ci_pipelines', 0, 'stages')).not_to be_empty end @@ -314,14 +327,17 @@ describe Gitlab::ImportExport::Project::TreeSaver do create(:commit_status, project: project, pipeline: ci_build.pipeline) create(:milestone, project: project) - create(:discussion_note, noteable: issue, project: project) - create(:note, noteable: merge_request, project: project) + discussion_note = create(:discussion_note, noteable: issue, project: project) + mr_note = create(:note, noteable: merge_request, project: project) create(:note, noteable: snippet, project: project) create(:note_on_commit, author: user, project: project, commit_id: ci_build.pipeline.sha) + create(:system_note_metadata, action: 'description', note: discussion_note) + create(:system_note_metadata, commit_count: 1, action: 'commit', note: mr_note) + create(:resource_label_event, label: project_label, issue: issue) create(:resource_label_event, label: group_label, merge_request: merge_request) diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index 533458afd73..7190d84573e 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -848,3 +848,9 @@ Epic: EpicIssue: - id - relative_position +SystemNoteMetadata: + - id + - commit_count + - action + - created_at + - updated_at |