Commit f941c8a3 authored by Tomislav Nikić's avatar Tomislav Nikić Committed by Mark Lapierre

Adding a new test for codeowners and mr

This test tests the ability to use a codeowner
file with the setting to squash commits and
merge into master.
parent daf1b272
---
name: gitaly_go_user_merge_branch
introduced_by_url:
rollout_issue_url:
milestone:
type: development
group:
default_enabled: false
...@@ -278,10 +278,10 @@ In line with [using the API](#prefer-api-over-ui), use a `Commit` resource whene ...@@ -278,10 +278,10 @@ In line with [using the API](#prefer-api-over-ui), use a `Commit` resource whene
```ruby ```ruby
# Using a commit resource # Using a commit resource
Resource::Commit.fabricate_via_api! do |commit| Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.commit_message = 'Initial commit' commit.commit_message = 'Initial commit'
commit.add_files([ commit.add_files([
{file_path: 'README.md', content: 'Hello, GitLab'} { file_path: 'README.md', content: 'Hello, GitLab' }
]) ])
end end
......
...@@ -58,7 +58,7 @@ module QA ...@@ -58,7 +58,7 @@ module QA
allowed[:roles] = Resource::ProtectedBranch::Roles::NO_ONE unless allowed.key?(:roles) allowed[:roles] = Resource::ProtectedBranch::Roles::NO_ONE unless allowed.key?(:roles)
within_element(:"allowed_to_#{action}_dropdown") do within_element(:"allowed_to_#{action}_dropdown") do
click_on allowed[:roles] click_on allowed[:roles][:description]
allowed[:users].each { |user| click_on user.username } if allowed.key?(:users) allowed[:users].each { |user| click_on user.username } if allowed.key?(:users)
allowed[:groups].each { |group| click_on group.name } if allowed.key?(:groups) allowed[:groups].each { |group| click_on group.name } if allowed.key?(:groups)
end end
......
...@@ -8,7 +8,6 @@ module QA ...@@ -8,7 +8,6 @@ module QA
attr_accessor :branch_name, attr_accessor :branch_name,
:allowed_to_push, :allowed_to_push,
:allowed_to_merge, :allowed_to_merge,
:protected,
:new_branch, :new_branch,
:require_code_owner_approval :require_code_owner_approval
...@@ -20,13 +19,14 @@ module QA ...@@ -20,13 +19,14 @@ module QA
end end
attribute :branch do attribute :branch do
Repository::ProjectPush.fabricate! do |project_push| Resource::Repository::Commit.fabricate_via_api! do |commit|
project_push.project = project commit.project = project
project_push.file_name = "new_file-#{SecureRandom.hex(8)}.md" commit.branch = branch_name
project_push.commit_message = 'Add new file' commit.start_branch = 'master'
project_push.branch_name = branch_name commit.commit_message = 'Add new file'
project_push.new_branch = true commit.add_files([
project_push.remote_branch = branch_name { file_path: "new_file-#{SecureRandom.hex(8)}.md", content: 'new file' }
])
end end
end end
...@@ -39,16 +39,11 @@ module QA ...@@ -39,16 +39,11 @@ module QA
@allowed_to_merge = { @allowed_to_merge = {
roles: Resource::ProtectedBranch::Roles::DEVS_AND_MAINTAINERS roles: Resource::ProtectedBranch::Roles::DEVS_AND_MAINTAINERS
} }
@protected = false @require_code_owner_approval = false
@require_code_owner_approval = true
end end
def fabricate! def fabricate!
if new_branch populate_new_branch_if_required
populate(:branch)
project.wait_for_push_new_branch branch_name
end
project.visit! project.visit!
Page::Project::Menu.perform(&:go_to_repository_settings) Page::Project::Menu.perform(&:go_to_repository_settings)
...@@ -67,6 +62,12 @@ module QA ...@@ -67,6 +62,12 @@ module QA
end end
end end
def fabricate_via_api!
populate_new_branch_if_required
super
end
def self.unprotect_via_api!(&block) def self.unprotect_via_api!(&block)
self.remove_via_api!(&block) self.remove_via_api!(&block)
end end
...@@ -79,10 +80,49 @@ module QA ...@@ -79,10 +80,49 @@ module QA
"/projects/#{project.id}/protected_branches/#{branch_name}" "/projects/#{project.id}/protected_branches/#{branch_name}"
end end
def api_post_path
"/projects/#{project.id}/protected_branches"
end
def api_post_body
{
name: branch_name,
code_owner_approval_required: require_code_owner_approval
}
.merge(allowed_to_push_hash)
.merge(allowed_to_merge_hash)
end
def allowed_to_push_hash
allowed = {}
allowed.merge({ push_access_level: allowed_to_push[:roles][:access_level] }) if allowed_to_push.key?(:roles)
end
def allowed_to_merge_hash
allowed = {}
allowed.merge({ merge_access_level: allowed_to_merge[:roles][:access_level] }) if allowed_to_merge.key?(:roles)
end
def resource_web_url(resource)
super
rescue ResourceURLMissingError
# this particular resource does not expose a web_url property
end
class Roles class Roles
NO_ONE = 'No one' NO_ONE = { description: 'No one', access_level: 0 }.freeze
DEVS_AND_MAINTAINERS = 'Developers + Maintainers' DEVS_AND_MAINTAINERS = { description: 'Developers + Maintainers', access_level: 30 }.freeze
MAINTAINERS = 'Maintainers' MAINTAINERS = { description: 'Maintainers', access_level: 40 }.freeze
end
private
def populate_new_branch_if_required
return unless new_branch
populate(:branch)
project.wait_for_push_new_branch(branch_name)
end end
end end
end end
......
...@@ -9,7 +9,8 @@ module QA ...@@ -9,7 +9,8 @@ module QA
:branch, :branch,
:commit_message, :commit_message,
:file_path, :file_path,
:sha :sha,
:start_branch
attribute :short_id attribute :short_id
...@@ -85,7 +86,7 @@ module QA ...@@ -85,7 +86,7 @@ module QA
author_name: @author_name || Runtime::User.username, author_name: @author_name || Runtime::User.username,
commit_message: commit_message, commit_message: commit_message,
actions: actions actions: actions
} }.merge(new_branch)
end end
def actions def actions
...@@ -104,6 +105,14 @@ module QA ...@@ -104,6 +105,14 @@ module QA
raise ArgumentError, "Please provide an array of hashes e.g.: [{file_path: 'file1', content: 'foo'}]" raise ArgumentError, "Please provide an array of hashes e.g.: [{file_path: 'file1', content: 'foo'}]"
end end
end end
def new_branch
return {} unless start_branch
{
start_branch: start_branch
}
end
end end
end end
end end
......
...@@ -40,7 +40,7 @@ module QA ...@@ -40,7 +40,7 @@ module QA
end end
def create_protected_branch(allowed_to_push:) def create_protected_branch(allowed_to_push:)
Resource::ProtectedBranch.fabricate! do |resource| Resource::ProtectedBranch.fabricate_via_api! do |resource|
resource.branch_name = branch_name resource.branch_name = branch_name
resource.project = project resource.project = project
resource.allowed_to_push = allowed_to_push resource.allowed_to_push = allowed_to_push
......
...@@ -43,9 +43,10 @@ module QA ...@@ -43,9 +43,10 @@ module QA
end end
# Create a projected branch that requires approval from code owners # Create a projected branch that requires approval from code owners
Resource::ProtectedBranch.fabricate! do |protected_branch| Resource::ProtectedBranch.fabricate_via_browser_ui! do |protected_branch|
protected_branch.branch_name = branch_name protected_branch.branch_name = branch_name
protected_branch.project = project protected_branch.project = project
protected_branch.require_code_owner_approval = true
end end
# Push a new CODEOWNERS file # Push a new CODEOWNERS file
......
# frozen_string_literal: true
module QA
RSpec.describe 'Create', :requires_admin do
describe 'Setup an MR with codeowners file' do
let(:project) do
Resource::Project.fabricate_via_api!
end
let!(:target) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.branch = 'master'
commit.add_files([
{ file_path: '.gitlab/CODEOWNERS', content: '* @root' }
])
end
end
let!(:source) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.branch = 'codeowners_test'
commit.start_branch = 'master'
commit.add_files([
{ file_path: 'test1.txt', content: '1' }
])
end
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.branch = 'codeowners_test'
commit.add_files([
{ file_path: 'test2.txt', content: '2' }
])
end
end
before do
Runtime::Feature.enable(:gitaly_go_user_merge_branch)
Flow::Login.sign_in
end
after do
Runtime::Feature.disable(:gitaly_go_user_merge_branch)
end
it 'creates a merge request with codeowners file and squashing commits enabled', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1090' do
# The default branch is already protected, and we can't update a protected branch via the API (yet)
# so we unprotect it first and then protect it again with the desired parameters
Resource::ProtectedBranch.unprotect_via_api! do |branch|
branch.project = project
branch.branch_name = 'master'
end
Resource::ProtectedBranch.fabricate_via_api! do |branch|
branch.project = project
branch.new_branch = false
branch.branch_name = 'master'
branch.allowed_to_push = { roles: Resource::ProtectedBranch::Roles::NO_ONE }
branch.allowed_to_merge = { roles: Resource::ProtectedBranch::Roles::MAINTAINERS }
branch.require_code_owner_approval = true
end
Resource::MergeRequest.fabricate_via_api! do |mr|
mr.no_preparation = true
mr.project = project
mr.source_branch = source.branch
mr.target_branch = target.branch
mr.title = 'merging two commits'
end.visit!
Page::MergeRequest::Show.perform do |mr|
mr.mark_to_squash
mr.merge!
expect(mr).to be_merged
end
end
end
end
end
...@@ -47,7 +47,7 @@ module QA ...@@ -47,7 +47,7 @@ module QA
login login
Resource::ProtectedBranch.fabricate! do |protected_branch| Resource::ProtectedBranch.fabricate_via_browser_ui! do |protected_branch|
protected_branch.branch_name = branch_name protected_branch.branch_name = branch_name
protected_branch.project = project protected_branch.project = project
protected_branch.allowed_to_merge = { protected_branch.allowed_to_merge = {
...@@ -84,7 +84,7 @@ module QA ...@@ -84,7 +84,7 @@ module QA
project.add_member(user_maintainer, Resource::Members::AccessLevel::MAINTAINER) project.add_member(user_maintainer, Resource::Members::AccessLevel::MAINTAINER)
Resource::ProtectedBranch.fabricate! do |protected_branch| Resource::ProtectedBranch.fabricate_via_browser_ui! do |protected_branch|
protected_branch.branch_name = branch_name protected_branch.branch_name = branch_name
protected_branch.project = project protected_branch.project = project
protected_branch.allowed_to_merge = { protected_branch.allowed_to_merge = {
......
...@@ -31,7 +31,14 @@ module QA ...@@ -31,7 +31,14 @@ module QA
end end
# Require approval from code owners on master # Require approval from code owners on master
Resource::ProtectedBranch.fabricate! do |protected_branch| # The default branch is already protected, and we can't update a protected branch via the API (yet)
# so we unprotect it first and then protect it again with the desired parameters
Resource::ProtectedBranch.unprotect_via_api! do |protected_branch|
protected_branch.project = project
protected_branch.branch_name = 'master'
end
Resource::ProtectedBranch.fabricate_via_api! do |protected_branch|
protected_branch.project = project protected_branch.project = project
protected_branch.branch_name = 'master' protected_branch.branch_name = 'master'
protected_branch.new_branch = false protected_branch.new_branch = false
......
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