Commit e3bd1af7 authored by Illya Klymov's avatar Illya Klymov

Implement gitlab.com JSON status endpoint

This one reuses same serializers approach introduced in MR
parent b9380cdf
......@@ -90,7 +90,6 @@ class Import::FogbugzController < Import::BaseController
def importable_repos
repos = client.repos
already_added_projects = find_already_added_projects('fogbugz')
already_added_projects_names = already_added_projects.pluck(:import_source)
repos.reject { |repo| already_added_projects_names.include? repo.name }
......
# frozen_string_literal: true
class Import::GitlabController < Import::BaseController
extend ::Gitlab::Utils::Override
MAX_PROJECT_PAGES = 15
PER_PAGE_PROJECTS = 100
......@@ -16,6 +18,8 @@ class Import::GitlabController < Import::BaseController
# rubocop: disable CodeReuse/ActiveRecord
def status
return super if Feature.enabled?(:new_import_ui)
@repos = client.projects(starting_page: 1, page_limit: MAX_PROJECT_PAGES, per_page: PER_PAGE_PROJECTS)
@already_added_projects = find_already_added_projects('gitlab')
......@@ -37,7 +41,7 @@ class Import::GitlabController < Import::BaseController
project = Gitlab::GitlabImport::ProjectCreator.new(repo, target_namespace, current_user, access_params).execute
if project.persisted?
render json: ProjectSerializer.new.represent(project)
render json: ProjectSerializer.new.represent(project, serializer: :import)
else
render json: { errors: project_save_error(project) }, status: :unprocessable_entity
end
......@@ -46,6 +50,29 @@ class Import::GitlabController < Import::BaseController
end
end
protected
# rubocop: disable CodeReuse/ActiveRecord
override :importable_repos
def importable_repos
repos = client.projects(starting_page: 1, page_limit: MAX_PROJECT_PAGES, per_page: PER_PAGE_PROJECTS)
already_added_projects_names = already_added_projects.pluck(:import_source)
repos.reject { |repo| already_added_projects_names.include? repo["path_with_namespace"] }
end
# rubocop: enable CodeReuse/ActiveRecord
override :provider_name
def provider_name
:gitlab
end
override :provider_url
def provider_url
'https://gitlab.com'
end
private
def client
......
# frozen_string_literal: true
class Import::BitbucketProviderRepoEntity < Import::BaseProviderRepoEntity
include ImportHelper
expose :id, override: true do |repo|
repo.full_name
end
......
# frozen_string_literal: true
class Import::GitlabProviderRepoEntity < Import::BaseProviderRepoEntity
expose :id, override: true do |repo|
repo["id"]
end
expose :full_name, override: true do |repo|
repo["path_with_namespace"]
end
expose :sanitized_name, override: true do |repo|
repo["path"]
end
expose :provider_link, override: true do |repo|
repo["web_url"]
end
end
......@@ -12,6 +12,8 @@ class Import::ProviderRepoSerializer < BaseSerializer
Import::BitbucketProviderRepoEntity
when :bitbucket_server
Import::BitbucketServerProviderRepoEntity
when :gitlab
Import::GitlabProviderRepoEntity
else
raise NotImplementedError
end
......
......@@ -70,6 +70,7 @@ RSpec.describe Import::BitbucketController do
let(:repo_id) { @repo.full_name }
let(:import_source) { @repo.full_name }
let(:provider_name) { 'bitbucket' }
let(:client_repos_field) { :repos }
end
it "assigns variables" do
......
......@@ -153,6 +153,7 @@ RSpec.describe Import::BitbucketServerController do
let(:repo_id) { @repo.full_name }
let(:import_source) { @repo.browse_url }
let(:provider_name) { 'bitbucket_server' }
let(:client_repos_field) { :repos }
end
it 'assigns repository categories' do
......
......@@ -90,6 +90,7 @@ RSpec.describe Import::FogbugzController do
let(:repo_id) { @repo.id }
let(:import_source) { @repo.name }
let(:provider_name) { 'fogbugz' }
let(:client_repos_field) { :repos }
end
it 'assigns variables' do
......
......@@ -34,8 +34,17 @@ RSpec.describe Import::GitlabController do
describe "GET status" do
before do
@repo = OpenStruct.new(path: 'vim', path_with_namespace: 'asd/vim')
@repo = OpenStruct.new(id: 1, path: 'vim', path_with_namespace: 'asd/vim', web_url: 'https://gitlab.com/asd/vim')
assign_session_token
stub_feature_flags(new_import_ui: false)
end
it_behaves_like 'import controller with new_import_ui feature flag' do
let(:repo) { @repo }
let(:repo_id) { @repo.id }
let(:import_source) { @repo.path_with_namespace }
let(:provider_name) { 'gitlab' }
let(:client_repos_field) { :projects }
end
it "assigns variables" do
......
# frozen_string_literal: true
require 'spec_helper'
describe Import::GitlabProviderRepoEntity do
let(:repo_data) do
{
'id' => 1,
'path_with_namespace' => 'demo/test',
'path' => 'test',
'web_url' => 'https://gitlab.com/demo/test'
}
end
subject { described_class.new(repo_data).as_json }
it_behaves_like 'exposes required fields for import entity' do
let(:expected_values) do
{
id: 1,
full_name: 'demo/test',
sanitized_name: 'test',
provider_link: 'https://gitlab.com/demo/test'
}
end
end
end
......@@ -13,7 +13,7 @@ RSpec.shared_examples 'import controller with new_import_ui feature flag' do
it "returns variables for json request" do
project = create(:project, import_type: provider_name, creator_id: user.id)
stub_client(repos: [repo])
stub_client(client_repos_field => [repo])
get :status, format: :json
......@@ -25,7 +25,7 @@ RSpec.shared_examples 'import controller with new_import_ui feature flag' do
it "does not show already added project" do
project = create(:project, import_type: provider_name, namespace: user.namespace, import_status: :finished, import_source: import_source)
stub_client(repos: [repo], orgs: [])
stub_client(client_repos_field => [repo])
get :status, format: :json
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment