Commit 0e40b41e authored by Kerri Miller's avatar Kerri Miller Committed by Nick Thomas

Add structure to support EE feature of COAR

These are the structural changes for supporting the EE feature of moving
"code_owner_approval_required" state from existing on a project to being
on the protected branches individually, allowing for CODEOWNER
validation on push events.
parent 95ef2725
...@@ -174,6 +174,7 @@ class MergeRequest < ApplicationRecord ...@@ -174,6 +174,7 @@ class MergeRequest < ApplicationRecord
scope :from_project, ->(project) { where(source_project_id: project.id) } scope :from_project, ->(project) { where(source_project_id: project.id) }
scope :merged, -> { with_state(:merged) } scope :merged, -> { with_state(:merged) }
scope :closed_and_merged, -> { with_states(:closed, :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 :from_source_branches, ->(branches) { where(source_branch: branches) }
scope :by_commit_sha, ->(sha) do 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) 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 ...@@ -187,6 +188,11 @@ class MergeRequest < ApplicationRecord
target_project: [:route, { namespace: :route }], target_project: [:route, { namespace: :route }],
source_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 after_save :keep_around_commit
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
class ProtectedBranch < ApplicationRecord class ProtectedBranch < ApplicationRecord
include ProtectedRef include ProtectedRef
scope :requiring_code_owner_approval,
-> { where(code_owner_approval_required: true) }
protected_ref_access_levels :merge, :push protected_ref_access_levels :merge, :push
def self.protected_ref_accessible_to?(ref, user, project:, action:, protected_refs: nil) def self.protected_ref_accessible_to?(ref, user, project:, action:, protected_refs: nil)
......
...@@ -5,7 +5,8 @@ module ProtectedBranches ...@@ -5,7 +5,8 @@ module ProtectedBranches
def execute(skip_authorization: false) def execute(skip_authorization: false)
raise Gitlab::Access::AccessDeniedError unless skip_authorization || authorized? raise Gitlab::Access::AccessDeniedError unless skip_authorization || authorized?
protected_branch.save save_protected_branch
protected_branch protected_branch
end end
...@@ -15,6 +16,10 @@ module ProtectedBranches ...@@ -15,6 +16,10 @@ module ProtectedBranches
private private
def save_protected_branch
protected_branch.save
end
def protected_branch def protected_branch
@protected_branch ||= project.protected_branches.new(params) @protected_branch ||= project.protected_branches.new(params)
end 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 ...@@ -2932,6 +2932,8 @@ ActiveRecord::Schema.define(version: 2019_09_04_173203) do
t.string "name", null: false t.string "name", null: false
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_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" t.index ["project_id"], name: "index_protected_branches_on_project_id"
end end
......
...@@ -20,9 +20,8 @@ describe Gitlab::Checks::DiffCheck do ...@@ -20,9 +20,8 @@ describe Gitlab::Checks::DiffCheck do
allow(project).to receive(:lfs_enabled?).and_return(false) allow(project).to receive(:lfs_enabled?).and_return(false)
end end
it 'skips the validation' do it 'does not invoke :lfs_file_locks_validation' do
expect(subject).not_to receive(:validate_diff) expect(subject).not_to receive(:lfs_file_locks_validation)
expect(subject).not_to receive(:validate_file_paths)
subject.validate! subject.validate!
end end
......
...@@ -467,6 +467,7 @@ ProtectedBranch: ...@@ -467,6 +467,7 @@ ProtectedBranch:
- name - name
- created_at - created_at
- updated_at - updated_at
- code_owner_approval_required
ProtectedTag: ProtectedTag:
- id - id
- project_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