diff options
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 |