2014-12-31 08:07:48 -05:00
|
|
|
module Gitlab
|
2015-02-02 17:26:29 -05:00
|
|
|
module GithubImport
|
2014-12-31 08:07:48 -05:00
|
|
|
class Importer
|
2015-02-05 19:57:27 -05:00
|
|
|
attr_reader :project, :client
|
2014-12-31 08:07:48 -05:00
|
|
|
|
|
|
|
def initialize(project)
|
|
|
|
@project = project
|
2015-02-05 19:57:27 -05:00
|
|
|
@client = Client.new(project.creator.github_access_token)
|
2015-02-02 20:01:07 -05:00
|
|
|
@formatter = Gitlab::ImportFormatter.new
|
2014-12-31 08:07:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
#Issues && Comments
|
|
|
|
client.list_issues(project.import_source, state: :all).each do |issue|
|
|
|
|
if issue.pull_request.nil?
|
2015-02-02 20:01:07 -05:00
|
|
|
|
|
|
|
body = @formatter.author_line(issue.user.login, issue.body)
|
2015-02-02 22:30:09 -05:00
|
|
|
|
2014-12-31 08:07:48 -05:00
|
|
|
if issue.comments > 0
|
2015-02-02 20:01:07 -05:00
|
|
|
body += @formatter.comments_header
|
|
|
|
|
2014-12-31 08:07:48 -05:00
|
|
|
client.issue_comments(project.import_source, issue.number).each do |c|
|
2015-02-17 10:59:50 -05:00
|
|
|
body += @formatter.comment(c.user.login, c.created_at, c.body)
|
2014-12-31 08:07:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
project.issues.create!(
|
2015-02-02 22:30:09 -05:00
|
|
|
description: body,
|
2014-12-31 08:07:48 -05:00
|
|
|
title: issue.title,
|
|
|
|
state: issue.state == 'closed' ? 'closed' : 'opened',
|
|
|
|
author_id: gl_user_id(project, issue.user.id)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def gl_user_id(project, github_id)
|
2015-02-05 13:31:36 -05:00
|
|
|
user = User.joins(:identities).
|
|
|
|
find_by("identities.extern_uid = ? AND identities.provider = 'github'", github_id.to_s)
|
2014-12-31 08:07:48 -05:00
|
|
|
(user && user.id) || project.creator_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|