Commit 411dc407 authored by George Koltsov's avatar George Koltsov

Sort Pipelines by ID on Project Import

- Previously when project was imported pipelines
  were shown in a reversed order
- This change sorts pipelines by id before doing
  the import to ensure that they are shown in a
  correct order on pipelines page
parent dcced034
---
title: Fix reversed pipeline order on Project Import
merge_request: 26390
author:
type: fixed
......@@ -26,6 +26,7 @@ module Gitlab
ActiveRecord::Base.uncached do
ActiveRecord::Base.no_touching do
update_params!
update_relation_hashes!
create_relations!
end
end
......@@ -217,6 +218,10 @@ module Gitlab
excluded_keys: excluded_keys_for_relation(relation_key)
}
end
def update_relation_hashes!
@tree_hash['ci_pipelines']&.sort_by! { |hash| hash['id'] }
end
end
end
end
......@@ -6452,7 +6452,7 @@
]
},
{
"id": 37,
"id": 26,
"project_id": 5,
"ref": "master",
"sha": "048721d90c449b244b7b4c53a9186b04330174ec",
......@@ -6744,7 +6744,7 @@
]
},
{
"id": 40,
"id": 19,
"project_id": 5,
"ref": "master",
"sha": "2ea1f3dec713d940208fb5ce4a38765ecb5d3f73",
......@@ -6851,7 +6851,7 @@
]
},
{
"id": 42,
"id": 20,
"project_id": 5,
"ref": "master",
"sha": "ce84140e8b878ce6e7c4d298c7202ff38170e3ac",
......
......@@ -104,6 +104,24 @@ describe Gitlab::ImportExport::Project::TreeRestorer do
expect(pipeline.merge_request.source_branch).to eq('feature_conflict')
end
it 'restores pipelines based on ascending id order' do
expected_ordered_shas = %w[
2ea1f3dec713d940208fb5ce4a38765ecb5d3f73
ce84140e8b878ce6e7c4d298c7202ff38170e3ac
048721d90c449b244b7b4c53a9186b04330174ec
sha-notes
5f923865dde3436854e9ceb9cdb7815618d4e849
d2d430676773caa88cdaf7c55944073b2fd5561a
2ea1f3dec713d940208fb5ce4a38765ecb5d3f73
]
project = Project.find_by_path('project')
project.ci_pipelines.order(:id).each_with_index do |pipeline, i|
expect(pipeline['sha']).to eq expected_ordered_shas[i]
end
end
it 'preserves updated_at on issues' do
issue = Issue.where(description: 'Aliquam enim illo et possimus.').first
......@@ -385,7 +403,7 @@ describe Gitlab::ImportExport::Project::TreeRestorer do
it 'has the correct number of pipelines and statuses' do
expect(@project.ci_pipelines.size).to eq(7)
@project.ci_pipelines.order(:id).zip([2, 2, 2, 2, 2, 0, 0])
@project.ci_pipelines.order(:id).zip([2, 0, 2, 2, 2, 2, 0])
.each do |(pipeline, expected_status_size)|
expect(pipeline.statuses.size).to eq(expected_status_size)
end
......@@ -422,7 +440,7 @@ describe Gitlab::ImportExport::Project::TreeRestorer do
end
it 'restores external pull request for the restored pipeline' do
pipeline_with_external_pr = @project.ci_pipelines.order(:id).last
pipeline_with_external_pr = @project.ci_pipelines.where(source: 'external_pull_request_event').first
expect(pipeline_with_external_pr.external_pull_request).to be_persisted
end
......
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