summaryrefslogtreecommitdiff
path: root/app/models/tree.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-01-05 11:00:10 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-01-05 11:06:18 -0200
commit6ce01ca3ece007f135c6b5a9bc258fdd9e8d71de (patch)
tree21b23feb015c82ea1fd4053db8d1e7395da8dca0 /app/models/tree.rb
parent2459d516337dbc37d9e653b4991e00cb9097aeb4 (diff)
downloadgitlab-ce-6ce01ca3ece007f135c6b5a9bc258fdd9e8d71de.tar.gz
Validate README format before displaying
Take the first previewable README file as project’s README, otherwise if none file is available, or we can’t preview any of them, we assume that project doesn’t have a README file.
Diffstat (limited to 'app/models/tree.rb')
-rw-r--r--app/models/tree.rb14
1 files changed, 6 insertions, 8 deletions
diff --git a/app/models/tree.rb b/app/models/tree.rb
index 93b3246a668..e0e04d8859f 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -17,18 +17,16 @@ class Tree
def readme
return @readme if defined?(@readme)
- available_readmes = blobs.select(&:readme?)
+ # Take the first previewable readme, or return nil if none is available or
+ # we can't preview any of them
+ readme_tree = blobs.find do |blob|
+ blob.readme? && (previewable?(blob.name) || plain?(blob.name))
+ end
- if available_readmes.count == 0
+ if readme_tree.nil?
return @readme = nil
end
- # Take the first previewable readme, or the first available readme, if we
- # can't preview any of them
- readme_tree = available_readmes.find do |readme|
- previewable?(readme.name)
- end || available_readmes.first
-
readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
git_repo = repository.raw_repository