Use project.import_url to fetch repositories from Github

parent 66e7b4cd
...@@ -41,13 +41,16 @@ module Github ...@@ -41,13 +41,16 @@ module Github
self.reset_callbacks :validate self.reset_callbacks :validate
end end
attr_reader :project, :repository, :repo, :options, :errors, :cached, :verbose attr_reader :project, :repository, :repo, :repo_url, :wiki_url,
:options, :errors, :cached, :verbose
def initialize(project, options) def initialize(project, options)
@project = project @project = project
@repository = project.repository @repository = project.repository
@repo = project.import_source @repo = project.import_source
@options = options @options = options
@repo_url = project.import_url
@wiki_url = project.import_url.sub(/\.git\z/, '.wiki.git')
@verbose = options.fetch(:verbose, false) @verbose = options.fetch(:verbose, false)
@cached = Hash.new { |hash, key| hash[key] = Hash.new } @cached = Hash.new { |hash, key| hash[key] = Hash.new }
@errors = [] @errors = []
...@@ -81,23 +84,21 @@ module Github ...@@ -81,23 +84,21 @@ module Github
def fetch_repository def fetch_repository
begin begin
project.create_repository unless project.repository.exists? project.ensure_repository
project.repository.add_remote('github', "https://#{options.fetch(:token)}@github.com/#{repo}.git") project.repository.add_remote('github', repo_url)
project.repository.set_remote_as_mirror('github') project.repository.set_remote_as_mirror('github')
project.repository.fetch_remote('github', forced: true) project.repository.fetch_remote('github', forced: true)
rescue Gitlab::Shell::Error => e rescue Gitlab::Shell::Error => e
error(:project, "https://github.com/#{repo}.git", e.message) error(:project, repo_url, e.message)
raise Github::RepositoryFetchError raise Github::RepositoryFetchError
end end
end end
def fetch_wiki_repository def fetch_wiki_repository
wiki_url = "https://#{options.fetch(:token)}@github.com/#{repo}.wiki.git" return if project.wiki.repository_exists?
wiki_path = "#{project.full_path}.wiki"
unless project.wiki.repository_exists? wiki_path = "#{project.path_with_namespace}.wiki"
gitlab_shell.import_repository(project.repository_storage_path, wiki_path, wiki_url) gitlab_shell.import_repository(project.repository_storage_path, wiki_path, wiki_url)
end
rescue Gitlab::Shell::Error => e rescue Gitlab::Shell::Error => e
# GitHub error message when the wiki repo has not been created, # GitHub error message when the wiki repo has not been created,
# this means that repo has wiki enabled, but have no pages. So, # this means that repo has wiki enabled, but have no pages. So,
......
...@@ -62,6 +62,7 @@ class GithubImport ...@@ -62,6 +62,7 @@ class GithubImport
visibility_level: visibility_level, visibility_level: visibility_level,
import_type: 'github', import_type: 'github',
import_source: @repo['full_name'], import_source: @repo['full_name'],
import_url: @repo['clone_url'].sub('://', "://#{options[:token]}@"),
skip_wiki: @repo['has_wiki'] skip_wiki: @repo['has_wiki']
).execute ).execute
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment