diff options
author | Robert Speicher <robert@gitlab.com> | 2016-01-25 21:42:53 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-01-25 21:42:53 +0000 |
commit | 991cd07619a4072e35073f1eaf4c8661871e66bb (patch) | |
tree | 96b4142110605c422b4e48f4d296ff19600092d6 /app | |
parent | 08755f6410a0c13f1ec9d774b19c4928bac2c75b (diff) | |
parent | 1aa82dc4597d5fcdaa0839f804dd688e641cf85c (diff) | |
download | gitlab-ce-991cd07619a4072e35073f1eaf4c8661871e66bb.tar.gz |
Merge branch 'prioritize-previewable-over-plain-readmes' into 'master'
Prioritize previewable over plain README files
Fixes #12441
See merge request !2521
Diffstat (limited to 'app')
-rw-r--r-- | app/models/tree.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/app/models/tree.rb b/app/models/tree.rb index e0e04d8859f..b28f31cdd6e 100644 --- a/app/models/tree.rb +++ b/app/models/tree.rb @@ -17,12 +17,20 @@ class Tree def readme return @readme if defined?(@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)) + available_readmes = blobs.select(&:readme?) + + previewable_readmes = available_readmes.select do |blob| + previewable?(blob.name) + end + + plain_readmes = available_readmes.select do |blob| + plain?(blob.name) end + # Prioritize previewable over plain readmes + readme_tree = previewable_readmes.first || plain_readmes.first + + # Return if we can't preview any of them if readme_tree.nil? return @readme = nil end |