summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/github_import
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /spec/lib/gitlab/github_import
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
downloadgitlab-ce-1f5bd14001245a518cecb87d251dddcde78b9bfb.tar.gz
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'spec/lib/gitlab/github_import')
-rw-r--r--spec/lib/gitlab/github_import/bulk_importing_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/client_spec.rb42
-rw-r--r--spec/lib/gitlab/github_import/importer/labels_importer_spec.rb3
-rw-r--r--spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb103
-rw-r--r--spec/lib/gitlab/github_import/importer/releases_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/page_counter_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/representation/protected_branch_spec.rb25
8 files changed, 166 insertions, 15 deletions
diff --git a/spec/lib/gitlab/github_import/bulk_importing_spec.rb b/spec/lib/gitlab/github_import/bulk_importing_spec.rb
index af31cb6c873..136ddb566aa 100644
--- a/spec/lib/gitlab/github_import/bulk_importing_spec.rb
+++ b/spec/lib/gitlab/github_import/bulk_importing_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::GithubImport::BulkImporting, feature_category: :importer do
+RSpec.describe Gitlab::GithubImport::BulkImporting, feature_category: :importers do
let(:project) { instance_double(Project, id: 1) }
let(:importer) { MyImporter.new(project, double) }
let(:importer_class) do
diff --git a/spec/lib/gitlab/github_import/client_spec.rb b/spec/lib/gitlab/github_import/client_spec.rb
index 526a8721ff3..d69bc4d60ee 100644
--- a/spec/lib/gitlab/github_import/client_spec.rb
+++ b/spec/lib/gitlab/github_import/client_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::GithubImport::Client do
+RSpec.describe Gitlab::GithubImport::Client, feature_category: :importer do
subject(:client) { described_class.new('foo', parallel: parallel) }
let(:parallel) { true }
@@ -614,6 +614,46 @@ RSpec.describe Gitlab::GithubImport::Client do
client.search_repos_by_name_graphql('test')
end
+ context 'when relation type option present' do
+ context 'when relation type is owned' do
+ let(:expected_query) { 'test in:name is:public,private user:user' }
+
+ it 'searches for repositories within the organization based on name' do
+ expect(client.octokit).to receive(:post).with(
+ '/graphql', { query: expected_graphql }.to_json
+ )
+
+ client.search_repos_by_name_graphql('test', relation_type: 'owned')
+ end
+ end
+
+ context 'when relation type is organization' do
+ let(:expected_query) { 'test in:name is:public,private org:test-login' }
+
+ it 'searches for repositories within the organization based on name' do
+ expect(client.octokit).to receive(:post).with(
+ '/graphql', { query: expected_graphql }.to_json
+ )
+
+ client.search_repos_by_name_graphql(
+ 'test', relation_type: 'organization', organization_login: 'test-login'
+ )
+ end
+ end
+
+ context 'when relation type is collaborated' do
+ let(:expected_query) { 'test in:name is:public,private repo:repo1 repo:repo2' }
+
+ it 'searches for collaborated repositories based on name' do
+ expect(client.octokit).to receive(:post).with(
+ '/graphql', { query: expected_graphql }.to_json
+ )
+
+ client.search_repos_by_name_graphql('test', relation_type: 'collaborated')
+ end
+ end
+ end
+
context 'when pagination options present' do
context 'with "first" option' do
let(:expected_graphql_params) do
diff --git a/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb b/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb
index ad9ef4afddd..9e295ab215a 100644
--- a/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb
@@ -2,7 +2,8 @@
require 'spec_helper'
-RSpec.describe Gitlab::GithubImport::Importer::LabelsImporter, :clean_gitlab_redis_cache, feature_category: :importer do
+RSpec.describe Gitlab::GithubImport::Importer::LabelsImporter, :clean_gitlab_redis_cache,
+feature_category: :importers do
let(:project) { create(:project, import_source: 'foo/bar') }
let(:client) { double(:client) }
let(:importer) { described_class.new(project, client) }
diff --git a/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb b/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb
index 8667729d79b..47b9a41c364 100644
--- a/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Importer::MilestonesImporter, :clean_gitlab_redis_cache,
- feature_category: :importer do
+ feature_category: :importers do
let(:project) { create(:project, import_source: 'foo/bar') }
let(:client) { double(:client) }
let(:importer) { described_class.new(project, client) }
diff --git a/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb b/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb
index d6b7411e640..d999bb3a3a3 100644
--- a/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb
@@ -15,6 +15,9 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
let(:expected_merge_access_level) { Gitlab::Access::MAINTAINER }
let(:expected_allow_force_push) { false }
let(:expected_code_owner_approval_required) { false }
+ let(:allowed_to_push_users) { [] }
+ let(:push_access_levels_number) { 1 }
+ let(:push_access_levels_attributes) { [{ access_level: expected_push_access_level }] }
let(:github_protected_branch) do
Gitlab::GithubImport::Representation::ProtectedBranch.new(
id: branch_name,
@@ -22,7 +25,8 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
required_conversation_resolution: required_conversation_resolution,
required_signatures: required_signatures,
required_pull_request_reviews: required_pull_request_reviews,
- require_code_owner_reviews: require_code_owner_reviews_on_github
+ require_code_owner_reviews: require_code_owner_reviews_on_github,
+ allowed_to_push_users: allowed_to_push_users
)
end
@@ -36,7 +40,7 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
let(:expected_ruleset) do
{
name: 'protection',
- push_access_levels_attributes: [{ access_level: expected_push_access_level }],
+ push_access_levels_attributes: push_access_levels_attributes,
merge_access_levels_attributes: [{ access_level: expected_merge_access_level }],
allow_force_push: expected_allow_force_push,
code_owner_approval_required: expected_code_owner_approval_required
@@ -56,7 +60,7 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
it 'creates protected branch and access levels for given github rule' do
expect { importer.execute }.to change(ProtectedBranch, :count).by(1)
- .and change(ProtectedBranch::PushAccessLevel, :count).by(1)
+ .and change(ProtectedBranch::PushAccessLevel, :count).by(push_access_levels_number)
.and change(ProtectedBranch::MergeAccessLevel, :count).by(1)
end
end
@@ -220,10 +224,97 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
context 'when required_pull_request_reviews rule is enabled on GitHub' do
let(:required_pull_request_reviews) { true }
- let(:expected_push_access_level) { Gitlab::Access::NO_ACCESS }
- let(:expected_merge_access_level) { Gitlab::Access::MAINTAINER }
- it_behaves_like 'create branch protection by the strictest ruleset'
+ context 'when no user is allowed to bypass push restrictions' do
+ let(:expected_push_access_level) { Gitlab::Access::NO_ACCESS }
+ let(:expected_merge_access_level) { Gitlab::Access::MAINTAINER }
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+
+ context 'when there are users who are allowed to bypass push restrictions' do
+ let(:owner_id) { project.owner.id }
+ let(:owner_username) { project.owner.username }
+ let(:other_user) { create(:user) }
+ let(:other_user_id) { other_user.id }
+ let(:other_user_username) { other_user.username }
+ let(:allowed_to_push_users) do
+ [
+ { id: owner_id, login: owner_username },
+ { id: other_user_id, login: other_user_username }
+ ]
+ end
+
+ context 'when the protected_refs_for_users feature is available', if: Gitlab.ee? do
+ let(:expected_merge_access_level) { Gitlab::Access::MAINTAINER }
+
+ before do
+ stub_licensed_features(protected_refs_for_users: true)
+ end
+
+ context 'when the users are found on GitLab' do
+ let(:push_access_levels_number) { 2 }
+ let(:push_access_levels_attributes) do
+ [
+ { user_id: owner_id },
+ { user_id: other_user_id }
+ ]
+ end
+
+ before do
+ project.add_member(other_user, :maintainer)
+ allow_next_instance_of(Gitlab::GithubImport::UserFinder) do |finder|
+ allow(finder).to receive(:find).with(owner_id, owner_username).and_return(owner_id)
+ allow(finder).to receive(:find).with(other_user_id, other_user_username).and_return(other_user_id)
+ end
+ end
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+
+ context 'when one of found users is not a member of the imported project' do
+ let(:push_access_levels_number) { 1 }
+ let(:push_access_levels_attributes) do
+ [
+ { user_id: owner_id }
+ ]
+ end
+
+ before do
+ allow_next_instance_of(Gitlab::GithubImport::UserFinder) do |finder|
+ allow(finder).to receive(:find).with(owner_id, owner_username).and_return(owner_id)
+ allow(finder).to receive(:find).with(other_user_id, other_user_username).and_return(other_user_id)
+ end
+ end
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+
+ context 'when the user are not found on GitLab' do
+ before do
+ allow_next_instance_of(Gitlab::GithubImport::UserFinder) do |finder|
+ allow(finder).to receive(:find).and_return(nil)
+ end
+ end
+
+ let(:expected_push_access_level) { Gitlab::Access::NO_ACCESS }
+ let(:expected_merge_access_level) { Gitlab::Access::MAINTAINER }
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+ end
+
+ context 'when the protected_refs_for_users feature is not available' do
+ before do
+ stub_licensed_features(protected_refs_for_users: false)
+ end
+
+ let(:expected_push_access_level) { Gitlab::Access::NO_ACCESS }
+ let(:expected_merge_access_level) { Gitlab::Access::MAINTAINER }
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+ end
end
context 'when required_pull_request_reviews rule is disabled on GitHub' do
diff --git a/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb b/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb
index ccbe5b5fc50..fe4d3e9d90b 100644
--- a/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter, feature_category: :importer do
+RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter, feature_category: :importers do
let(:project) { create(:project) }
let(:client) { double(:client) }
let(:importer) { described_class.new(project, client) }
diff --git a/spec/lib/gitlab/github_import/page_counter_spec.rb b/spec/lib/gitlab/github_import/page_counter_spec.rb
index 511b19c00e5..ddb62cc8fad 100644
--- a/spec/lib/gitlab/github_import/page_counter_spec.rb
+++ b/spec/lib/gitlab/github_import/page_counter_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::GithubImport::PageCounter, :clean_gitlab_redis_cache, feature_category: :importer do
+RSpec.describe Gitlab::GithubImport::PageCounter, :clean_gitlab_redis_cache, feature_category: :importers do
let(:project) { double(:project, id: 1) }
let(:counter) { described_class.new(project, :issues) }
diff --git a/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb b/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb
index 60cae79459e..e57ea31d1d2 100644
--- a/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb
+++ b/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb
@@ -28,6 +28,14 @@ RSpec.describe Gitlab::GithubImport::Representation::ProtectedBranch do
it 'includes the protected branch require_code_owner_reviews' do
expect(protected_branch.require_code_owner_reviews).to eq true
end
+
+ it 'includes the protected branch allowed_to_push_users' do
+ expect(protected_branch.allowed_to_push_users[0])
+ .to be_an_instance_of(Gitlab::GithubImport::Representation::User)
+
+ expect(protected_branch.allowed_to_push_users[0].id).to eq(4)
+ expect(protected_branch.allowed_to_push_users[0].login).to eq('alice')
+ end
end
end
@@ -40,7 +48,7 @@ RSpec.describe Gitlab::GithubImport::Representation::ProtectedBranch do
)
enabled_setting = Struct.new(:enabled, keyword_init: true)
required_pull_request_reviews = Struct.new(
- :url, :dismissal_restrictions, :require_code_owner_reviews,
+ :url, :dismissal_restrictions, :require_code_owner_reviews, :bypass_pull_request_allowances,
keyword_init: true
)
response.new(
@@ -57,7 +65,17 @@ RSpec.describe Gitlab::GithubImport::Representation::ProtectedBranch do
required_pull_request_reviews: required_pull_request_reviews.new(
url: 'https://example.com/branches/main/protection/required_pull_request_reviews',
dismissal_restrictions: {},
- require_code_owner_reviews: true
+ require_code_owner_reviews: true,
+ bypass_pull_request_allowances: {
+ users: [
+ {
+ login: 'alice',
+ id: 4,
+ url: 'https://api.github.com/users/cervols',
+ type: 'User'
+ }
+ ]
+ }
)
)
end
@@ -76,7 +94,8 @@ RSpec.describe Gitlab::GithubImport::Representation::ProtectedBranch do
'required_conversation_resolution' => true,
'required_signatures' => true,
'required_pull_request_reviews' => true,
- 'require_code_owner_reviews' => true
+ 'require_code_owner_reviews' => true,
+ 'allowed_to_push_users' => [{ 'id' => 4, 'login' => 'alice' }]
}
end