diff options
author | Stan Hu <stanhu@gmail.com> | 2018-07-08 07:44:33 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-07-08 07:44:33 -0700 |
commit | 5d7e130e64aa08717ef0914348ee458949d7bb14 (patch) | |
tree | cfffc989ad5e305eecb31198a456ea8301e53344 /app/controllers/import | |
parent | 24ac81cca62a18b102b3414d97541bdf23a31f2d (diff) | |
download | gitlab-ce-5d7e130e64aa08717ef0914348ee458949d7bb14.tar.gz |
Add more specs and fix some typos
Diffstat (limited to 'app/controllers/import')
-rw-r--r-- | app/controllers/import/bitbucket_server_controller.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/app/controllers/import/bitbucket_server_controller.rb b/app/controllers/import/bitbucket_server_controller.rb index ac6b6a73c7a..2b48a51a947 100644 --- a/app/controllers/import/bitbucket_server_controller.rb +++ b/app/controllers/import/bitbucket_server_controller.rb @@ -27,13 +27,11 @@ class Import::BitbucketServerController < Import::BaseController end def create - bitbucket_client = BitbucketServer::Client.new(credentials) - repo = bitbucket_client.repo(@project_key, @repo_slug) unless repo return render json: { errors: "Project #{@project_key}/#{repo_slug} could not be found" } - end + end project_name = params[:new_name].presence || repo.name @@ -52,7 +50,7 @@ class Import::BitbucketServerController < Import::BaseController else render json: { errors: 'This namespace has already been taken! Please choose another one.' }, status: :unprocessable_entity end - rescue *SERVER_ERRROS => e + rescue *SERVER_ERRORS => e render json: { errors: "Unable to connect to server: #{e}" } end @@ -86,14 +84,19 @@ class Import::BitbucketServerController < Import::BaseController private + def bitbucket_client + @bitbucket_client ||= BitbucketServer::Client.new(credentials) + end + def validate_import_params @project_key = params[:project] @repo_slug = params[:repository] + status = :unprocessable_entity - return render json: { errors: 'Missing project key' } unless @project_key.present? && @repo_slug.present? - return render json: { errors: 'Missing repository slug' } unless @repo_slug.present? - return render json: { errors: 'Invalid project key' } unless @project_key =~ VALID_BITBUCKET_CHARS - return render json: { errors: 'Invalid repository slug' } unless @repo_slug =~ VALID_BITBUCKET_CHARS + return render json: { errors: 'Missing project key' }, status: status unless @project_key.present? && @repo_slug.present? + return render json: { errors: 'Missing repository slug' }, status: status unless @repo_slug.present? + return render json: { errors: 'Invalid project key' }, status: status unless @project_key =~ VALID_BITBUCKET_CHARS + return render json: { errors: 'Invalid repository slug' }, status: status unless @repo_slug =~ VALID_BITBUCKET_CHARS end def bitbucket_auth |