Commit b6ccfed0 authored by Andrejs Cunskis's avatar Andrejs Cunskis

Merge branch 'ml-update-protected-branch-code-owner-approval-test' into 'master'

Update protected branch to set code owner approval

See merge request gitlab-org/gitlab!78514
parents 5a5cc407 2560d75c
...@@ -61,6 +61,8 @@ module QA ...@@ -61,6 +61,8 @@ module QA
end end
def fabricate_via_api! def fabricate_via_api!
resource_web_url(api_get)
rescue ResourceNotFoundError
populate_new_branch_if_required populate_new_branch_if_required
super super
...@@ -75,7 +77,11 @@ module QA ...@@ -75,7 +77,11 @@ module QA
end end
def api_delete_path def api_delete_path
"/projects/#{project.id}/protected_branches/#{branch_name}" api_get_path
end
def api_put_path
api_get_path
end end
def api_post_path def api_post_path
...@@ -107,6 +113,16 @@ module QA ...@@ -107,6 +113,16 @@ module QA
# this particular resource does not expose a web_url property # this particular resource does not expose a web_url property
end end
def set_require_code_owner_approval(require = true)
response = patch(Runtime::API::Request.new(api_client, api_put_path).url, { code_owner_approval_required: require })
return if response.code == HTTP_STATUS_OK
raise(
ResourceUpdateFailedError,
"Could not update code_owner_approval_required to #{require}. Request returned (#{response.code}): `#{response}`."
)
end
class Roles class Roles
NO_ONE = { description: 'No one', access_level: 0 }.freeze NO_ONE = { description: 'No one', access_level: 0 }.freeze
DEVS_AND_MAINTAINERS = { description: 'Developers + Maintainers', access_level: 30 }.freeze DEVS_AND_MAINTAINERS = { description: 'Developers + Maintainers', access_level: 30 }.freeze
......
...@@ -44,6 +44,18 @@ module QA ...@@ -44,6 +44,18 @@ module QA
end end
end end
def patch(url, payload = nil)
with_retry_on_too_many_requests do
RestClient::Request.execute(
method: :patch,
url: url,
payload: payload,
verify_ssl: false)
rescue RestClient::ExceptionWithResponse => e
return_response_or_raise(e)
end
end
def put(url, payload = nil) def put(url, payload = nil)
with_retry_on_too_many_requests do with_retry_on_too_many_requests do
RestClient::Request.execute( RestClient::Request.execute(
......
...@@ -31,19 +31,13 @@ module QA ...@@ -31,19 +31,13 @@ module QA
end end
# Require approval from code owners on the default branch # Require approval from code owners on the default branch
# The default branch is already protected, and we can't update a protected branch via the API (yet) protected_branch = Resource::ProtectedBranch.fabricate_via_api! do |branch|
# so we unprotect it first and then protect it again with the desired parameters branch.project = project
Resource::ProtectedBranch.unprotect_via_api! do |protected_branch| branch.branch_name = project.default_branch
protected_branch.project = project branch.new_branch = false
protected_branch.branch_name = project.default_branch branch.require_code_owner_approval = true
end
Resource::ProtectedBranch.fabricate_via_api! do |protected_branch|
protected_branch.project = project
protected_branch.branch_name = project.default_branch
protected_branch.new_branch = false
protected_branch.require_code_owner_approval = true
end end
protected_branch.set_require_code_owner_approval
# Push a change to the file with a CODEOWNERS rule # Push a change to the file with a CODEOWNERS rule
Resource::Repository::Push.fabricate! do |push| Resource::Repository::Push.fabricate! do |push|
......
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