From 0e5f0276eae25c975078f825ea10ff2c8d05563c Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 8 Jul 2016 17:21:28 +0200 Subject: squashed - refactor to cope with sub sub N relations probably using the sub_relations method recursively. --- CHANGELOG | 25 ++++++++++++++++++++++ lib/gitlab/import_export/project_tree_restorer.rb | 9 ++++++++ spec/lib/gitlab/import_export/project.json | 13 ++++++++++- .../import_export/project_tree_restorer_spec.rb | 18 +++++++++++++++- 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a019f56c0fa..f895f05ca70 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -32,6 +32,31 @@ v 8.10.0 (unreleased) - Add basic system information like memory and disk usage to the admin panel v 8.9.5 (unreleased) + - Don't garbage collect commits that have related DB records like comments + - More descriptive message for git hooks and file locks + - Handle custom Git hook result in GitLab UI + - Allow '?', or '&' for label names + - Fix importer for GitHub Pull Requests when a branch was reused across Pull Requests + - Add date when user joined the team on the member page + - Fix 404 redirect after validation fails importing a GitLab project + - Added setting to set new users by default as external !4545 (Dravere) + +v 8.9.6 + - Fix importing of events under notes for GitLab projects + +v 8.9.5 + - Add more debug info to import/export and memory killer. !5108 + - Fixed avatar alignment in new MR view. !5095 + - Fix diff comments not showing up in activity feed. !5069 + - Add index on both Award Emoji user and name. !5061 + - Downgrade to Redis 3.2.2 due to massive memory leak with Sidekiq. !5056 + - Re-enable import button when import process fails due to namespace already being taken. !5053 + - Fix snippets comments not displayed. !5045 + - Fix emoji paths in relative root configurations. !5027 + - Fix issues importing events in Import/Export. !4987 + - Fixed 'use shortcuts' button on docs. !4979 + - Admin should be able to turn shared runners into specific ones. !4961 + - Update RedCloth to 4.3.2 for CVE-2012-6684. !4929 (Takuya Noguchi) - Improve the request / withdraw access button. !4860 - Fix assigning shared runners as admins. !4961 - Show "locked" label for locked runners on runners admin. !4961 diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb index dd71b92c522..e2413b082b2 100644 --- a/lib/gitlab/import_export/project_tree_restorer.rb +++ b/lib/gitlab/import_export/project_tree_restorer.rb @@ -70,10 +70,19 @@ module Gitlab # Example: # +relation_key+ issues, loops through the list of *issues* and for each individual # issue, finds any subrelations such as notes, creates them and assign them back to the hash + # + # Recursively calls this method if the sub-relation is a hash containing more sub-relations def create_sub_relations(relation, tree_hash) relation_key = relation.keys.first.to_s + return if tree_hash[relation_key].blank? + tree_hash[relation_key].each do |relation_item| relation.values.flatten.each do |sub_relation| + # We just use author to get the user ID, do not attempt to create an instance. + next if sub_relation == :author + + create_sub_relations(sub_relation, relation_item) if sub_relation.is_a?(Hash) + relation_hash, sub_relation = assign_relation_hash(relation_item, sub_relation) relation_item[sub_relation.to_s] = create_relation(sub_relation, relation_hash) unless relation_hash.blank? end diff --git a/spec/lib/gitlab/import_export/project.json b/spec/lib/gitlab/import_export/project.json index 0b30e8c9b04..7286b0c39c0 100644 --- a/spec/lib/gitlab/import_export/project.json +++ b/spec/lib/gitlab/import_export/project.json @@ -4208,7 +4208,18 @@ "name": "User 4" }, "events": [ - + { + "id": 529, + "target_type": "Note", + "target_id": 2521, + "title": "test levels", + "data": null, + "project_id": 4, + "created_at": "2016-07-07T14:35:12.128Z", + "updated_at": "2016-07-07T14:35:12.128Z", + "action": 6, + "author_id": 1 + } ] }, { 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 e401ca99077..d2d0a05ad5c 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -25,11 +25,27 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do expect(Ci::Pipeline.first.notes).not_to be_empty end - it 'restores the correct event' do + it 'restores the correct event with symbolised data' do restored_project_json expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty end + + context 'event at forth level of the tree' do + let(:event) { Event.where(title: 'test levels').first } + + before do + restored_project_json + end + + it 'restores the event' do + expect(event).not_to be_nil + end + + it 'event belongs to note, belongs to merge request, belongs to a project' do + expect(event.note.noteable.project).not_to be_nil + end + end end end end -- cgit v1.2.1 From 95fe316f5d5cad06ed3457dd6c6f8263dfabd058 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Mon, 11 Jul 2016 18:09:19 +0200 Subject: fix changelog... --- CHANGELOG | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ce17040614e..eaa0ae2de0c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -53,8 +53,6 @@ v 8.10.0 (unreleased) - Memoize MR merged/closed events retrieval - Don't render discussion notes when requesting diff tab through AJAX - Add basic system information like memory and disk usage to the admin panel - -v 8.9.5 (unreleased) - Don't garbage collect commits that have related DB records like comments - More descriptive message for git hooks and file locks - Handle custom Git hook result in GitLab UI @@ -63,12 +61,12 @@ v 8.9.5 (unreleased) - Add date when user joined the team on the member page - Fix 404 redirect after validation fails importing a GitLab project - Added setting to set new users by default as external !4545 (Dravere) - -v 8.9.6 - - Fix importing of events under notes for GitLab projects - Add min value for project limit field on user's form !3622 (jastkand) - Add reminder to not paste private SSH keys !4399 (Ingo Blechschmidt) +v 8.9.6 (unreleased) + - Fix importing of events under notes for GitLab projects + v 8.9.5 - Add more debug info to import/export and memory killer. !5108 - Fixed avatar alignment in new MR view. !5095 -- cgit v1.2.1