BigW Consortium Gitlab

Commit 77b7bfd4 by James Lopez Committed by Douglas Barbosa Alexandre

Fix import/export labels to cope with project and group labels. Added relevant specs.

parent 848a146f
...@@ -22,7 +22,8 @@ with all their related data and be moved into a new GitLab instance. ...@@ -22,7 +22,8 @@ with all their related data and be moved into a new GitLab instance.
| GitLab version | Import/Export version | | GitLab version | Import/Export version |
| -------- | -------- | | -------- | -------- |
| 8.12.0 to current | 0.1.4 | | 8.13.0 to current | 0.1.5 |
| 8.12.0 | 0.1.4 |
| 8.10.3 | 0.1.3 | | 8.10.3 | 0.1.3 |
| 8.10.0 | 0.1.2 | | 8.10.0 | 0.1.2 |
| 8.9.5 | 0.1.1 | | 8.9.5 | 0.1.1 |
......
...@@ -3,7 +3,7 @@ module Gitlab ...@@ -3,7 +3,7 @@ module Gitlab
extend self extend self
# For every version update, the version history in import_export.md has to be kept up to date. # For every version update, the version history in import_export.md has to be kept up to date.
VERSION = '0.1.4' VERSION = '0.1.5'
FILENAME_LIMIT = 50 FILENAME_LIMIT = 50
def export_path(relative_path:) def export_path(relative_path:)
......
...@@ -71,7 +71,7 @@ excluded_attributes: ...@@ -71,7 +71,7 @@ excluded_attributes:
- :awardable_id - :awardable_id
methods: methods:
project_labels: labels:
- :type - :type
label: label:
- :type - :type
......
...@@ -110,7 +110,7 @@ module Gitlab ...@@ -110,7 +110,7 @@ module Gitlab
def create_relation(relation, relation_hash_list) def create_relation(relation, relation_hash_list)
relation_array = [relation_hash_list].flatten.map do |relation_hash| relation_array = [relation_hash_list].flatten.map do |relation_hash|
Gitlab::ImportExport::RelationFactory.create(relation_sym: relation.to_sym, Gitlab::ImportExport::RelationFactory.create(relation_sym: relation.to_sym,
relation_hash: relation_hash, relation_hash: parsed_relation_hash(relation_hash),
members_mapper: members_mapper, members_mapper: members_mapper,
user: @user, user: @user,
project_id: restored_project.id) project_id: restored_project.id)
...@@ -118,6 +118,11 @@ module Gitlab ...@@ -118,6 +118,11 @@ module Gitlab
relation_hash_list.is_a?(Array) ? relation_array : relation_array.first relation_hash_list.is_a?(Array) ? relation_array : relation_array.first
end end
def parsed_relation_hash(relation_hash)
group_id = restored_project.group ? restored_project.group.id : nil
relation_hash.merge!('group_id' => group_id, 'project_id' => restored_project.id)
end
end end
end end
end end
...@@ -10,7 +10,8 @@ module Gitlab ...@@ -10,7 +10,8 @@ module Gitlab
hooks: 'ProjectHook', hooks: 'ProjectHook',
merge_access_levels: 'ProtectedBranch::MergeAccessLevel', merge_access_levels: 'ProtectedBranch::MergeAccessLevel',
push_access_levels: 'ProtectedBranch::PushAccessLevel', push_access_levels: 'ProtectedBranch::PushAccessLevel',
labels: :project_labels }.freeze labels: :project_labels,
label: :project_label }.freeze
USER_REFERENCES = %w[author_id assignee_id updated_by_id user_id].freeze USER_REFERENCES = %w[author_id assignee_id updated_by_id user_id].freeze
...@@ -20,7 +21,7 @@ module Gitlab ...@@ -20,7 +21,7 @@ module Gitlab
IMPORTED_OBJECT_MAX_RETRIES = 5.freeze IMPORTED_OBJECT_MAX_RETRIES = 5.freeze
EXISTING_OBJECT_CHECK = %i[milestone milestones label labels project_label project_labels].freeze EXISTING_OBJECT_CHECK = %i[milestone milestones label labels project_label project_labels project_label group_label].freeze
FINDER_ATTRIBUTES = %w[title project_id].freeze FINDER_ATTRIBUTES = %w[title project_id].freeze
...@@ -57,6 +58,8 @@ module Gitlab ...@@ -57,6 +58,8 @@ module Gitlab
update_user_references update_user_references
update_project_references update_project_references
handle_group_label if group_label?
reset_ci_tokens if @relation_name == 'Ci::Trigger' reset_ci_tokens if @relation_name == 'Ci::Trigger'
@relation_hash['data'].deep_symbolize_keys! if @relation_name == :events && @relation_hash['data'] @relation_hash['data'].deep_symbolize_keys! if @relation_name == :events && @relation_hash['data']
set_st_diffs if @relation_name == :merge_request_diff set_st_diffs if @relation_name == :merge_request_diff
...@@ -124,6 +127,19 @@ module Gitlab ...@@ -124,6 +127,19 @@ module Gitlab
@relation_hash['target_project_id'] && @relation_hash['target_project_id'] == @relation_hash['source_project_id'] @relation_hash['target_project_id'] && @relation_hash['target_project_id'] == @relation_hash['source_project_id']
end end
def group_label?
@relation_hash['type'] == 'GroupLabel'
end
def handle_group_label
# If there's no group, move the label to a project label
if @relation_hash['group_id']
@relation_name = :group_label
else
@relation_hash['type'] = 'ProjectLabel'
end
end
def reset_ci_tokens def reset_ci_tokens
return unless Gitlab::ImportExport.reset_tokens? return unless Gitlab::ImportExport.reset_tokens?
......
...@@ -64,7 +64,29 @@ ...@@ -64,7 +64,29 @@
"updated_at": "2016-07-22T08:55:44.161Z", "updated_at": "2016-07-22T08:55:44.161Z",
"template": false, "template": false,
"description": "", "description": "",
"priority": null "priority": null,
"type": "ProjectLabel"
}
},
{
"id": 3,
"label_id": 3,
"target_id": 40,
"target_type": "Issue",
"created_at": "2016-07-22T08:57:02.841Z",
"updated_at": "2016-07-22T08:57:02.841Z",
"label": {
"id": 3,
"title": "test3",
"color": "#428bca",
"group_id": 8,
"created_at": "2016-07-22T08:55:44.161Z",
"updated_at": "2016-07-22T08:55:44.161Z",
"template": false,
"description": "",
"priority": null,
"project_id": null,
"type": "GroupLabel"
} }
} }
], ],
...@@ -536,7 +558,8 @@ ...@@ -536,7 +558,8 @@
"updated_at": "2016-07-22T08:55:44.161Z", "updated_at": "2016-07-22T08:55:44.161Z",
"template": false, "template": false,
"description": "", "description": "",
"priority": null "priority": null,
"type": "ProjectLabel"
} }
} }
], ],
......
...@@ -32,7 +32,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do ...@@ -32,7 +32,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
it 'has the same label associated to two issues' do it 'has the same label associated to two issues' do
restored_project_json restored_project_json
expect(Label.first.issues.count).to eq(2) expect(ProjectLabel.find_by_title('test2').issues.count).to eq(2)
end end
it 'has milestones associated to two separate issues' do it 'has milestones associated to two separate issues' do
...@@ -107,6 +107,33 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do ...@@ -107,6 +107,33 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
expect(Label.first.label_links.first.target).not_to be_nil expect(Label.first.label_links.first.target).not_to be_nil
end end
it 'has project labels' do
restored_project_json
expect(ProjectLabel.count).to eq(2)
end
it 'has no group labels' do
restored_project_json
expect(GroupLabel.count).to eq(0)
end
context 'with group' do
let!(:project) { create(:empty_project,
name: 'project',
path: 'project',
builds_access_level: ProjectFeature::DISABLED,
issues_access_level: ProjectFeature::DISABLED,
group: create(:group)) }
it 'has group labels' do
restored_project_json
expect(GroupLabel.count).to eq(1)
end
end
it 'has a project feature' do it 'has a project feature' do
restored_project_json restored_project_json
......
...@@ -111,6 +111,12 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do ...@@ -111,6 +111,12 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
expect(saved_project_json['issues'].first['label_links'].first['label']).not_to be_empty expect(saved_project_json['issues'].first['label_links'].first['label']).not_to be_empty
end end
it 'has project and group labels' do
label_types = saved_project_json['issues'].first['label_links'].map { |link| link['label']['type']}
expect(label_types).to match(['ProjectLabel', 'GroupLabel'])
end
it 'saves the correct service type' do it 'saves the correct service type' do
expect(saved_project_json['services'].first['type']).to eq('CustomIssueTrackerService') expect(saved_project_json['services'].first['type']).to eq('CustomIssueTrackerService')
end end
...@@ -135,15 +141,19 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do ...@@ -135,15 +141,19 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
issue = create(:issue, assignee: user) issue = create(:issue, assignee: user)
snippet = create(:project_snippet) snippet = create(:project_snippet)
release = create(:release) release = create(:release)
group = create(:group)
project = create(:project, project = create(:project,
:public, :public,
issues: [issue], issues: [issue],
snippets: [snippet], snippets: [snippet],
releases: [release] releases: [release],
group: group
) )
label = create(:label, project: project) project_label = create(:label, project: project)
create(:label_link, label: label, target: issue) group_label = create(:group_label, group: group)
create(:label_link, label: project_label, target: issue)
create(:label_link, label: group_label, target: issue)
milestone = create(:milestone, project: project) milestone = create(:milestone, project: project)
merge_request = create(:merge_request, source_project: project, milestone: milestone) merge_request = create(:merge_request, source_project: project, milestone: milestone)
commit_status = create(:commit_status, project: project) commit_status = create(:commit_status, project: project)
......
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