BigW Consortium Gitlab

Commit 1024718e by Shinya Maeda

Refactor access_level to not_protected and ref_protected

parent 38759832
......@@ -34,7 +34,7 @@ module Ci
scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) }
scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
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_metadata, ArtifactUploader
......
......@@ -41,8 +41,8 @@ module Ci
after_destroy :cleanup_runner_queue
enum access_level: {
unprotected: 0,
protected_: 1
not_protected: 0,
ref_protected: 1
}
# Searches for runners matching the given query.
......@@ -111,7 +111,7 @@ module Ci
end
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)
end
......
......@@ -78,7 +78,7 @@ module Ci
def new_builds
builds = Ci::Build.pending.unstarted
builds = builds.protected_ if runner.protected_?
builds = builds.ref_protected if runner.ref_protected?
builds
end
......
......@@ -10,7 +10,7 @@
= label :protected, "Protected", class: 'control-label'
.col-sm-10
.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
.form-group
= label :run_untagged, 'Run untagged jobs', class: 'control-label'
......
......@@ -21,7 +21,7 @@
%td= @runner.active? ? 'Yes' : 'No'
%tr
%td Protected
%td= @runner.protected_? ? 'Yes' : 'No'
%td= @runner.ref_protected? ? 'Yes' : 'No'
%tr
%td Can run untagged jobs
%td= @runner.run_untagged? ? 'Yes' : 'No'
......
......@@ -7,7 +7,7 @@ class AddAccessLevelToCiRunners < ActiveRecord::Migration
def up
add_column_with_default(:ci_runners, :access_level, :integer,
default: Ci::Runner.access_levels['unprotected'])
default: Ci::Runner.access_levels['not_protected'])
end
def down
......
......@@ -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 |
| `run_untagged` | boolean | no | Flag indicating the runner can execute untagged jobs |
| `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"
......
......@@ -22,12 +22,12 @@ FactoryGirl.define do
active false
end
trait :protected do
access_level 'protected_'
trait :ref_protected do
access_level 'ref_protected'
end
trait :unprotected do
access_level 'unprotected'
trait :not_protected do
access_level 'not_protected'
end
end
end
......@@ -43,11 +43,11 @@ describe Ci::Build do
it { is_expected.not_to include(manual_but_created) }
end
describe '.protected_' do
describe '.ref_protected' do
let!(:protected_job) { create(:ci_build, :protected) }
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.not_to include(unprotected_job) }
......
......@@ -227,7 +227,7 @@ describe Ci::Runner do
context 'when runner is protected' do
before do
runner.protected_!
runner.ref_protected!
end
context 'when build is protected' do
......@@ -489,18 +489,18 @@ describe Ci::Runner do
it 'a protected runner exists' do
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
context 'when access_level of a runner is unprotected' do
context 'when access_level of a runner is not_protected' do
before do
create(:ci_runner, :unprotected)
create(:ci_runner, :not_protected)
end
it 'an unprotected runner exists' do
it 'an not_protected runner exists' do
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
......
......@@ -192,7 +192,7 @@ describe API::Runners do
tag_list: ['ruby2.1', 'pgsql', 'mysql'],
run_untagged: 'false',
locked: 'true',
access_level: Ci::Runner.access_levels['protected_'])
access_level: Ci::Runner.access_levels['ref_protected'])
shared_runner.reload
expect(response).to have_http_status(200)
......@@ -201,7 +201,7 @@ describe API::Runners do
expect(shared_runner.tag_list).to include('ruby2.1', 'pgsql', 'mysql')
expect(shared_runner.run_untagged?).to be(false)
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)
.not_to eq(runner_queue_value)
end
......
......@@ -215,7 +215,7 @@ module Ci
end
end
context 'when a runner is unprotected' do
context 'when a runner is not_protected' do
context 'when a job is protected' do
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