Class: Import::BitbucketServerService

Inherits:
BaseService show all
Defined in:
app/services/import/bitbucket_server_service.rb

Instance Attribute Summary collapse

Attributes inherited from BaseService

#project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from Import::BaseService

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


5
6
7
# File 'app/services/import/bitbucket_server_service.rb', line 5

def client
  @client
end

#current_userObject (readonly)

Returns the value of attribute current_user


5
6
7
# File 'app/services/import/bitbucket_server_service.rb', line 5

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params


5
6
7
# File 'app/services/import/bitbucket_server_service.rb', line 5

def params
  @params
end

Instance Method Details

#execute(credentials) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/import/bitbucket_server_service.rb', line 7

def execute(credentials)
  if blocked_url?
    return log_and_return_error("Invalid URL: #{url}", :bad_request)
  end

  unless authorized?
    return log_and_return_error("You don't have permissions to create this project", :unauthorized)
  end

  unless repo
    return log_and_return_error("Project %{project_repo} could not be found" % { project_repo: "#{project_key}/#{repo_slug}" }, :unprocessable_entity)
  end

  project = create_project(credentials)

  if project.persisted?
    success(project)
  else
    log_and_return_error(project_save_error(project), :unprocessable_entity)
  end
rescue BitbucketServer::Connection::ConnectionError => e
  log_and_return_error("Import failed due to a BitBucket Server error: #{e}", :bad_request)
end