Class: Import::GithubService
- Inherits:
-
BaseService
show all
- Includes:
- ActiveSupport::NumberHelper, Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/import/github_service.rb
Instance Attribute Summary collapse
Attributes inherited from BaseService
#project
Instance Method Summary
collapse
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?
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
85
86
87
|
# File 'app/services/import/github_service.rb', line 85
def allow_local_requests?
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
end
|
#blocked_url? ⇒ Boolean
89
90
91
92
93
94
95
96
|
# File 'app/services/import/github_service.rb', line 89
def blocked_url?
Gitlab::UrlBlocker.blocked_url?(
url,
allow_localhost: allow_local_requests?,
allow_local_network: allow_local_requests?,
schemes: %w[http https]
)
end
|
#create_project(access_params, provider) ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'app/services/import/github_service.rb', line 30
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
|
# File 'app/services/import/github_service.rb', line 11
def execute(access_params, provider)
context_error = validate_context
return context_error if context_error
project = create_project(access_params, provider)
track_access_level('github')
if project.persisted?
store_import_settings(project, access_params)
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
|
53
54
55
|
# File 'app/services/import/github_service.rb', line 53
def
{}
end
|
#oversize_error_message ⇒ Object
61
62
63
64
65
66
67
|
# File 'app/services/import/github_service.rb', line 61
def oversize_error_message
_('"%{repository_name}" size (%{repository_size}) is larger than the limit of %{limit}.') % {
repository_name: repo[:name],
repository_size: number_to_human_size(repo[:size]),
limit: number_to_human_size(repository_size_limit)
}
end
|
#oversized? ⇒ Boolean
57
58
59
|
# File 'app/services/import/github_service.rb', line 57
def oversized?
repository_size_limit > 0 && repo[:size] > repository_size_limit
end
|
#project_name ⇒ Object
45
46
47
|
# File 'app/services/import/github_service.rb', line 45
def project_name
@project_name ||= params[:new_name].presence || repo[:name]
end
|
#repo ⇒ Object
41
42
43
|
# File 'app/services/import/github_service.rb', line 41
def repo
@repo ||= client.repository(params[:repo_id].to_i)
end
|
#repository_size_limit ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/services/import/github_service.rb', line 69
def repository_size_limit
strong_memoize :repository_size_limit do
namespace_limit = target_namespace.repository_size_limit.to_i
if namespace_limit > 0
namespace_limit
else
Gitlab::CurrentSettings.repository_size_limit.to_i
end
end
end
|
#target_namespace ⇒ Object
49
50
51
|
# File 'app/services/import/github_service.rb', line 49
def target_namespace
@target_namespace ||= Namespace.find_by_full_path(target_namespace_path)
end
|
#url ⇒ Object
81
82
83
|
# File 'app/services/import/github_service.rb', line 81
def url
@url ||= params[:github_hostname]
end
|