Import GitHub wiki into GitLab

This commit is contained in:
Douglas Barbosa Alexandre 2016-01-06 21:15:37 -02:00
parent e47f0e563d
commit 78f5eb94fb
4 changed files with 56 additions and 1 deletions

View file

@ -1,6 +1,8 @@
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

View file

@ -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 } )

View file

@ -0,0 +1,19 @@
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

View file

@ -0,0 +1,22 @@
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