Skip to content
Snippets Groups Projects
Commit be041934 authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Rename Project's auto-protected columns to start with 'auto_'


Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 6204a63a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -234,7 +234,7 @@ class ProjectsController < Projects::ApplicationController
:issues_tracker_id, :default_branch,
:wiki_enabled, :visibility_level, :import_url, :last_activity_at, :namespace_id, :avatar,
:builds_enabled, :build_allow_git_fetch, :build_timeout_in_minutes, :build_coverage_regex,
:public_builds, :protected_branch_pattern, :developers_can_push_protected_branch
:public_builds, :auto_protected_branch_pattern, :developers_can_push_to_auto_protected_branch
)
end
 
Loading
Loading
Loading
Loading
@@ -160,7 +160,7 @@ class Project < ActiveRecord::Base
validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
validate :visibility_level_allowed_by_group
validate :visibility_level_allowed_as_fork
validates :protected_branch_pattern, regexp: true, allow_blank: true
validates :auto_protected_branch_pattern, regexp: true, allow_blank: true
validates :build_coverage_regex, regexp: true, allow_blank: true
 
add_authentication_token_field :runners_token
Loading
Loading
Loading
Loading
@@ -169,7 +169,7 @@ class GitPushService < BaseService
end
 
def create_protected_branch!
pattern = @project.protected_branch_pattern
pattern = @project.auto_protected_branch_pattern
 
return unless pattern.present? && branch_name =~ Regexp.new(pattern)
return if @project.protected_branches.exists?(name: branch_name)
Loading
Loading
class AddAutoProtectedBranchPatternToProject < ActiveRecord::Migration
def change
add_column :projects, :auto_protected_branch_pattern, :string
end
end
class AddProtectedBranchPatternToProject < ActiveRecord::Migration
def change
add_column :projects, :protected_branch_pattern, :string
end
end
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
 
class AddDevelopersCanPushProtectedBranchToProject < ActiveRecord::Migration
class AddDevelopersCanPushToAutoProtectedBranchToProject < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
 
def up
add_column_with_default(:projects, :developers_can_push_protected_branch, :boolean,
default: false, allow_null: false)
add_column_with_default(:projects,
:developers_can_push_to_auto_protected_branch,
:boolean,
default: false,
allow_null: false)
end
 
def down
remove_column(:projects, :developers_can_push_protected_branch)
remove_column(:projects, :developers_can_push_to_auto_protected_branch)
end
end
Loading
Loading
@@ -64,20 +64,20 @@ describe Project, models: true do
end
 
it 'does not allow protected branch pattern if it is not a valid regex' do
project.protected_branch_pattern = "[0-9"
project.auto_protected_branch_pattern = "[0-9"
 
expect(project).not_to be_valid
expect(project.errors[:protected_branch_pattern].first).to match(/'\[0-9' is not a valid regular expression: .+/)
expect(project.errors[:auto_protected_branch_pattern].first).to match(/'\[0-9' is not a valid regular expression: .+/)
end
 
it 'allows nil protected_branch_pattern' do
project.protected_branch_pattern = nil
it 'allows nil auto_protected_branch_pattern' do
project.auto_protected_branch_pattern = nil
 
expect(project).to be_valid
end
 
it 'allows "" protected_branch_pattern' do
project.protected_branch_pattern = ''
it 'allows "" auto_protected_branch_pattern' do
project.auto_protected_branch_pattern = ''
 
expect(project).to be_valid
end
Loading
Loading
Loading
Loading
@@ -4,28 +4,28 @@ describe RegexpValidator do
let(:project) { build(:project) }
 
it 'does not add an error if attribute is nil' do
validate_regexp(project, :protected_branch_pattern, nil)
validate_regexp(project, :auto_protected_branch_pattern, nil)
 
expect(project.errors[:protected_branch_pattern]).to be_empty
expect(project.errors[:auto_protected_branch_pattern]).to be_empty
end
 
it 'does not add an error if attribute is ""' do
validate_regexp(project, :protected_branch_pattern, '')
validate_regexp(project, :auto_protected_branch_pattern, '')
 
expect(project.errors[:protected_branch_pattern]).to be_empty
expect(project.errors[:auto_protected_branch_pattern]).to be_empty
end
 
it 'does not add an error if attribute is a valid regex' do
validate_regexp(project, :protected_branch_pattern, '[0-9]')
validate_regexp(project, :auto_protected_branch_pattern, '[0-9]')
 
expect(project.errors[:protected_branch_pattern]).to be_empty
expect(project.errors[:auto_protected_branch_pattern]).to be_empty
end
 
it 'adds an error if attribute is not a valid regex' do
validate_regexp(project, :protected_branch_pattern, '[0-9')
validate_regexp(project, :auto_protected_branch_pattern, '[0-9')
 
expect(project.errors[:protected_branch_pattern].size).to eq(1)
expect(project.errors[:protected_branch_pattern].first).to eq("'[0-9' is not a valid regular expression: premature end of char-class: /[0-9/")
expect(project.errors[:auto_protected_branch_pattern].size).to eq(1)
expect(project.errors[:auto_protected_branch_pattern].first).to eq("'[0-9' is not a valid regular expression: premature end of char-class: /[0-9/")
end
 
def validate_regexp(record, attribute, value)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment