summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Leopard <mleopard@gitlab.com>2019-08-29 13:53:57 -0400
committerMichael Leopard <mleopard@gitlab.com>2019-09-11 09:45:40 -0400
commit973f2dd9c9ef045e2b5f2c75393a594dd1fd57d1 (patch)
treee687e45b86517a97298a128e284528f4fceaeccb
parenta9cd5d2a378b90a4263793a14d73ad6e2c170889 (diff)
downloadgitlab-ce-60121-pipelines-in-reverse-order-after-import.tar.gz
Reversing pipeline order on import60121-pipelines-in-reverse-order-after-import
Updating tree restorer and saver tests
-rw-r--r--changelogs/unreleased/60121-pipelines-in-reverse-order-after-import.yml5
-rw-r--r--lib/gitlab/import_export/project_tree_restorer.rb11
-rw-r--r--spec/lib/gitlab/import_export/project_tree_restorer_spec.rb7
-rw-r--r--spec/lib/gitlab/import_export/project_tree_saver_spec.rb33
4 files changed, 41 insertions, 15 deletions
diff --git a/changelogs/unreleased/60121-pipelines-in-reverse-order-after-import.yml b/changelogs/unreleased/60121-pipelines-in-reverse-order-after-import.yml
new file mode 100644
index 00000000000..12991373993
--- /dev/null
+++ b/changelogs/unreleased/60121-pipelines-in-reverse-order-after-import.yml
@@ -0,0 +1,5 @@
+---
+title: Reverse Pipeline Order On Import
+merge_request: 32388
+author:
+type: fixed
diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb
index 2dd18616cd6..a606a6333c7 100644
--- a/lib/gitlab/import_export/project_tree_restorer.rb
+++ b/lib/gitlab/import_export/project_tree_restorer.rb
@@ -28,6 +28,8 @@ module Gitlab
RelationRenameService.rename(@tree_hash)
+ correct_pipeline_order
+
ActiveRecord::Base.uncached do
ActiveRecord::Base.no_touching do
create_relations
@@ -235,6 +237,15 @@ module Gitlab
def nil_iid_pipeline?(relation_key, relation_item)
relation_key == 'ci_pipelines' && relation_item['iid'].nil?
end
+
+ def correct_pipeline_order
+ if @tree_hash['ci_pipelines'].present?
+ pipelines = @tree_hash["ci_pipelines"]
+ if pipelines.first["created_at"] > pipelines.last["created_at"]
+ @tree_hash["ci_pipelines"].sort_by! { |pipelines| pipelines['created_at'] }
+ end
+ end
+ end
end
end
end
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 87be7857e67..38870314951 100644
--- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
@@ -62,6 +62,13 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect(Milestone.find_by_description('test milestone').issues.count).to eq(2)
end
+ it 'has ci pipeline builds in reverse chronological order' do
+ first_build = @project.ci_pipelines.first
+ last_build = @project.ci_pipelines.last
+
+ expect(first_build["created_at"]).to be < last_build["created_at"]
+ end
+
context 'when importing a project with cached_markdown_version and note_html' do
context 'for an Issue' do
it 'does not import note_html' do
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 ff46e062a5d..61b2508c0b9 100644
--- a/spec/lib/gitlab/import_export/project_tree_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/project_tree_saver_spec.rb
@@ -196,10 +196,9 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
it 'has pipeline builds' do
builds_count = saved_project_json
- .dig('ci_pipelines', 0, 'stages', 0, 'statuses')
- .count { |hash| hash['type'] == 'Ci::Build' }
+ .dig('ci_pipelines').length
- expect(builds_count).to eq(1)
+ expect(builds_count).to eq(3)
end
it 'has no when YML attributes but only the DB column' do
@@ -359,18 +358,22 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
milestone = create(:milestone, project: project)
merge_request = create(:merge_request, source_project: project, milestone: milestone)
- ci_build = create(:ci_build, project: project, when: nil)
- ci_build.pipeline.update(project: project)
- 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)
- create(:note, noteable: snippet, project: project)
- create(:note_on_commit,
- author: user,
- project: project,
- commit_id: ci_build.pipeline.sha)
+ pipelines = []
+
+ 3.times do |i|
+ pipelines.push(create(:ci_empty_pipeline, project: project, sha: project.commit.sha, ref: 'master'))
+ ci_build = create(:ci_build, project: project, when: nil, pipeline: pipelines[i])
+ ci_build.pipeline.update(project: project)
+ 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)
+ create(:note, noteable: snippet, project: project)
+ create(:note_on_commit,
+ author: user,
+ project: project,
+ commit_id: ci_build.pipeline.sha)
+ end
create(:resource_label_event, label: project_label, issue: issue)
create(:resource_label_event, label: group_label, merge_request: merge_request)