mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-18 00:56:41 +10:00
some refactoring based on feedback
This commit is contained in:
@@ -8,7 +8,7 @@ module Gitlab
|
||||
def initialize(project)
|
||||
@project = project
|
||||
credentials = project.import_data.credentials if import_data
|
||||
@client = Client.new(credentials["github_access_token"])
|
||||
@client = Client.new(credentials[:user])
|
||||
@formatter = Gitlab::ImportFormatter.new
|
||||
end
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ module Gitlab
|
||||
end
|
||||
|
||||
def execute
|
||||
project = ::Projects::CreateService.new(
|
||||
::Projects::CreateService.new(
|
||||
current_user,
|
||||
name: repo.name,
|
||||
path: repo.name,
|
||||
@@ -20,19 +20,9 @@ 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,
|
||||
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
|
||||
|
||||
create_import_data(project)
|
||||
project
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_import_data(project)
|
||||
project.create_import_data(
|
||||
credentials: { github_access_token: session_data.delete(:github_access_token) })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,9 +12,7 @@ module Gitlab
|
||||
end
|
||||
|
||||
def import_url
|
||||
import_url = Gitlab::ImportUrlExposer.expose(import_url: project.import_url,
|
||||
credentials: project.import_data.credentials)
|
||||
import_url.sub(/\.git\z/, ".wiki.git")
|
||||
project.import_url.import_url.sub(/\.git\z/, ".wiki.git")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
module Gitlab
|
||||
class ImportUrlSanitizer
|
||||
def initialize(url)
|
||||
@url = URI.parse(url)
|
||||
end
|
||||
|
||||
def sanitized_url
|
||||
@sanitized_url ||= safe_url.to_s
|
||||
end
|
||||
|
||||
def credentials
|
||||
@credentials ||= { user: @url.user, password: @url.password }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def safe_url
|
||||
safe_url = @url.dup
|
||||
safe_url.password = nil
|
||||
safe_url.user = nil
|
||||
safe_url
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user