Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
05ddb259
Commit
05ddb259
authored
Jan 05, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assign stage and pipeline to a status when importing
parent
099a59e8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
426 additions
and
368 deletions
+426
-368
app/models/ci/build.rb
app/models/ci/build.rb
+1
-1
lib/gitlab/import_export/import_export.yml
lib/gitlab/import_export/import_export.yml
+2
-2
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+13
-5
spec/lib/gitlab/import_export/project.json
spec/lib/gitlab/import_export/project.json
+401
-357
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+9
-3
No files found.
app/models/ci/build.rb
View file @
05ddb259
...
...
@@ -79,7 +79,7 @@ module Ci
before_save
:ensure_token
before_destroy
{
unscoped_project
}
after_create
do
|
build
|
after_create
unless: :importing?
do
|
build
|
run_after_commit
{
BuildHooksWorker
.
perform_async
(
build
.
id
)
}
end
...
...
lib/gitlab/import_export/import_export.yml
View file @
05ddb259
...
...
@@ -49,7 +49,7 @@ project_tree:
-
:author
-
events
:
-
:push_event_payload
-
:stages
-
stages
:
-
:statuses
-
:auto_devops
-
:triggers
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
05ddb259
...
...
@@ -62,6 +62,7 @@ module Gitlab
when
:notes
then
setup_note
when
:project_label
,
:project_labels
then
setup_label
when
:milestone
,
:milestones
then
setup_milestone
when
'Ci::Pipeline'
then
setup_pipeline
else
@relation_hash
[
'project_id'
]
=
@project
.
id
end
...
...
@@ -112,9 +113,7 @@ module Gitlab
@relation_hash
.
delete
(
'trace'
)
# old export files have trace
@relation_hash
.
delete
(
'token'
)
imported_object
do
|
object
|
object
.
commit_id
=
nil
end
imported_object
elsif
@relation_name
==
:merge_requests
MergeRequestParser
.
new
(
@project
,
@relation_hash
.
delete
(
'diff_head_sha'
),
imported_object
,
@relation_hash
).
parse!
else
...
...
@@ -182,8 +181,9 @@ module Gitlab
end
def
imported_object
yield
(
existing_or_new_object
)
if
block_given?
existing_or_new_object
.
importing
=
true
if
existing_or_new_object
.
respond_to?
(
:importing
)
if
existing_or_new_object
.
respond_to?
(
:importing
)
existing_or_new_object
.
importing
=
true
end
existing_or_new_object
rescue
ActiveRecord
::
RecordNotUnique
...
...
@@ -211,6 +211,14 @@ module Gitlab
@relation_hash
[
'diff'
]
=
@relation_hash
.
delete
(
'utf8_diff'
)
end
def
setup_pipeline
@relation_hash
.
fetch
(
'stages'
).
each
do
|
stage
|
stage
.
statuses
.
each
do
|
status
|
status
.
pipeline
=
imported_object
end
end
end
def
existing_or_new_object
# Only find existing records to avoid mapping tables such as milestones
# Otherwise always create the record, skipping the extra SELECT clause.
...
...
spec/lib/gitlab/import_export/project.json
View file @
05ddb259
...
...
@@ -6473,18 +6473,7 @@
"name"
:
"test"
,
"status"
:
1
,
"created_at"
:
"2016-03-22T15:44:44.772Z"
,
"updated_at"
:
"2016-03-29T06:44:44.634Z"
},
{
"id"
:
12
,
"project_id"
:
5
,
"pipeline_id"
:
36
,
"name"
:
"deploy"
,
"status"
:
2
,
"created_at"
:
"2016-03-22T15:45:45.772Z"
,
"updated_at"
:
"2016-03-29T06:45:45.634Z"
}
],
"updated_at"
:
"2016-03-29T06:44:44.634Z"
,
"statuses"
:
[
{
"id"
:
71
,
...
...
@@ -6562,6 +6551,17 @@
}
]
},
{
"id"
:
12
,
"project_id"
:
5
,
"pipeline_id"
:
36
,
"name"
:
"deploy"
,
"status"
:
2
,
"created_at"
:
"2016-03-22T15:45:45.772Z"
,
"updated_at"
:
"2016-03-29T06:45:45.634Z"
}
]
},
{
"id"
:
37
,
"project_id"
:
5
,
...
...
@@ -6578,6 +6578,15 @@
"started_at"
:
null
,
"finished_at"
:
null
,
"duration"
:
null
,
"stages"
:
[
{
"id"
:
21
,
"project_id"
:
5
,
"pipeline_id"
:
37
,
"name"
:
"test"
,
"status"
:
1
,
"created_at"
:
"2016-03-22T15:44:44.772Z"
,
"updated_at"
:
"2016-03-29T06:44:44.634Z"
,
"statuses"
:
[
{
"id"
:
74
,
...
...
@@ -6650,6 +6659,8 @@
"erased_at"
:
null
}
]
}
]
},
{
"id"
:
38
,
...
...
@@ -6667,6 +6678,15 @@
"started_at"
:
null
,
"finished_at"
:
null
,
"duration"
:
null
,
"stages"
:
[
{
"id"
:
22
,
"project_id"
:
5
,
"pipeline_id"
:
38
,
"name"
:
"test"
,
"status"
:
1
,
"created_at"
:
"2016-03-22T15:44:44.772Z"
,
"updated_at"
:
"2016-03-29T06:44:44.634Z"
,
"statuses"
:
[
{
"id"
:
76
,
...
...
@@ -6739,6 +6759,8 @@
"erased_at"
:
null
}
]
}
]
},
{
"id"
:
39
,
...
...
@@ -6756,6 +6778,15 @@
"started_at"
:
null
,
"finished_at"
:
null
,
"duration"
:
null
,
"stages"
:
[
{
"id"
:
23
,
"project_id"
:
5
,
"pipeline_id"
:
39
,
"name"
:
"test"
,
"status"
:
1
,
"created_at"
:
"2016-03-22T15:44:44.772Z"
,
"updated_at"
:
"2016-03-29T06:44:44.634Z"
,
"statuses"
:
[
{
"id"
:
78
,
...
...
@@ -6828,6 +6859,8 @@
"erased_at"
:
null
}
]
}
]
},
{
"id"
:
40
,
...
...
@@ -6845,6 +6878,15 @@
"started_at"
:
null
,
"finished_at"
:
null
,
"duration"
:
null
,
"stages"
:
[
{
"id"
:
24
,
"project_id"
:
5
,
"pipeline_id"
:
40
,
"name"
:
"test"
,
"status"
:
1
,
"created_at"
:
"2016-03-22T15:44:44.772Z"
,
"updated_at"
:
"2016-03-29T06:44:44.634Z"
,
"statuses"
:
[
{
"id"
:
79
,
...
...
@@ -6918,6 +6960,8 @@
}
]
}
]
}
],
"triggers"
:
[
{
...
...
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
05ddb259
...
...
@@ -181,14 +181,20 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
context
'when restoring hierarchy of pipeline, stages and jobs'
do
let
(
:pipeline
)
{
Ci
::
Pipeline
.
first
}
it
'restores statuses'
do
expect
(
CommitStatus
.
all
.
count
).
to
be
10
end
it
'restores pipeline stages'
do
expect
(
pipeline
.
stages
.
count
).
to
be
2
expect
(
Ci
::
Stage
.
all
.
count
).
to
be
6
end
it
'correctly restores association between a stage and a job'
do
expect
(
pipeline
.
statuses
).
to
all
(
have_attributes
(
stage_id:
a_value
>
0
))
expect
(
CommitStatus
.
all
).
to
all
(
have_attributes
(
stage_id:
a_value
>
0
))
end
it
'correctly restores association between a stage and a pipeline'
do
expect
(
CommitStatus
.
all
).
to
all
(
have_attributes
(
pipeline_id:
a_value
>
0
))
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment