Commit 1024718e authored by Shinya Maeda's avatar Shinya Maeda

Refactor access_level to not_protected and ref_protected

parent 38759832
...@@ -34,7 +34,7 @@ module Ci ...@@ -34,7 +34,7 @@ module Ci
scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) } scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) }
scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) } scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
scope :manual_actions, ->() { where(when: :manual, status: COMPLETED_STATUSES + [:manual]) } scope :manual_actions, ->() { where(when: :manual, status: COMPLETED_STATUSES + [:manual]) }
scope :protected_, -> { where(protected: true) } scope :ref_protected, -> { where(protected: true) }
mount_uploader :artifacts_file, ArtifactUploader mount_uploader :artifacts_file, ArtifactUploader
mount_uploader :artifacts_metadata, ArtifactUploader mount_uploader :artifacts_metadata, ArtifactUploader
......
...@@ -41,8 +41,8 @@ module Ci ...@@ -41,8 +41,8 @@ module Ci
after_destroy :cleanup_runner_queue after_destroy :cleanup_runner_queue
enum access_level: { enum access_level: {
unprotected: 0, not_protected: 0,
protected_: 1 ref_protected: 1
} }
# Searches for runners matching the given query. # Searches for runners matching the given query.
...@@ -111,7 +111,7 @@ module Ci ...@@ -111,7 +111,7 @@ module Ci
end end
def can_pick?(build) def can_pick?(build)
return false if self.protected_? && !build.protected? return false if self.ref_protected? && !build.protected?
assignable_for?(build.project) && accepting_tags?(build) assignable_for?(build.project) && accepting_tags?(build)
end end
......
...@@ -78,7 +78,7 @@ module Ci ...@@ -78,7 +78,7 @@ module Ci
def new_builds def new_builds
builds = Ci::Build.pending.unstarted builds = Ci::Build.pending.unstarted
builds = builds.protected_ if runner.protected_? builds = builds.ref_protected if runner.ref_protected?
builds builds
end end
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
= label :protected, "Protected", class: 'control-label' = label :protected, "Protected", class: 'control-label'
.col-sm-10 .col-sm-10
.checkbox .checkbox
= f.check_box :access_level, {}, 'protected_', 'unprotected' = f.check_box :access_level, {}, 'ref_protected', 'not_protected'
%span.light This runner will only run on pipelines trigged on protected branches %span.light This runner will only run on pipelines trigged on protected branches
.form-group .form-group
= label :run_untagged, 'Run untagged jobs', class: 'control-label' = label :run_untagged, 'Run untagged jobs', class: 'control-label'
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
%td= @runner.active? ? 'Yes' : 'No' %td= @runner.active? ? 'Yes' : 'No'
%tr %tr
%td Protected %td Protected
%td= @runner.protected_? ? 'Yes' : 'No' %td= @runner.ref_protected? ? 'Yes' : 'No'
%tr %tr
%td Can run untagged jobs %td Can run untagged jobs
%td= @runner.run_untagged? ? 'Yes' : 'No' %td= @runner.run_untagged? ? 'Yes' : 'No'
......
...@@ -7,7 +7,7 @@ class AddAccessLevelToCiRunners < ActiveRecord::Migration ...@@ -7,7 +7,7 @@ class AddAccessLevelToCiRunners < ActiveRecord::Migration
def up def up
add_column_with_default(:ci_runners, :access_level, :integer, add_column_with_default(:ci_runners, :access_level, :integer,
default: Ci::Runner.access_levels['unprotected']) default: Ci::Runner.access_levels['not_protected'])
end end
def down def down
......
...@@ -159,7 +159,7 @@ PUT /runners/:id ...@@ -159,7 +159,7 @@ PUT /runners/:id
| `tag_list` | array | no | The list of tags for a runner; put array of tags, that should be finally assigned to a runner | | `tag_list` | array | no | The list of tags for a runner; put array of tags, that should be finally assigned to a runner |
| `run_untagged` | boolean | no | Flag indicating the runner can execute untagged jobs | | `run_untagged` | boolean | no | Flag indicating the runner can execute untagged jobs |
| `locked` | boolean | no | Flag indicating the runner is locked | | `locked` | boolean | no | Flag indicating the runner is locked |
| `access_level` | integer | no | The access_level of the runner; `unprotected`: 0, `protected`: 1 | | `access_level` | integer | no | The access_level of the runner; `not_protected`: 0, `ref_protected`: 1 |
``` ```
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/runners/6" --form "description=test-1-20150125-test" --form "tag_list=ruby,mysql,tag1,tag2" curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/runners/6" --form "description=test-1-20150125-test" --form "tag_list=ruby,mysql,tag1,tag2"
......
...@@ -22,12 +22,12 @@ FactoryGirl.define do ...@@ -22,12 +22,12 @@ FactoryGirl.define do
active false active false
end end
trait :protected do trait :ref_protected do
access_level 'protected_' access_level 'ref_protected'
end end
trait :unprotected do trait :not_protected do
access_level 'unprotected' access_level 'not_protected'
end end
end end
end end
...@@ -43,11 +43,11 @@ describe Ci::Build do ...@@ -43,11 +43,11 @@ describe Ci::Build do
it { is_expected.not_to include(manual_but_created) } it { is_expected.not_to include(manual_but_created) }
end end
describe '.protected_' do describe '.ref_protected' do
let!(:protected_job) { create(:ci_build, :protected) } let!(:protected_job) { create(:ci_build, :protected) }
let!(:unprotected_job) { create(:ci_build, :unprotected) } let!(:unprotected_job) { create(:ci_build, :unprotected) }
subject { described_class.protected_ } subject { described_class.ref_protected }
it { is_expected.to include(protected_job) } it { is_expected.to include(protected_job) }
it { is_expected.not_to include(unprotected_job) } it { is_expected.not_to include(unprotected_job) }
......
...@@ -227,7 +227,7 @@ describe Ci::Runner do ...@@ -227,7 +227,7 @@ describe Ci::Runner do
context 'when runner is protected' do context 'when runner is protected' do
before do before do
runner.protected_! runner.ref_protected!
end end
context 'when build is protected' do context 'when build is protected' do
...@@ -489,18 +489,18 @@ describe Ci::Runner do ...@@ -489,18 +489,18 @@ describe Ci::Runner do
it 'a protected runner exists' do it 'a protected runner exists' do
expect(described_class.count).to eq(1) expect(described_class.count).to eq(1)
expect(described_class.last.protected_?).to eq(true) expect(described_class.last.ref_protected?).to eq(true)
end end
end end
context 'when access_level of a runner is unprotected' do context 'when access_level of a runner is not_protected' do
before do before do
create(:ci_runner, :unprotected) create(:ci_runner, :not_protected)
end end
it 'an unprotected runner exists' do it 'an not_protected runner exists' do
expect(described_class.count).to eq(1) expect(described_class.count).to eq(1)
expect(described_class.last.unprotected?).to eq(true) expect(described_class.last.not_protected?).to eq(true)
end end
end end
end end
......
...@@ -192,7 +192,7 @@ describe API::Runners do ...@@ -192,7 +192,7 @@ describe API::Runners do
tag_list: ['ruby2.1', 'pgsql', 'mysql'], tag_list: ['ruby2.1', 'pgsql', 'mysql'],
run_untagged: 'false', run_untagged: 'false',
locked: 'true', locked: 'true',
access_level: Ci::Runner.access_levels['protected_']) access_level: Ci::Runner.access_levels['ref_protected'])
shared_runner.reload shared_runner.reload
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -201,7 +201,7 @@ describe API::Runners do ...@@ -201,7 +201,7 @@ describe API::Runners do
expect(shared_runner.tag_list).to include('ruby2.1', 'pgsql', 'mysql') expect(shared_runner.tag_list).to include('ruby2.1', 'pgsql', 'mysql')
expect(shared_runner.run_untagged?).to be(false) expect(shared_runner.run_untagged?).to be(false)
expect(shared_runner.locked?).to be(true) expect(shared_runner.locked?).to be(true)
expect(shared_runner.protected_?).to be_truthy expect(shared_runner.ref_protected?).to be_truthy
expect(shared_runner.ensure_runner_queue_value) expect(shared_runner.ensure_runner_queue_value)
.not_to eq(runner_queue_value) .not_to eq(runner_queue_value)
end end
......
...@@ -215,7 +215,7 @@ module Ci ...@@ -215,7 +215,7 @@ module Ci
end end
end end
context 'when a runner is unprotected' do context 'when a runner is not_protected' do
context 'when a job is protected' do context 'when a job is protected' do
let!(:pending_build) { create(:ci_build, :protected, pipeline: pipeline) } let!(:pending_build) { create(:ci_build, :protected, pipeline: pipeline) }
......
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