Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-11-07 08:29:16 +0300
committerShinya Maeda <shinya@gitlab.com>2018-11-07 08:29:16 +0300
commit9c811566f85d18bc9eb4a85c6a343cf1bfa4fbd2 (patch)
tree0d5de6f22917fa5def4e8a9a918bf0bcd5f1d3e4 /app/models/environment.rb
parent4eeb51dc71062fa2eac828c6030388d354179efc (diff)
Revert add action column changes
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r--app/models/environment.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 1a535ba6b18..581c870b2c5 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -8,9 +8,9 @@ class Environment < ActiveRecord::Base
belongs_to :project, required: true
- has_many :deployments, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
+ has_many :deployments, -> { success }, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
- has_one :last_deployment, -> { deployed.order('deployments.id DESC') }, class_name: 'Deployment'
+ has_one :last_deployment, -> { success.order('deployments.id DESC') }, class_name: 'Deployment'
before_validation :nullify_external_url
before_validation :generate_slug, if: ->(env) { env.slug.blank? }
@@ -50,7 +50,7 @@ class Environment < ActiveRecord::Base
scope :in_review_folder, -> { where(environment_type: "review") }
scope :for_name, -> (name) { where(name: name) }
scope :for_project, -> (project) { where(project_id: project) }
- scope :with_deployment, -> (sha) { where('EXISTS (?)', Deployment.select(1).start.where('deployments.environment_id = environments.id').where(sha: sha)) }
+ scope :with_deployment, -> (sha) { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id').where(sha: sha)) }
state_machine :state, initial: :available do
event :start do
@@ -103,6 +103,15 @@ class Environment < ActiveRecord::Base
folder_name == "production"
end
+ def first_deployment_for(commit_sha)
+ ref = project.repository.ref_name_for_sha(ref_path, commit_sha)
+
+ return nil unless ref
+
+ deployment_iid = ref.split('/').last
+ deployments.find_by(iid: deployment_iid)
+ end
+
def ref_path
"refs/#{Repository::REF_ENVIRONMENTS}/#{slug}"
end