Import GitHub wiki into GitLab

parent e47f0e56
module Gitlab
module GithubImport
class Importer
include Gitlab::ShellAdapter
attr_reader :project, :client
def initialize(project)
......@@ -14,8 +16,11 @@ module Gitlab
def execute
import_issues
import_pull_requests
import_wiki
true
rescue Gitlab::Shell::Error
false
end
private
......@@ -66,6 +71,14 @@ module Gitlab
noteable.notes.create!(comment.attributes)
end
end
def import_wiki
unless project.wiki_enabled?
wiki = WikiFormatter.new(project)
gitlab_shell.import_repository(wiki.path_with_namespace, wiki.import_url)
project.update_attribute(:wiki_enabled, true)
end
end
end
end
end
......@@ -20,7 +20,8 @@ module Gitlab
visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::VisibilityLevel::PUBLIC,
import_type: "github",
import_source: repo.full_name,
import_url: repo.clone_url.sub("https://", "https://#{@session_data[:github_access_token]}@")
import_url: repo.clone_url.sub("https://", "https://#{@session_data[:github_access_token]}@"),
wiki_enabled: !repo.has_wiki? # If repo has wiki we'll import it later
).execute
project.create_import_data(data: { "github_session" => session_data } )
......
module Gitlab
module GithubImport
class WikiFormatter
attr_reader :project
def initialize(project)
@project = project
end
def path_with_namespace
"#{project.path_with_namespace}.wiki"
end
def import_url
project.import_url.sub(".git", ".wiki.git")
end
end
end
end
require 'spec_helper'
describe Gitlab::GithubImport::WikiFormatter, lib: true do
let(:project) do
create(:project, namespace: create(:namespace, path: 'gitlabhq'),
import_url: 'https://xxx@github.com/gitlabhq/gitlabhq.git')
end
subject(:wiki) { described_class.new(project)}
describe '#path_with_namespace' do
it 'appends .wiki to project path' do
expect(wiki.path_with_namespace).to eq 'gitlabhq/gitlabhq.wiki'
end
end
describe '#import_url' do
it 'returns URL of the wiki repository' do
expect(wiki.import_url).to eq 'https://xxx@github.com/gitlabhq/gitlabhq.wiki.git'
end
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