diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-23 09:11:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-23 09:11:16 +0300 |
commit | d5f3372f10b9fefc8cf831515152eee7ae908f69 (patch) | |
tree | a9d231fa5618b907f38565f72d8c41d112c601c5 /app/services/import | |
parent | bf562015bb1bfd526c6367fed394a74ab0eeabf0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/import')
-rw-r--r-- | app/services/import/github_service.rb | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/app/services/import/github_service.rb b/app/services/import/github_service.rb index 847c5eb4397..3ee5a185f42 100644 --- a/app/services/import/github_service.rb +++ b/app/services/import/github_service.rb @@ -2,6 +2,9 @@ module Import class GithubService < Import::BaseService + include ActiveSupport::NumberHelper + include Gitlab::Utils::StrongMemoize + attr_accessor :client attr_reader :params, :current_user @@ -14,6 +17,10 @@ module Import return error(_('This namespace has already been taken! Please choose another one.'), :unprocessable_entity) end + if oversized? + return error(oversize_error_message, :unprocessable_entity) + end + project = create_project(access_params, provider) if project.persisted? @@ -32,7 +39,8 @@ module Import target_namespace, current_user, type: provider, - **access_params).execute(extra_project_attrs) + **access_params + ).execute(extra_project_attrs) end def repo @@ -55,6 +63,30 @@ module Import {} end + def oversized? + repository_size_limit > 0 && repo.size > repository_size_limit + end + + 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 + + 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 + def authorized? can?(current_user, :create_projects, target_namespace) end |