Commit 43189510 authored by Andrejs Cunskis's avatar Andrejs Cunskis

Add github project import via api

parent 0e588e91
......@@ -9,21 +9,22 @@ module QA
include Members
include Visibility
attr_accessor :repository_storage # requires admin access
attr_writer :initialize_with_readme,
:auto_devops_enabled,
:github_personal_access_token,
:github_repository_path
attribute :id
attribute :name
attribute :add_name_uuid
attribute :description
attribute :standalone
attribute :runners_token
attribute :visibility
attribute :template_name
attribute :import
attr_accessor :repository_storage, # requires admin access
:initialize_with_readme,
:auto_devops_enabled,
:github_personal_access_token,
:github_repository_path
attributes :id,
:name,
:add_name_uuid,
:description,
:standalone,
:runners_token,
:visibility,
:template_name,
:import,
:import_status
attribute :group do
Group.fabricate!
......
......@@ -5,6 +5,8 @@ require 'securerandom'
module QA
module Resource
class ProjectImportedFromGithub < Resource::Project
attribute :github_repo_id
def fabricate!
self.import = true
......@@ -16,10 +18,34 @@ module QA
end
Page::Project::Import::Github.perform do |import_page|
import_page.add_personal_access_token(@github_personal_access_token)
import_page.import!(@github_repository_path, @name)
import_page.add_personal_access_token(github_personal_access_token)
import_page.import!(github_repository_path, name)
end
end
def fabricate_via_api!
super
rescue ResourceURLMissingError
"#{Runtime::Scenario.gitlab_address}/#{group.full_path}/#{name}"
end
def api_post_path
'/import/github'
end
def api_post_body
{
repo_id: github_repo_id,
new_name: name,
target_namespace: group.full_path,
personal_access_token: github_personal_access_token,
ci_cd_only: false
}
end
def transform_api_resource(api_resource)
api_resource
end
end
end
end
# frozen_string_literal: true
module QA
RSpec.describe 'Manage', :github, :requires_admin do
describe 'Project import' do
let!(:api_client) { Runtime::API::Client.as_admin }
let!(:group) { Resource::Group.fabricate_via_api! { |resource| resource.api_client = api_client } }
let!(:user) do
Resource::User.fabricate_via_api! do |resource|
resource.api_client = api_client
resource.hard_delete_on_api_removal = true
end
end
let(:imported_project) do
Resource::ProjectImportedFromGithub.fabricate_via_api! do |project|
project.name = 'imported-project'
project.group = group
project.github_personal_access_token = Runtime::Env.github_access_token
project.github_repository_path = 'gitlab-qa-github/test-project'
project.api_client = api_client
project.github_repo_id = '310217317'
end
end
before do
group.add_member(user, Resource::Members::AccessLevel::MAINTAINER)
end
after do
user.remove_via_api!
end
it 'imports Github repo via api' do
imported_project.reload! # import the project and reload all fields
expect { imported_project.reload!.import_status }.to eventually_eq('finished').within(duration: 90)
end
end
end
end
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