Class: Import::GithubService
Constant Summary
Constants inherited
from BaseService
BaseService::UnauthorizedError
Instance Attribute Summary collapse
Attributes inherited from BaseService
#project
Instance Method Summary
collapse
#safe_format, #tag_pair
Methods inherited from BaseService
#authorized?, #initialize
Methods inherited from BaseService
#initialize
#deny_visibility_level, #event_service, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level
#can?, #can_all?, #can_any?
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
8
9
10
|
# File 'app/services/import/github_service.rb', line 8
def client
@client
end
|
#current_user ⇒ Object
Returns the value of attribute current_user.
9
10
11
|
# File 'app/services/import/github_service.rb', line 9
def current_user
@current_user
end
|
#params ⇒ Object
Returns the value of attribute params.
9
10
11
|
# File 'app/services/import/github_service.rb', line 9
def params
@params
end
|
Instance Method Details
#allow_local_requests? ⇒ Boolean
74
75
76
|
# File 'app/services/import/github_service.rb', line 74
def allow_local_requests?
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
end
|
#blocked_url? ⇒ Boolean
78
79
80
81
82
83
84
85
86
87
|
# File 'app/services/import/github_service.rb', line 78
def blocked_url?
Gitlab::HTTP_V2::UrlBlocker.blocked_url?(
url,
allow_localhost: allow_local_requests?,
allow_local_network: allow_local_requests?,
schemes: %w[http https],
deny_all_requests_except_allowed: Gitlab::CurrentSettings.deny_all_requests_except_allowed?,
outbound_local_requests_allowlist: Gitlab::CurrentSettings.outbound_local_requests_whitelist )
end
|
#create_project(access_params, provider) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'app/services/import/github_service.rb', line 43
def create_project(access_params, provider)
Gitlab::LegacyGithubImport::ProjectCreator.new(
repo,
project_name,
target_namespace,
current_user,
type: provider,
**access_params
).execute()
end
|
#execute(access_params, provider) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/services/import/github_service.rb', line 11
def execute(access_params, provider)
if rate_limited?
return error(_('This endpoint has been requested too many times. Try again later.'), :too_many_requests)
end
context_error = validate_context
return context_error if context_error
if provider == :github access_token_error = validate_access_token
return access_token_error if access_token_error
end
project = create_project(access_params, provider)
track_access_level(provider.to_s)
if project.persisted?
store_import_settings(project)
success(project)
elsif project.errors[:import_source_disabled].present?
error(project.errors[:import_source_disabled], :forbidden)
else
error(project_save_error(project), :unprocessable_entity)
end
rescue Octokit::Error => e
log_error(e)
end
|
66
67
68
|
# File 'app/services/import/github_service.rb', line 66
def
{}
end
|
#project_name ⇒ Object
58
59
60
|
# File 'app/services/import/github_service.rb', line 58
def project_name
@project_name ||= params[:new_name].presence || repo[:name]
end
|
#repo ⇒ Object
54
55
56
|
# File 'app/services/import/github_service.rb', line 54
def repo
@repo ||= client.repository(params[:repo_id].to_i)
end
|
#target_namespace ⇒ Object
62
63
64
|
# File 'app/services/import/github_service.rb', line 62
def target_namespace
@target_namespace ||= Namespace.find_by_full_path(target_namespace_path)
end
|
#url ⇒ Object
70
71
72
|
# File 'app/services/import/github_service.rb', line 70
def url
@url ||= params[:github_hostname]
end
|