diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/environment_status.rb | 29 | ||||
-rw-r--r-- | app/serializers/environment_status_entity.rb | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/app/models/environment_status.rb b/app/models/environment_status.rb index cae0d396089..5ff3acc0e58 100644 --- a/app/models/environment_status.rb +++ b/app/models/environment_status.rb @@ -24,4 +24,33 @@ class EnvironmentStatus def deployed_at deployment&.created_at end + + def changes + sha = merge_request.diff_head_sha + return [] if project.route_map_for(sha).nil? + + changed_files.map { |file| build_change(file, sha) }.compact + end + + def changed_files + merge_request.merge_request_diff + .merge_request_diff_files.where(deleted_file: false) + end + + private + + PAGE_EXTENSIONS = /\A\.(s?html?|php|asp|cgi|pl)\z/i.freeze + + def build_change(file, sha) + public_path = project.public_path_for_source_path(file.new_path, sha) + return if public_path.nil? + + ext = File.extname(public_path) + return if ext.present? && ext !~ PAGE_EXTENSIONS + + { + path: public_path, + external_url: environment.external_url_for(file.new_path, sha) + } + end end diff --git a/app/serializers/environment_status_entity.rb b/app/serializers/environment_status_entity.rb index 62152dd1d40..3dfa4f204c9 100644 --- a/app/serializers/environment_status_entity.rb +++ b/app/serializers/environment_status_entity.rb @@ -36,6 +36,8 @@ class EnvironmentStatusEntity < Grape::Entity es.deployment.try(:formatted_deployment_time) end + expose :changes, if: ->(*) { Feature.enabled?(:ci_environments_status_changes, project) } + private def environment |