Commit 77b7bfd4 authored by James Lopez's avatar 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.
| 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.0 | 0.1.2 |
| 8.9.5 | 0.1.1 |
......
......@@ -3,7 +3,7 @@ module Gitlab
extend self
# 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
def export_path(relative_path:)
......
......@@ -71,7 +71,7 @@ excluded_attributes:
- :awardable_id
methods:
project_labels:
labels:
- :type
label:
- :type
......
......@@ -110,7 +110,7 @@ module Gitlab
def create_relation(relation, relation_hash_list)
relation_array = [relation_hash_list].flatten.map do |relation_hash|
Gitlab::ImportExport::RelationFactory.create(relation_sym: relation.to_sym,
relation_hash: relation_hash,
relation_hash: parsed_relation_hash(relation_hash),
members_mapper: members_mapper,
user: @user,
project_id: restored_project.id)
......@@ -118,6 +118,11 @@ module Gitlab
relation_hash_list.is_a?(Array) ? relation_array : relation_array.first
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
......@@ -10,7 +10,8 @@ module Gitlab
hooks: 'ProjectHook',
merge_access_levels: 'ProtectedBranch::MergeAccessLevel',
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
......@@ -20,7 +21,7 @@ module Gitlab
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
......@@ -57,6 +58,8 @@ module Gitlab
update_user_references
update_project_references
handle_group_label if group_label?
reset_ci_tokens if @relation_name == 'Ci::Trigger'
@relation_hash['data'].deep_symbolize_keys! if @relation_name == :events && @relation_hash['data']
set_st_diffs if @relation_name == :merge_request_diff
......@@ -124,6 +127,19 @@ module Gitlab
@relation_hash['target_project_id'] && @relation_hash['target_project_id'] == @relation_hash['source_project_id']
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
return unless Gitlab::ImportExport.reset_tokens?
......
......@@ -64,7 +64,29 @@
"updated_at": "2016-07-22T08:55:44.161Z",
"template": false,
"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 @@
"updated_at": "2016-07-22T08:55:44.161Z",
"template": false,
"description": "",
"priority": null
"priority": null,
"type": "ProjectLabel"
}
}
],
......
......@@ -32,7 +32,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
it 'has the same label associated to two issues' do
restored_project_json
expect(Label.first.issues.count).to eq(2)
expect(ProjectLabel.find_by_title('test2').issues.count).to eq(2)
end
it 'has milestones associated to two separate issues' do
......@@ -107,6 +107,33 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
expect(Label.first.label_links.first.target).not_to be_nil
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
restored_project_json
......
......@@ -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
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
expect(saved_project_json['services'].first['type']).to eq('CustomIssueTrackerService')
end
......@@ -135,15 +141,19 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
issue = create(:issue, assignee: user)
snippet = create(:project_snippet)
release = create(:release)
group = create(:group)
project = create(:project,
:public,
issues: [issue],
snippets: [snippet],
releases: [release]
releases: [release],
group: group
)
label = create(:label, project: project)
create(:label_link, label: label, target: issue)
project_label = create(:label, project: project)
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)
merge_request = create(:merge_request, source_project: project, milestone: milestone)
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