Commit 6f6dcc36 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix/import-export-gitlab-errors' into 'master'

Fix errors found on importing GitLab CE repo

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/18968

See merge request !4855
parents 3eab71f9 79192a84
...@@ -6,6 +6,9 @@ v 8.10.0 (unreleased) ...@@ -6,6 +6,9 @@ v 8.10.0 (unreleased)
- Fix MR-auto-close text added to description. !4836 - Fix MR-auto-close text added to description. !4836
- Implement Subresource Integrity for CSS and JavaScript assets. This prevents malicious assets from loading in the case of a CDN compromise. - Implement Subresource Integrity for CSS and JavaScript assets. This prevents malicious assets from loading in the case of a CDN compromise.
v 8.9.1
- Fix GitLab project import issues related to notes and builds
v 8.9.0 v 8.9.0
- Fix builds API response not including commit data - Fix builds API response not including commit data
- Fix error when CI job variables key specified but not defined - Fix error when CI job variables key specified but not defined
......
...@@ -170,6 +170,19 @@ module Ci ...@@ -170,6 +170,19 @@ module Ci
builds.where.not(environment: nil).success.pluck(:environment).uniq builds.where.not(environment: nil).success.pluck(:environment).uniq
end end
# Manually set the notes for a Ci::Pipeline
# There is no ActiveRecord relation between Ci::Pipeline and notes
# as they are related to a commit sha. This method helps importing
# them using the +Gitlab::ImportExport::RelationFactory+ class.
def notes=(notes)
notes.each do |note|
note[:id] = nil
note[:commit_id] = sha
note[:noteable_id] = self['id']
note.save!
end
end
def notes def notes
Note.for_commit_id(sha) Note.for_commit_id(sha)
end end
......
...@@ -12,6 +12,8 @@ module Gitlab ...@@ -12,6 +12,8 @@ module Gitlab
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
BUILD_MODELS = %w[Ci::Build commit_status].freeze
def self.create(*args) def self.create(*args)
new(*args).create new(*args).create
end end
...@@ -70,7 +72,7 @@ module Gitlab ...@@ -70,7 +72,7 @@ module Gitlab
end end
def generate_imported_object def generate_imported_object
if @relation_sym == 'commit_status' # call #trace= method after assigning the other attributes if BUILD_MODELS.include?(@relation_name) # call #trace= method after assigning the other attributes
trace = @relation_hash.delete('trace') trace = @relation_hash.delete('trace')
imported_object do |object| imported_object do |object|
object.trace = trace object.trace = trace
......
...@@ -4894,6 +4894,29 @@ ...@@ -4894,6 +4894,29 @@
"started_at": null, "started_at": null,
"finished_at": null, "finished_at": null,
"duration": null, "duration": null,
"notes": [
{
"id": 999,
"note": "Natus rerum qui dolorem dolorum voluptas.",
"noteable_type": "Commit",
"author_id": 1,
"created_at": "2016-03-22T15:19:59.469Z",
"updated_at": "2016-03-22T15:19:59.469Z",
"project_id": 5,
"attachment": {
"url": null
},
"line_code": null,
"commit_id": "be93687618e4b132087f430a4d8fc3a609c9b77c",
"noteable_id": 36,
"system": false,
"st_diff": null,
"updated_by_id": null,
"author": {
"name": "Administrator"
}
}
],
"statuses": [ "statuses": [
{ {
"id": 71, "id": 71,
......
...@@ -18,6 +18,12 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do ...@@ -18,6 +18,12 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
it 'restores models based on JSON' do it 'restores models based on JSON' do
expect(restored_project_json).to be true expect(restored_project_json).to be true
end end
it 'creates a valid pipeline note' do
restored_project_json
expect(Ci::Pipeline.first.notes).not_to be_empty
end
end end
end end
end 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