Commit e1ef436d authored by Shinya Maeda's avatar Shinya Maeda

Update application code by the db schema change

parent 0a7b3ae9
...@@ -34,11 +34,7 @@ module Ci ...@@ -34,11 +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 :on_protected, ->() do
joins("LEFT JOIN ci_pipelines ON ci_builds.commit_id = ci_pipelines.id")
.where('ci_pipelines.protected IS TRUE')
end
mount_uploader :artifacts_file, ArtifactUploader mount_uploader :artifacts_file, ArtifactUploader
mount_uploader :artifacts_metadata, ArtifactUploader mount_uploader :artifacts_metadata, ArtifactUploader
......
...@@ -5,7 +5,7 @@ module Ci ...@@ -5,7 +5,7 @@ module Ci
RUNNER_QUEUE_EXPIRY_TIME = 60.minutes RUNNER_QUEUE_EXPIRY_TIME = 60.minutes
ONLINE_CONTACT_TIMEOUT = 1.hour ONLINE_CONTACT_TIMEOUT = 1.hour
AVAILABLE_SCOPES = %w[specific shared active paused online].freeze AVAILABLE_SCOPES = %w[specific shared active paused online].freeze
FORM_EDITABLE = %i[description tag_list active run_untagged locked protected].freeze FORM_EDITABLE = %i[description tag_list active run_untagged locked access_level].freeze
has_many :builds has_many :builds
has_many :runner_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :runner_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
...@@ -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: {
protection_none: 0, unprotected: 0,
protection_full: 1 protected_: 1
} }
# Searches for runners matching the given query. # Searches for runners matching the given query.
......
...@@ -12,8 +12,7 @@ module Ci ...@@ -12,8 +12,7 @@ module Ci
tag: tag?, tag: tag?,
trigger_requests: Array(trigger_request), trigger_requests: Array(trigger_request),
user: current_user, user: current_user,
pipeline_schedule: schedule, pipeline_schedule: schedule
protected: protected?
) )
result = validate(current_user, result = validate(current_user,
...@@ -176,10 +175,6 @@ module Ci ...@@ -176,10 +175,6 @@ module Ci
origin_sha && origin_sha != Gitlab::Git::BLANK_SHA origin_sha && origin_sha != Gitlab::Git::BLANK_SHA
end end
def protected?
project.protected_for?(ref)
end
def error(message, save: false) def error(message, save: false)
pipeline.tap do pipeline.tap do
pipeline.errors.add(:base, message) pipeline.errors.add(:base, message)
......
...@@ -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.on_protected if runner.protected? builds = builds.protected_ if runner.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 :protected = f.check_box :access_level, 1, 0
%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.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'
......
...@@ -6,7 +6,7 @@ class AddAccessLevelToCiRunners < ActiveRecord::Migration ...@@ -6,7 +6,7 @@ class AddAccessLevelToCiRunners < ActiveRecord::Migration
disable_ddl_transaction! disable_ddl_transaction!
def up def up
# Ci::Runner.protection_none: 0 # Ci::Runner.unprotected: 0
add_column_with_default(:ci_runners, :access_level, :integer, default: 0) add_column_with_default(:ci_runners, :access_level, :integer, default: 0)
end end
......
...@@ -28,10 +28,15 @@ module Gitlab ...@@ -28,10 +28,15 @@ module Gitlab
attributes.merge(project: project, attributes.merge(project: project,
ref: pipeline.ref, ref: pipeline.ref,
tag: pipeline.tag, tag: pipeline.tag,
trigger_request: trigger) trigger_request: trigger
protected: protected?)
end end
end end
def protected?
@protected ||= project.protected_for?(pipeline.ref)
end
def create! def create!
pipeline.stages.create!(stage).tap do |stage| pipeline.stages.create!(stage).tap do |stage|
builds_attributes = builds.map do |attributes| builds_attributes = builds.map do |attributes|
......
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