Clone GitHub wiki

parent 3c0a713a
module Github module Github
class Import class Import
class MergeRequest < ::MergeRequest class MergeRequest < ::MergeRequest
self.table_name = 'merge_requests' self.table_name = 'merge_requests'
...@@ -47,6 +48,7 @@ module Github ...@@ -47,6 +48,7 @@ module Github
fetch_milestones fetch_milestones
fetch_pull_requests fetch_pull_requests
fetch_issues fetch_issues
fetch_wiki_repository
expire_repository_cache expire_repository_cache
errors errors
...@@ -57,7 +59,7 @@ module Github ...@@ -57,7 +59,7 @@ module Github
def fetch_repository def fetch_repository
begin begin
project.create_repository project.create_repository
project.repository.add_remote('github', "https://{token}@github.com/#{repo}.git") project.repository.add_remote('github', "https://{options.fetch(:token)}@github.com/#{repo}.git")
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
...@@ -65,6 +67,22 @@ module Github ...@@ -65,6 +67,22 @@ module Github
end end
end end
def fetch_wiki_repository
wiki_url = "https://{options.fetch(:token)}@github.com/#{repo}.wiki.git"
wiki_path = "#{project.path_with_namespace}.wiki"
unless project.wiki.repository_exists?
gitlab_shell.import_repository(project.repository_storage_path, wiki_path, wiki_url)
end
rescue Gitlab::Shell::Error => e
# GitHub error message when the wiki repo has not been created,
# this means that repo has wiki enabled, but have no pages. So,
# we can skip the import.
if e.message !~ /repository not exported/
errors(:wiki, wiki_url, e.message)
end
end
def fetch_labels def fetch_labels
url = "/repos/#{repo}/labels" url = "/repos/#{repo}/labels"
...@@ -163,6 +181,7 @@ module Github ...@@ -163,6 +181,7 @@ module Github
comments_url = "/repos/#{repo}/issues/#{pull_request.iid}/comments" comments_url = "/repos/#{repo}/issues/#{pull_request.iid}/comments"
fetch_comments(merge_request, :comment, comments_url) fetch_comments(merge_request, :comment, comments_url)
rescue => e rescue => e
error(:pull_request, pull_request.url, e.message)
ensure ensure
clean_up_restored_branches(pull_request) clean_up_restored_branches(pull_request)
end end
...@@ -209,8 +228,8 @@ module Github ...@@ -209,8 +228,8 @@ module Github
issue.updated_at = representation.updated_at issue.updated_at = representation.updated_at
issue.save!(validate: false) issue.save!(validate: false)
# Fetch comments
if representation.has_comments? if representation.has_comments?
# Fetch comments
comments_url = "/repos/#{repo}/issues/#{issue.iid}/comments" comments_url = "/repos/#{repo}/issues/#{issue.iid}/comments"
fetch_comments(issue, :comment, comments_url) fetch_comments(issue, :comment, comments_url)
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