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:
authorDouwe Maan <douwe@selenight.nl>2017-01-29 22:38:00 +0300
committerDouwe Maan <douwe@selenight.nl>2017-02-07 01:12:23 +0300
commit27f2ca94181880861269a7ddc07ae0d50a656d35 (patch)
treef93a26a7bf263e448f24230950db618bcd73b8f5 /app/models/environment.rb
parentd147688af4adb6bcd6cb0f18797c70a8a451f4fa (diff)
Add 'View on [env]' link to blobs and individual files in diffs
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r--app/models/environment.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 577367f1eed..909249dacca 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -51,6 +51,14 @@ class Environment < ActiveRecord::Base
state :stopped
end
+ def self.latest_for_commit(environments, commit)
+ environments.sort_by do |environment|
+ deployment = environment.first_deployment_for(commit)
+
+ deployment.try(:created_at) || DateTime.parse('1970-01-01')
+ end.last
+ end
+
def predefined_variables
[
{ key: 'CI_ENVIRONMENT_NAME', value: name, public: true },
@@ -171,6 +179,16 @@ class Environment < ActiveRecord::Base
self.slug = slugified
end
+ def external_url_for(path, commit_sha)
+ return unless self.external_url
+
+ public_path = project.public_path_for_source_path(path, commit_sha)
+ return unless public_path
+
+ # TODO: Verify this can't be used for XSS
+ URI.join(external_url, public_path).to_s
+ end
+
private
# Slugifying a name may remove the uniqueness guarantee afforded by it being