Import GitHub wiki into GitLab

parent e47f0e56
module Gitlab module Gitlab
module GithubImport module GithubImport
class Importer class Importer
include Gitlab::ShellAdapter
attr_reader :project, :client attr_reader :project, :client
def initialize(project) def initialize(project)
...@@ -14,8 +16,11 @@ module Gitlab ...@@ -14,8 +16,11 @@ module Gitlab
def execute def execute
import_issues import_issues
import_pull_requests import_pull_requests
import_wiki
true true
rescue Gitlab::Shell::Error
false
end end
private private
...@@ -66,6 +71,14 @@ module Gitlab ...@@ -66,6 +71,14 @@ module Gitlab
noteable.notes.create!(comment.attributes) noteable.notes.create!(comment.attributes)
end end
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 end
end end
...@@ -20,7 +20,8 @@ module Gitlab ...@@ -20,7 +20,8 @@ module Gitlab
visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::VisibilityLevel::PUBLIC, visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::VisibilityLevel::PUBLIC,
import_type: "github", import_type: "github",
import_source: repo.full_name, 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 ).execute
project.create_import_data(data: { "github_session" => session_data } ) 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