Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKerri Miller <kerrizor@kerrizor.com>2019-09-05 16:01:36 +0300
committerNick Thomas <nick@gitlab.com>2019-09-05 16:01:36 +0300
commit0e40b41e224f18076426578da08548ae22afdcd1 (patch)
tree3bf58eb8e415771f28270910a66672b4d9db87b9 /app
parent95ef27253909ba7ff30667af14f7ea2256c1ae8d (diff)
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.
Diffstat (limited to 'app')
-rw-r--r--app/models/merge_request.rb6
-rw-r--r--app/models/protected_branch.rb3
-rw-r--r--app/services/protected_branches/create_service.rb7
3 files changed, 15 insertions, 1 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 28e450f9b30..bc98ae0ce28 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -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
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb
index ee0c94c20af..9fd929371f8 100644
--- a/app/models/protected_branch.rb
+++ b/app/models/protected_branch.rb
@@ -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)
diff --git a/app/services/protected_branches/create_service.rb b/app/services/protected_branches/create_service.rb
index 87aaf4672a4..6b2836bba39 100644
--- a/app/services/protected_branches/create_service.rb
+++ b/app/services/protected_branches/create_service.rb
@@ -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