summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-04-18 13:44:27 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-04-18 20:07:04 -0300
commit06ec511164b37cadbfdf069037745c108486162c (patch)
tree50b57b5b35a55333beb53cda63bb80f22bcabecf /lib
parent17b60d681828567e47c8a62ef312abc46e2beeea (diff)
downloadgitlab-ce-06ec511164b37cadbfdf069037745c108486162c.tar.gz
Import milestones from GitHub
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/github_import/importer.rb13
-rw-r--r--lib/gitlab/github_import/milestone_formatter.rb48
2 files changed, 60 insertions, 1 deletions
diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb
index 7f70ab63f37..0f9e3ee14ee 100644
--- a/lib/gitlab/github_import/importer.rb
+++ b/lib/gitlab/github_import/importer.rb
@@ -16,7 +16,8 @@ module Gitlab
end
def execute
- import_labels && import_issues && import_pull_requests && import_wiki
+ import_labels && import_milestones && import_issues &&
+ import_pull_requests && import_wiki
end
private
@@ -35,6 +36,16 @@ module Gitlab
raise Projects::ImportService::Error, e.message
end
+ def import_milestones
+ client.list_milestones(project.import_source, state: :all).each do |raw_data|
+ Milestone.create!(MilestoneFormatter.new(project, raw_data).attributes)
+ end
+
+ true
+ rescue ActiveRecord::RecordInvalid => e
+ raise Projects::ImportService::Error, e.message
+ end
+
def import_issues
client.list_issues(project.import_source, state: :all,
sort: :created,
diff --git a/lib/gitlab/github_import/milestone_formatter.rb b/lib/gitlab/github_import/milestone_formatter.rb
new file mode 100644
index 00000000000..e91a7e328cf
--- /dev/null
+++ b/lib/gitlab/github_import/milestone_formatter.rb
@@ -0,0 +1,48 @@
+module Gitlab
+ module GithubImport
+ class MilestoneFormatter < BaseFormatter
+ def attributes
+ {
+ iid: number,
+ project: project,
+ title: title,
+ description: description,
+ due_date: due_date,
+ state: state,
+ created_at: created_at,
+ updated_at: updated_at
+ }
+ end
+
+ private
+
+ def number
+ raw_data.number
+ end
+
+ def title
+ raw_data.title
+ end
+
+ def description
+ raw_data.description
+ end
+
+ def due_date
+ raw_data.due_on
+ end
+
+ def state
+ raw_data.state == 'closed' ? 'closed' : 'active'
+ end
+
+ def created_at
+ raw_data.created_at
+ end
+
+ def updated_at
+ state == 'closed' ? raw_data.closed_at : raw_data.updated_at
+ end
+ end
+ end
+end