Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/github_import/importer/events/changed_milestone.rb')
-rw-r--r--lib/gitlab/github_import/importer/events/changed_milestone.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/gitlab/github_import/importer/events/changed_milestone.rb b/lib/gitlab/github_import/importer/events/changed_milestone.rb
new file mode 100644
index 00000000000..3164c041dc3
--- /dev/null
+++ b/lib/gitlab/github_import/importer/events/changed_milestone.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GithubImport
+ module Importer
+ module Events
+ class ChangedMilestone < BaseImporter
+ # GitHub API doesn't provide the historical state of an issue for
+ # de/milestoned issue events. So we'll assign the default state to
+ # those events that are imported from GitHub.
+ DEFAULT_STATE = Issue.available_states[:opened]
+
+ def execute(issue_event)
+ create_event(issue_event)
+ end
+
+ private
+
+ def create_event(issue_event)
+ ResourceMilestoneEvent.create!(
+ issue_id: issuable_db_id(issue_event),
+ user_id: author_id(issue_event),
+ created_at: issue_event.created_at,
+ milestone_id: project.milestones.find_by_title(issue_event.milestone_title)&.id,
+ action: action(issue_event.event),
+ state: DEFAULT_STATE
+ )
+ end
+
+ def action(event_type)
+ return ResourceMilestoneEvent.actions[:remove] if event_type == 'demilestoned'
+
+ ResourceMilestoneEvent.actions[:add]
+ end
+ end
+ end
+ end
+ end
+end