summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-14 14:50:56 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-14 14:50:56 +0200
commitdba63d667d536c939400979a22967ed9b25980b2 (patch)
tree224155b5cdd0bc9db91df26436a2387f4a3116af /lib
parentf6cb42f3d197b7920207088f5fa5f5161be90905 (diff)
downloadgitlab-ce-dba63d667d536c939400979a22967ed9b25980b2.tar.gz
Allow user map to be specified.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/google_code_import/client.rb25
-rw-r--r--lib/gitlab/google_code_import/importer.rb32
-rw-r--r--lib/gitlab/google_code_import/project_creator.rb12
-rw-r--r--lib/gitlab/google_code_import/repository.rb4
4 files changed, 56 insertions, 17 deletions
diff --git a/lib/gitlab/google_code_import/client.rb b/lib/gitlab/google_code_import/client.rb
index 0514494d3ad..02f31e45f88 100644
--- a/lib/gitlab/google_code_import/client.rb
+++ b/lib/gitlab/google_code_import/client.rb
@@ -3,6 +3,12 @@ module Gitlab
class Client
attr_reader :raw_data
+ def self.mask_email(author)
+ parts = author.split("@", 2)
+ parts[0] = "#{parts[0][0...-3]}..."
+ parts.join("@")
+ end
+
def initialize(raw_data)
@raw_data = raw_data
end
@@ -18,6 +24,25 @@ module Gitlab
def repo(id)
repos.find { |repo| repo.id == id }
end
+
+ def user_map
+ user_map = Hash.new { |hash, user| hash[user] = self.class.mask_email(user) }
+
+ repos.each do |repo|
+ next unless repo.valid? && repo.issues
+
+ repo.issues.each do |raw_issue|
+ # Touching is enough to add the entry and masked email.
+ user_map[raw_issue["author"]["name"]]
+
+ raw_issue["comments"]["items"].each do |raw_comment|
+ user_map[raw_comment["author"]["name"]]
+ end
+ end
+ end
+
+ Hash[user_map.sort]
+ end
end
end
end
diff --git a/lib/gitlab/google_code_import/importer.rb b/lib/gitlab/google_code_import/importer.rb
index eaa8c6bc6d3..730fbb8606b 100644
--- a/lib/gitlab/google_code_import/importer.rb
+++ b/lib/gitlab/google_code_import/importer.rb
@@ -5,7 +5,7 @@ module Gitlab
def initialize(project)
@project = project
- @repo = GoogleCodeImport::Repository.new(project.import_data)
+ @repo = GoogleCodeImport::Repository.new(project.import_data["repo"])
@closed_statuses = []
@known_labels = Set.new
@@ -25,6 +25,17 @@ module Gitlab
private
+ def user_map
+ @user_map ||= begin
+ user_map = Hash.new { |hash, user| hash[user] = Client.mask_email(user) }
+
+ stored_user_map = project.import_data["user_map"]
+ user_map.update(stored_user_map) if stored_user_map
+
+ user_map
+ end
+ end
+
def import_status_labels
repo.raw_data["issuesConfig"]["statuses"].each do |status|
closed = !status["meansOpen"]
@@ -45,14 +56,13 @@ module Gitlab
end
def import_issues
- return unless repo.raw_data["issues"]
+ return unless repo.issues
last_id = 0
deleted_issues = []
- issues = repo.raw_data["issues"]["items"]
- issues.each do |raw_issue|
+ repo.issues.each do |raw_issue|
while raw_issue["id"] > last_id + 1
last_id += 1
@@ -66,7 +76,7 @@ module Gitlab
end
last_id = raw_issue["id"]
- author = mask_email(raw_issue["author"]["name"])
+ author = user_map[raw_issue["author"]["name"]]
date = DateTime.parse(raw_issue["published"]).to_formatted_s(:long)
body = []
@@ -119,7 +129,7 @@ module Gitlab
comments.each do |raw_comment|
next if raw_comment.has_key?("deletedBy")
- author = mask_email(raw_comment["author"]["name"])
+ author = user_map[raw_comment["author"]["name"]]
date = DateTime.parse(raw_comment["published"]).to_formatted_s(:long)
body = []
@@ -202,12 +212,6 @@ module Gitlab
"Status: #{name}"
end
- def mask_email(author)
- parts = author.split("@", 2)
- parts[0] = "#{parts[0][0...-3]}..."
- parts.join("@")
- end
-
def linkify_issues(s)
s.gsub(/([Ii]ssue) ([0-9]+)/, '\1 #\2')
end
@@ -248,14 +252,14 @@ module Gitlab
end
if raw_updates.has_key?("owner")
- updates << "*Owner: #{mask_email(raw_updates["owner"])}*"
+ updates << "*Owner: #{user_map[raw_updates["owner"]]}*"
end
if raw_updates.has_key?("cc")
cc = raw_updates["cc"].map do |l|
deleted = l.start_with?("-")
l = l[1..-1] if deleted
- l = mask_email(l)
+ l = user_map[l]
l = "~~#{l}~~" if deleted
l
end
diff --git a/lib/gitlab/google_code_import/project_creator.rb b/lib/gitlab/google_code_import/project_creator.rb
index 933e144d8ea..7ac4387d79d 100644
--- a/lib/gitlab/google_code_import/project_creator.rb
+++ b/lib/gitlab/google_code_import/project_creator.rb
@@ -1,15 +1,21 @@
module Gitlab
module GoogleCodeImport
class ProjectCreator
- attr_reader :repo, :namespace, :current_user
+ attr_reader :repo, :namespace, :current_user, :user_map
- def initialize(repo, namespace, current_user)
+ def initialize(repo, namespace, current_user, user_map = nil)
@repo = repo
@namespace = namespace
@current_user = current_user
+ @user_map = user_map
end
def execute
+ import_data = {
+ "repo" => repo.raw_data,
+ "user_map" => user_map
+ }
+
@project = Project.new(
name: repo.name,
path: repo.name,
@@ -20,7 +26,7 @@ module Gitlab
import_type: "google_code",
import_source: repo.name,
import_url: repo.import_url,
- import_data: repo.raw_data
+ import_data: import_data
)
if @project.save!
diff --git a/lib/gitlab/google_code_import/repository.rb b/lib/gitlab/google_code_import/repository.rb
index 39a884d8292..ad33fc2cad2 100644
--- a/lib/gitlab/google_code_import/repository.rb
+++ b/lib/gitlab/google_code_import/repository.rb
@@ -34,6 +34,10 @@ module Gitlab
def import_url
raw_data["repositoryUrls"].first
end
+
+ def issues
+ raw_data["issues"] && raw_data["issues"]["items"]
+ end
end
end
end