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
path: root/lib
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-02-03 04:01:07 +0300
committerValery Sizov <valery@gitlab.com>2015-02-05 23:50:34 +0300
commit33349dd54928a0b074b4ae3ebfabf214799fc085 (patch)
tree593a14d0f6df812410349f353e252e3a58d8cacd /lib
parent713bc152bde5396bb95a1555907bcd9a2847839d (diff)
GitLab.com integration: refactoring
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/github_import/client.rb2
-rw-r--r--lib/gitlab/github_import/importer.rb9
-rw-r--r--lib/gitlab/gitlab_import/client.rb4
-rw-r--r--lib/gitlab/gitlab_import/importer.rb10
-rw-r--r--lib/gitlab/import_formatter.rb15
5 files changed, 30 insertions, 10 deletions
diff --git a/lib/gitlab/github_import/client.rb b/lib/gitlab/github_import/client.rb
index 2e454e7c10f..cf43d36c6c3 100644
--- a/lib/gitlab/github_import/client.rb
+++ b/lib/gitlab/github_import/client.rb
@@ -14,7 +14,7 @@ module Gitlab
private
def config
- Gitlab.config.omniauth.providers.select{|provider| provider.name == "github"}.first
+ Gitlab.config.omniauth.providers.find{|provider| provider.name == "github"}
end
def github_options
diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb
index 180ad6c3018..91a4595b9ea 100644
--- a/lib/gitlab/github_import/importer.rb
+++ b/lib/gitlab/github_import/importer.rb
@@ -5,6 +5,7 @@ module Gitlab
def initialize(project)
@project = project
+ @formatter = Gitlab::ImportFormatter.new
end
def execute
@@ -13,12 +14,14 @@ module Gitlab
#Issues && Comments
client.list_issues(project.import_source, state: :all).each do |issue|
if issue.pull_request.nil?
- body = "*Created by: #{issue.user.login}*\n\n#{issue.body}"
+
+ body = @formatter.author_line(issue.user.login, issue.body)
if issue.comments > 0
- body += "\n\n\n**Imported comments:**\n"
+ body += @formatter.comments_header
+
client.issue_comments(project.import_source, issue.number).each do |c|
- body += "\n\n*By #{c.user.login} on #{c.created_at}*\n\n#{c.body}"
+ body += @formatter.comment_to_md(c.user.login, c.created_at, c.body)
end
end
diff --git a/lib/gitlab/gitlab_import/client.rb b/lib/gitlab/gitlab_import/client.rb
index 64e369e9c12..2206b68da99 100644
--- a/lib/gitlab/gitlab_import/client.rb
+++ b/lib/gitlab/gitlab_import/client.rb
@@ -13,7 +13,7 @@ module Gitlab
)
if access_token
- @api = OAuth2::AccessToken.from_hash(@client, :access_token => access_token)
+ @api = OAuth2::AccessToken.from_hash(@client, access_token: access_token)
end
end
@@ -67,7 +67,7 @@ module Gitlab
end
def config
- Gitlab.config.omniauth.providers.select{|provider| provider.name == "gitlab"}.first
+ Gitlab.config.omniauth.providers.find{|provider| provider.name == "gitlab"}
end
def github_options
diff --git a/lib/gitlab/gitlab_import/importer.rb b/lib/gitlab/gitlab_import/importer.rb
index 3e9087a556c..a529483c1e2 100644
--- a/lib/gitlab/gitlab_import/importer.rb
+++ b/lib/gitlab/gitlab_import/importer.rb
@@ -6,6 +6,7 @@ module Gitlab
def initialize(project)
@project = project
@client = Client.new(project.creator.gitlab_access_token)
+ @formatter = Gitlab::ImportFormatter.new
end
def execute
@@ -15,15 +16,16 @@ module Gitlab
issues = client.issues(project_identifier)
issues.each do |issue|
- body = "*Created by: #{issue["author"]["name"]}*\n\n#{issue["description"]}"
-
+ body = @formatter.author_line(issue["author"]["name"], issue["description"])
comments = client.issue_comments(project_identifier, issue["id"])
+
if comments.any?
- body += "\n\n\n**Imported comments:**\n"
+ body += @formatter.comments_header
end
+
comments.each do |comment|
- body += "\n\n*By #{comment["author"]["name"]} on #{comment["created_at"]}*\n\n#{comment["body"]}"
+ body += @formatter.comment_to_md(comment["author"]["name"], comment["created_at"], comment["body"])
end
project.issues.create!(
diff --git a/lib/gitlab/import_formatter.rb b/lib/gitlab/import_formatter.rb
new file mode 100644
index 00000000000..a9283eaf2a5
--- /dev/null
+++ b/lib/gitlab/import_formatter.rb
@@ -0,0 +1,15 @@
+module Gitlab
+ class ImportFormatter
+ def comment_to_md(author, date, body)
+ "\n\n*By #{author} on #{date}*\n\n#{body}"
+ end
+
+ def comments_header
+ "\n\n\n**Imported comments:**\n"
+ end
+
+ def author_line(author, body)
+ "*Created by: #{author}*\n\n#{body}"
+ end
+ end
+end \ No newline at end of file