Commit ff082a00 authored by Yorick Peterse's avatar Yorick Peterse

Fix the GH importer Rake task

This task was broken in a few areas with the removal of the old GitHub
importer code.
parent 2b886a78
...@@ -14,7 +14,9 @@ class GithubImport ...@@ -14,7 +14,9 @@ class GithubImport
end end
def run! def run!
@repo = GithubRepos.new(@options, @current_user, @github_repo).choose_one! @repo = GithubRepos
.new(@options[:token], @current_user, @github_repo)
.choose_one!
raise 'No repo found!' unless @repo raise 'No repo found!' unless @repo
...@@ -28,7 +30,7 @@ class GithubImport ...@@ -28,7 +30,7 @@ class GithubImport
private private
def show_warning! def show_warning!
puts "This will import GitHub #{@repo['full_name'].bright} into GitLab #{@project_path.bright} as #{@current_user.name}" puts "This will import GitHub #{@repo.full_name.bright} into GitLab #{@project_path.bright} as #{@current_user.name}"
puts "Permission checks are ignored. Press any key to continue.".color(:red) puts "Permission checks are ignored. Press any key to continue.".color(:red)
STDIN.getch STDIN.getch
...@@ -65,16 +67,16 @@ class GithubImport ...@@ -65,16 +67,16 @@ class GithubImport
@current_user, @current_user,
name: name, name: name,
path: name, path: name,
description: @repo['description'], description: @repo.description,
namespace_id: namespace.id, namespace_id: namespace.id,
visibility_level: visibility_level, visibility_level: visibility_level,
skip_wiki: @repo['has_wiki'] skip_wiki: @repo.has_wiki
).execute ).execute
project.update!( project.update!(
import_type: 'github', import_type: 'github',
import_source: @repo['full_name'], import_source: @repo.full_name,
import_url: @repo['clone_url'].sub('://', "://#{@options[:token]}@") import_url: @repo.clone_url.sub('://', "://#{@options[:token]}@")
) )
project project
...@@ -93,13 +95,15 @@ class GithubImport ...@@ -93,13 +95,15 @@ class GithubImport
end end
def visibility_level def visibility_level
@repo['private'] ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::CurrentSettings.current_application_settings.default_project_visibility @repo.private ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::CurrentSettings.current_application_settings.default_project_visibility
end end
end end
class GithubRepos class GithubRepos
def initialize(options, current_user, github_repo) def initialize(token, current_user, github_repo)
@options = options @client = Octokit::Client
.new(access_token: token, auto_paginate: true, per_page: 100)
@current_user = current_user @current_user = current_user
@github_repo = github_repo @github_repo = github_repo
end end
...@@ -108,17 +112,17 @@ class GithubRepos ...@@ -108,17 +112,17 @@ class GithubRepos
return found_github_repo if @github_repo return found_github_repo if @github_repo
repos.each do |repo| repos.each do |repo|
print "ID: #{repo['id'].to_s.bright}".color(:green) print "ID: #{repo.id.to_s.bright}".color(:green)
print "\tName: #{repo['full_name']}\n".color(:green) print "\tName: #{repo.full_name}\n".color(:green)
end end
print 'ID? '.bright print 'ID? '.bright
repos.find { |repo| repo['id'] == repo_id } repos.find { |repo| repo.id == repo_id }
end end
def found_github_repo def found_github_repo
repos.find { |repo| repo['full_name'] == @github_repo } repos.find { |repo| repo.full_name == @github_repo }
end end
def repo_id def repo_id
...@@ -126,7 +130,7 @@ class GithubRepos ...@@ -126,7 +130,7 @@ class GithubRepos
end end
def repos def repos
Github::Repositories.new(@options).fetch @client.list_repositories
end 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