diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-01-29 13:38:00 -0600 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-02-06 16:12:23 -0600 |
commit | 27f2ca94181880861269a7ddc07ae0d50a656d35 (patch) | |
tree | f93a26a7bf263e448f24230950db618bcd73b8f5 /app/models/environment.rb | |
parent | d147688af4adb6bcd6cb0f18797c70a8a451f4fa (diff) | |
download | gitlab-ce-27f2ca94181880861269a7ddc07ae0d50a656d35.tar.gz |
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.rb | 18 |
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 |