diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2018-10-18 17:17:24 +0300 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2018-10-18 17:25:31 +0300 |
commit | d60cc75d4355be9adf2d6195e49c4e6a96ca336c (patch) | |
tree | 1ad19c4b9061a636a2d126627b1a958d2e398fd2 /app/models/environment_status.rb | |
parent | 4a9efc606f5cdd9cf3aa34991543eb2f77555914 (diff) |
Show modified and added public paths in MR
Diffstat (limited to 'app/models/environment_status.rb')
-rw-r--r-- | app/models/environment_status.rb | 29 |
1 files changed, 29 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 |