summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-09-13 14:14:55 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-09-19 10:05:35 +0200
commita4638dddf22797f46d72ea7b73c8453ba68645ab (patch)
tree3b270989070a48e9e1ea3f983070168f863c4bd1 /app/models
parent1d51bc7dfd04886fa5af69a60bb509691d697813 (diff)
downloadgitlab-ce-a4638dddf22797f46d72ea7b73c8453ba68645ab.tar.gz
Add support for dynamic environments
Environments that can have a URL with predefined CI variables.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/build.rb4
-rw-r--r--app/models/environment.rb12
-rw-r--r--app/models/merge_request.rb13
3 files changed, 27 insertions, 2 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index fb16bc06d71..abdf8c76447 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -83,7 +83,9 @@ module Ci
environment: build.environment,
sha: build.sha,
ref: build.ref,
- tag: build.tag)
+ tag: build.tag,
+ options: build.options[:environment],
+ variables: variables)
service.execute(build)
end
end
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 75e6f869786..33c9abf382a 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -4,6 +4,7 @@ class Environment < ActiveRecord::Base
has_many :deployments
before_validation :nullify_external_url
+ before_save :set_environment_type
validates :name,
presence: true,
@@ -26,6 +27,17 @@ class Environment < ActiveRecord::Base
self.external_url = nil if self.external_url.blank?
end
+ def set_environment_type
+ names = name.split('/')
+
+ self.environment_type =
+ if names.many?
+ names.first
+ else
+ nil
+ end
+ end
+
def includes_commit?(commit)
return false unless last_deployment
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 75f48fd4ba5..b215f02e4b7 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -744,10 +744,21 @@ class MergeRequest < ActiveRecord::Base
@pipeline ||= source_project.pipeline_for(source_branch, diff_head_sha)
end
+ def all_commits_sha
+ merge_request_diffs.map(&:commits).flatten.map(&:sha).sort.uniq
+ end
+
+ def latest_pipelines
+ @latest_pipelines ||=
+ if diff_head_sha && source_project
+ source_project.pipelines.order(id: :desc).where(sha: commits_sha, ref: source_branch)
+ end
+ end
+
def all_pipelines
@all_pipelines ||=
if diff_head_sha && source_project
- source_project.pipelines.order(id: :desc).where(sha: commits_sha, ref: source_branch)
+ source_project.pipelines.order(id: :desc).where(sha: all_commits_sha, ref: source_branch)
end
end