Commit 3d2a7366 authored by James Lopez's avatar James Lopez

fixing events for import/export

parent 9e8fdead
module Eventable
extend ActiveSupport::Concern
def events
Event.where(target_id: id, target_type: self.class.to_s)
end
def events=(events)
events.each do |event|
event.target_id = id
event.data.deep_symbolize_keys!
event.save!
end
end
end
\ No newline at end of file
...@@ -6,6 +6,7 @@ class Issue < ActiveRecord::Base ...@@ -6,6 +6,7 @@ class Issue < ActiveRecord::Base
include Referable include Referable
include Sortable include Sortable
include Taskable include Taskable
include Eventable
DueDateStruct = Struct.new(:title, :name).freeze DueDateStruct = Struct.new(:title, :name).freeze
NoDueDate = DueDateStruct.new('No Due Date', '0').freeze NoDueDate = DueDateStruct.new('No Due Date', '0').freeze
......
...@@ -5,6 +5,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -5,6 +5,7 @@ class MergeRequest < ActiveRecord::Base
include Sortable include Sortable
include Taskable include Taskable
include Importable include Importable
include Eventable
belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project" belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project"
belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project" belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project"
......
...@@ -11,6 +11,7 @@ class Milestone < ActiveRecord::Base ...@@ -11,6 +11,7 @@ class Milestone < ActiveRecord::Base
include Referable include Referable
include StripAttribute include StripAttribute
include Milestoneish include Milestoneish
include Eventable
belongs_to :project belongs_to :project
has_many :issues has_many :issues
......
...@@ -5,6 +5,7 @@ class Note < ActiveRecord::Base ...@@ -5,6 +5,7 @@ class Note < ActiveRecord::Base
include Mentionable include Mentionable
include Awardable include Awardable
include Importable include Importable
include Eventable
# Attribute containing rendered and redacted Markdown as generated by # Attribute containing rendered and redacted Markdown as generated by
# Banzai::ObjectRenderer. # Banzai::ObjectRenderer.
......
# Model relationships to be included in the project import/export # Model relationships to be included in the project import/export
project_tree: project_tree:
- issues: - issues:
- :events
- notes: - notes:
:author - :author
- :events
- :labels - :labels
- :milestones - milestones:
- :events
- snippets: - snippets:
- notes: - notes:
:author :author
- :releases - :releases
- :events
- project_members: - project_members:
- :user - :user
- merge_requests: - merge_requests:
- notes: - notes:
:author - :author
- :events
- :merge_request_diff - :merge_request_diff
- :events
- pipelines: - pipelines:
- notes: - notes:
:author - :author
- :events
- :statuses - :statuses
- :variables - :variables
- :triggers - :triggers
......
...@@ -34,7 +34,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do ...@@ -34,7 +34,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
end end
it 'has events' do it 'has events' do
expect(saved_project_json['events']).not_to be_empty expect(saved_project_json['milestones'].first['events']).not_to be_empty
end end
it 'has milestones' do it 'has milestones' do
...@@ -132,7 +132,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do ...@@ -132,7 +132,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
statuses: [commit_status]) statuses: [commit_status])
create(:ci_build, pipeline: ci_pipeline, project: project) create(:ci_build, pipeline: ci_pipeline, project: project)
create(:milestone, project: project) milestone = create(:milestone, project: project)
create(:note, noteable: issue, project: project) create(:note, noteable: issue, project: project)
create(:note, noteable: merge_request, project: project) create(:note, noteable: merge_request, project: project)
create(:note, noteable: snippet, project: project) create(:note, noteable: snippet, project: project)
...@@ -140,6 +140,9 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do ...@@ -140,6 +140,9 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
author: user, author: user,
project: project, project: project,
commit_id: ci_pipeline.sha) commit_id: ci_pipeline.sha)
create(:event, target: milestone, project: project, action: Event::CREATED, author: user)
project project
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