Commit 4aeb9f87 authored by Nick Thomas's avatar Nick Thomas

Merge branch '10395-require-code-owner-approval-on-pushes' into 'master'

EE->CE: Structure for "Require code owner approval on pushes"

See merge request gitlab-org/gitlab-ce!32607
parents 95ef2725 0e40b41e
......@@ -174,6 +174,7 @@ class MergeRequest < ApplicationRecord
scope :from_project, ->(project) { where(source_project_id: project.id) }
scope :merged, -> { with_state(:merged) }
scope :closed_and_merged, -> { with_states(:closed, :merged) }
scope :open_and_closed, -> { with_states(:opened, :closed) }
scope :from_source_branches, ->(branches) { where(source_branch: branches) }
scope :by_commit_sha, ->(sha) do
where('EXISTS (?)', MergeRequestDiff.select(1).where('merge_requests.latest_merge_request_diff_id = merge_request_diffs.id').by_commit_sha(sha)).reorder(nil)
......@@ -187,6 +188,11 @@ class MergeRequest < ApplicationRecord
target_project: [:route, { namespace: :route }],
source_project: [:route, { namespace: :route }])
}
scope :by_target_branch_wildcard, ->(wildcard_branch_name) do
where("target_branch LIKE ?", ApplicationRecord.sanitize_sql_like(wildcard_branch_name).tr('*', '%'))
end
scope :by_target_branch, ->(branch_name) { where(target_branch: branch_name) }
scope :preload_source_project, -> { preload(:source_project) }
after_save :keep_around_commit
......
......@@ -3,6 +3,9 @@
class ProtectedBranch < ApplicationRecord
include ProtectedRef
scope :requiring_code_owner_approval,
-> { where(code_owner_approval_required: true) }
protected_ref_access_levels :merge, :push
def self.protected_ref_accessible_to?(ref, user, project:, action:, protected_refs: nil)
......
......@@ -5,7 +5,8 @@ module ProtectedBranches
def execute(skip_authorization: false)
raise Gitlab::Access::AccessDeniedError unless skip_authorization || authorized?
protected_branch.save
save_protected_branch
protected_branch
end
......@@ -15,6 +16,10 @@ module ProtectedBranches
private
def save_protected_branch
protected_branch.save
end
def protected_branch
@protected_branch ||= project.protected_branches.new(params)
end
......
# frozen_string_literal: true
class AddMergeRequestsRequireCodeOwnerApprovalToProtectedBranches < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
disable_ddl_transaction!
def up
add_column_with_default(
:protected_branches,
:code_owner_approval_required,
:boolean,
default: false
)
add_concurrent_index(
:protected_branches,
[:project_id, :code_owner_approval_required],
name: "code_owner_approval_required",
where: "code_owner_approval_required = #{Gitlab::Database.true_value}")
end
def down
remove_concurrent_index(:protected_branches, name: "code_owner_approval_required")
remove_column(:protected_branches, :code_owner_approval_required)
end
end
......@@ -2932,6 +2932,8 @@ ActiveRecord::Schema.define(version: 2019_09_04_173203) do
t.string "name", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "code_owner_approval_required", default: false, null: false
t.index ["project_id", "code_owner_approval_required"], name: "code_owner_approval_required", where: "(code_owner_approval_required = true)"
t.index ["project_id"], name: "index_protected_branches_on_project_id"
end
......
......@@ -20,9 +20,8 @@ describe Gitlab::Checks::DiffCheck do
allow(project).to receive(:lfs_enabled?).and_return(false)
end
it 'skips the validation' do
expect(subject).not_to receive(:validate_diff)
expect(subject).not_to receive(:validate_file_paths)
it 'does not invoke :lfs_file_locks_validation' do
expect(subject).not_to receive(:lfs_file_locks_validation)
subject.validate!
end
......
......@@ -467,6 +467,7 @@ ProtectedBranch:
- name
- created_at
- updated_at
- code_owner_approval_required
ProtectedTag:
- id
- project_id
......
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