summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-09-06 23:09:41 +0900
committerShinya Maeda <shinya@gitlab.com>2017-09-06 23:09:41 +0900
commitf7da15bae3e41e1a3fe30918887928c8908ccbe3 (patch)
tree98a1eb2ab8b5cf92cf02d2c3ca1cd58c8a83e315
parentd68ff7f50a93ebbff537b5e795cf6bf80bd66a6e (diff)
downloadgitlab-ce-f7da15bae3e41e1a3fe30918887928c8908ccbe3.tar.gz
Use before_save :set_protected
-rw-r--r--app/models/ci/build.rb6
-rw-r--r--app/models/ci/pipeline.rb6
-rw-r--r--app/services/ci/create_pipeline_service.rb3
-rw-r--r--lib/gitlab/ci/stage/seed.rb9
-rw-r--r--spec/services/ci/retry_build_service_spec.rb11
5 files changed, 23 insertions, 12 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index ba3156154ac..11390d3aa0d 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -27,7 +27,6 @@ module Ci
validates :coverage, numericality: true, allow_blank: true
validates :ref, presence: true
- validates :protected, inclusion: { in: [true, false], unless: :importing? }, on: :create
scope :unstarted, ->() { where(runner_id: nil) }
scope :ignore_failures, ->() { where(allow_failure: false) }
@@ -47,6 +46,7 @@ module Ci
before_save :update_artifacts_size, if: :artifacts_file_changed?
before_save :ensure_token
+ before_save :set_protected
before_destroy { unscoped_project }
after_create do |build|
@@ -461,6 +461,10 @@ module Ci
end
end
+ def set_protected
+ self.protected = pipeline.protected
+ end
+
def erase_trace!
trace.erase!
end
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 35d14b6e297..f51b7d7d2a7 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -36,9 +36,9 @@ module Ci
validates :sha, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing? }
validates :status, presence: { unless: :importing? }
- validates :protected, inclusion: { in: [true, false], unless: :importing? }, on: :create
validate :valid_commit_sha, unless: :importing?
+ # before_save :set_protected
after_create :keep_around_commits, unless: :importing?
enum source: {
@@ -445,6 +445,10 @@ module Ci
statuses.latest.status || 'skipped'
end
+ def set_protected
+ self.protected = project.protected_for?(self.ref)
+ end
+
def keep_around_commits
return unless project
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb
index 414c01b2546..de2cd7e87be 100644
--- a/app/services/ci/create_pipeline_service.rb
+++ b/app/services/ci/create_pipeline_service.rb
@@ -12,8 +12,7 @@ module Ci
tag: tag?,
trigger_requests: Array(trigger_request),
user: current_user,
- pipeline_schedule: schedule,
- protected: project.protected_for?(ref)
+ pipeline_schedule: schedule
)
result = validate(current_user,
diff --git a/lib/gitlab/ci/stage/seed.rb b/lib/gitlab/ci/stage/seed.rb
index e19aae35a81..f81f9347b4d 100644
--- a/lib/gitlab/ci/stage/seed.rb
+++ b/lib/gitlab/ci/stage/seed.rb
@@ -28,8 +28,7 @@ module Gitlab
attributes.merge(project: project,
ref: pipeline.ref,
tag: pipeline.tag,
- trigger_request: trigger,
- protected: protected_ref?)
+ trigger_request: trigger)
end
end
@@ -44,12 +43,6 @@ module Gitlab
end
end
end
-
- private
-
- def protected_ref?
- @protected_ref ||= project.protected_for?(pipeline.ref)
- end
end
end
end
diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb
index f5ed9ff608f..f0eb700d342 100644
--- a/spec/services/ci/retry_build_service_spec.rb
+++ b/spec/services/ci/retry_build_service_spec.rb
@@ -52,6 +52,17 @@ describe Ci::RetryBuildService do
expect(new_build.send(attribute)).to eq build.send(attribute)
end
end
+
+ context 'when job has nullified protected' do
+ before do
+ build.update_attribute(:protected, nil)
+ end
+
+ it "clones protected build attribute" do
+ expect(new_build.protected).not_to be_nil
+ expect(new_build.protected).to eq build.protected
+ end
+ end
end
describe 'reject acessors' do