diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-08-29 15:56:03 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-09-03 23:49:10 +0900 |
commit | 1024718e9fddbb0d61d3f64f44303964641fcdd8 (patch) | |
tree | 3eef4777a58c9d3e798827ca39e3a5fa0602088c | |
parent | 3875983205fd3cdbdc93f18b118deaf098d75af1 (diff) | |
download | gitlab-ce-1024718e9fddbb0d61d3f64f44303964641fcdd8.tar.gz |
Refactor access_level to not_protected and ref_protected
-rw-r--r-- | app/models/ci/build.rb | 2 | ||||
-rw-r--r-- | app/models/ci/runner.rb | 6 | ||||
-rw-r--r-- | app/services/ci/register_job_service.rb | 2 | ||||
-rw-r--r-- | app/views/projects/runners/_form.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/runners/show.html.haml | 2 | ||||
-rw-r--r-- | db/migrate/20170816133938_add_access_level_to_ci_runners.rb | 2 | ||||
-rw-r--r-- | doc/api/runners.md | 2 | ||||
-rw-r--r-- | spec/factories/ci/runners.rb | 8 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/ci/runner_spec.rb | 12 | ||||
-rw-r--r-- | spec/requests/api/runners_spec.rb | 4 | ||||
-rw-r--r-- | spec/services/ci/register_job_service_spec.rb | 2 |
12 files changed, 24 insertions, 24 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 04d5b85ab01..e58484878ba 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -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 diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index a3b4a1fccf3..f202f08b151 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -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 diff --git a/app/services/ci/register_job_service.rb b/app/services/ci/register_job_service.rb index 1f243de5761..b8db709211a 100644 --- a/app/services/ci/register_job_service.rb +++ b/app/services/ci/register_job_service.rb @@ -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 diff --git a/app/views/projects/runners/_form.html.haml b/app/views/projects/runners/_form.html.haml index 8c98075eeb5..ac8e15a48b2 100644 --- a/app/views/projects/runners/_form.html.haml +++ b/app/views/projects/runners/_form.html.haml @@ -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' diff --git a/app/views/projects/runners/show.html.haml b/app/views/projects/runners/show.html.haml index 9d427d18272..dfab04aa1fb 100644 --- a/app/views/projects/runners/show.html.haml +++ b/app/views/projects/runners/show.html.haml @@ -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' diff --git a/db/migrate/20170816133938_add_access_level_to_ci_runners.rb b/db/migrate/20170816133938_add_access_level_to_ci_runners.rb index cb8d023e439..fc484730f42 100644 --- a/db/migrate/20170816133938_add_access_level_to_ci_runners.rb +++ b/db/migrate/20170816133938_add_access_level_to_ci_runners.rb @@ -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 diff --git a/doc/api/runners.md b/doc/api/runners.md index dcca30dbfa7..df458af77bb 100644 --- a/doc/api/runners.md +++ b/doc/api/runners.md @@ -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" diff --git a/spec/factories/ci/runners.rb b/spec/factories/ci/runners.rb index e563a14ce08..249d8bde5a1 100644 --- a/spec/factories/ci/runners.rb +++ b/spec/factories/ci/runners.rb @@ -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 diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 1673d873b57..ef6c91d11f1 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -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) } diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 566b9b48879..54f68542d41 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -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 diff --git a/spec/requests/api/runners_spec.rb b/spec/requests/api/runners_spec.rb index 5a6edad8118..abaa6eb4f6d 100644 --- a/spec/requests/api/runners_spec.rb +++ b/spec/requests/api/runners_spec.rb @@ -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 diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb index 99f2507e59c..eb3e7e749ef 100644 --- a/spec/services/ci/register_job_service_spec.rb +++ b/spec/services/ci/register_job_service_spec.rb @@ -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) } |