| ... | @@ -5,7 +5,10 @@ module Gitlab |
... | @@ -5,7 +5,10 @@ module Gitlab |
|
|
|
|
|
|
|
def initialize(project)
|
|
def initialize(project)
|
|
|
@project = project
|
|
@project = project
|
|
|
@repo = GoogleCodeImport::Repository.new(project.import_data["repo"])
|
|
|
|
|
|
import_data = project.import_data.try(:data)
|
|
|
|
repo_data = import_data["repo"] if import_data
|
|
|
|
@repo = GoogleCodeImport::Repository.new(repo_data)
|
|
|
|
|
|
|
|
@closed_statuses = []
|
|
@closed_statuses = []
|
|
|
@known_labels = Set.new
|
|
@known_labels = Set.new
|
| ... | @@ -27,9 +30,10 @@ module Gitlab |
... | @@ -27,9 +30,10 @@ module Gitlab |
|
|
|
|
|
|
|
def user_map
|
|
def user_map
|
|
|
@user_map ||= begin
|
|
@user_map ||= begin
|
|
|
user_map = Hash.new { |hash, user| hash[user] = Client.mask_email(user) }
|
|
user_map = Hash.new { |hash, user| Client.mask_email(user) }
|
|
|
|
|
|
|
|
stored_user_map = project.import_data["user_map"]
|
|
import_data = project.import_data.try(:data)
|
|
|
|
stored_user_map = import_data["user_map"] if import_data
|
|
|
user_map.update(stored_user_map) if stored_user_map
|
|
user_map.update(stored_user_map) if stored_user_map
|
|
|
|
|
|
|
|
user_map
|
|
user_map
|
| ... | @@ -58,24 +62,7 @@ module Gitlab |
... | @@ -58,24 +62,7 @@ module Gitlab |
|
|
def import_issues
|
|
def import_issues
|
|
|
return unless repo.issues
|
|
return unless repo.issues
|
|
|
|
|
|
|
|
last_id = 0
|
|
while raw_issue = repo.issues.shift
|
|
|
|
|
|
|
|
deleted_issues = []
|
|
|
|
|
|
|
|
|
|
repo.issues.each do |raw_issue|
|
|
|
|
|
while raw_issue["id"] > last_id + 1
|
|
|
|
|
last_id += 1
|
|
|
|
|
|
|
|
|
|
issue = project.issues.create!(
|
|
|
|
|
title: "Deleted issue",
|
|
|
|
|
description: "*This issue has been deleted*",
|
|
|
|
|
author_id: project.creator_id,
|
|
|
|
|
state: "closed"
|
|
|
|
|
)
|
|
|
|
|
deleted_issues << issue
|
|
|
|
|
end
|
|
|
|
|
last_id = raw_issue["id"]
|
|
|
|
|
|
|
|
|
|
author = user_map[raw_issue["author"]["name"]]
|
|
author = user_map[raw_issue["author"]["name"]]
|
|
|
date = DateTime.parse(raw_issue["published"]).to_formatted_s(:long)
|
|
date = DateTime.parse(raw_issue["published"]).to_formatted_s(:long)
|
|
|
|
|
|
| ... | @@ -112,7 +99,8 @@ module Gitlab |
... | @@ -112,7 +99,8 @@ module Gitlab |
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
issue = project.issues.create!(
|
|
issue = Issue.create!(
|
|
|
|
project_id: project.id,
|
|
|
title: raw_issue["title"],
|
|
title: raw_issue["title"],
|
|
|
description: body,
|
|
description: body,
|
|
|
author_id: project.creator_id,
|
|
author_id: project.creator_id,
|
| ... | @@ -121,14 +109,17 @@ module Gitlab |
... | @@ -121,14 +109,17 @@ module Gitlab |
|
|
)
|
|
)
|
|
|
issue.add_labels_by_names(labels)
|
|
issue.add_labels_by_names(labels)
|
|
|
|
|
|
|
|
import_issue_comments(issue, comments)
|
|
if issue.iid != raw_issue["id"]
|
|
|
|
issue.update_attribute(:iid, raw_issue["id"])
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
deleted_issues.each(&:destroy!)
|
|
import_issue_comments(issue, comments)
|
|
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
def import_issue_comments(issue, comments)
|
|
def import_issue_comments(issue, comments)
|
|
|
comments.each do |raw_comment|
|
|
Note.transaction do
|
|
|
|
while raw_comment = comments.shift
|
|
|
next if raw_comment.has_key?("deletedBy")
|
|
next if raw_comment.has_key?("deletedBy")
|
|
|
|
|
|
|
|
content = format_content(raw_comment["content"])
|
|
content = format_content(raw_comment["content"])
|
| ... | @@ -149,13 +140,17 @@ module Gitlab |
... | @@ -149,13 +140,17 @@ module Gitlab |
|
|
attachments
|
|
attachments
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
issue.notes.create!(
|
|
# Needs to match order of `comment_columns` below.
|
|
|
|
Note.create!(
|
|
|
project_id: project.id,
|
|
project_id: project.id,
|
|
|
|
noteable_type: "Issue",
|
|
|
|
noteable_id: issue.id,
|
|
|
author_id: project.creator_id,
|
|
author_id: project.creator_id,
|
|
|
note: body
|
|
note: body
|
|
|
)
|
|
)
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def nice_label_color(name)
|
|
def nice_label_color(name)
|
|
|
case name
|
|
case name
|
| ... | @@ -232,7 +227,7 @@ module Gitlab |
... | @@ -232,7 +227,7 @@ module Gitlab |
|
|
|
|
|
|
|
def create_label(name)
|
|
def create_label(name)
|
|
|
color = nice_label_color(name)
|
|
color = nice_label_color(name)
|
|
|
project.labels.create!(name: name, color: color)
|
|
Label.create!(project_id: project.id, name: name, color: color)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
def format_content(raw_content)
|
|
def format_content(raw_content)
|
| ... | |
... | |
| ... | | ... | |