Commit b8e30b44 authored by 🤖 GitLab Bot 🤖's avatar 🤖 GitLab Bot 🤖

Add latest changes from gitlab-org/[email protected]

parent 01226c75
......@@ -24,7 +24,7 @@ const isRichReadme = file => {
};
const isPlainReadme = file => {
const re = new RegExp(`^(${FILENAMES.join('|')})$`, 'i');
const re = new RegExp(`^(${FILENAMES.join('|')})(\\.txt)?$`, 'i');
return re.test(file.name);
};
......
---
title: Fix README.txt not showing up on a project page
merge_request: 21763
author: Alexander Oleynikov
type: fixed
......@@ -8,7 +8,7 @@ module Gitlab
module FileDetector
PATTERNS = {
# Project files
readme: /\A(#{Regexp.union(*Gitlab::MarkupHelper::PLAIN_FILENAMES).source})(\.(#{Regexp.union(*Gitlab::MarkupHelper::EXTENSIONS).source}))?\z/i,
readme: /\A(#{Regexp.union(*Gitlab::MarkupHelper::PLAIN_FILENAMES).source})(\.(txt|#{Regexp.union(*Gitlab::MarkupHelper::EXTENSIONS).source}))?\z/i,
changelog: %r{\A(changelog|history|changes|news)[^/]*\z}i,
license: %r{\A((un)?licen[sc]e|copying)(\.[^/]+)?\z}i,
contributing: %r{\Acontributing[^/]*\z}i,
......
......@@ -31,6 +31,12 @@ describe('readmeFile', () => {
});
});
it('recognizes Readme.txt as a plain text README', () => {
expect(readmeFile([{ name: 'Readme.txt' }])).toEqual({
name: 'Readme.txt',
});
});
it('returns undefined when there are no appropriate files', () => {
expect(readmeFile([{ name: 'index.js' }, { name: 'md.README' }])).toBe(undefined);
expect(readmeFile([])).toBe(undefined);
......
......@@ -410,7 +410,7 @@ describe MarkupHelper do
end
context 'when file has an unknown type' do
let(:file_name) { 'foo' }
let(:file_name) { 'foo.tex' }
it 'returns html (rendered by Gitlab::OtherMarkup)' do
expected_html = 'Noël'
......
......@@ -16,23 +16,30 @@ describe Gitlab::FileDetector do
end
describe '.type_of' do
it 'returns the type of a README file' do
filenames = Gitlab::MarkupHelper::PLAIN_FILENAMES + Gitlab::MarkupHelper::PLAIN_FILENAMES.map(&:upcase)
extensions = Gitlab::MarkupHelper::EXTENSIONS + Gitlab::MarkupHelper::EXTENSIONS.map(&:upcase)
it 'returns the type of a README without extension' do
expect(described_class.type_of('README')).to eq(:readme)
expect(described_class.type_of('INDEX')).to eq(:readme)
end
filenames.each do |filename|
expect(described_class.type_of(filename)).to eq(:readme)
it 'returns the type of a README file with a recognized extension' do
extensions = ['txt', *Gitlab::MarkupHelper::EXTENSIONS]
extensions.each do |extname|
expect(described_class.type_of("#{filename}.#{extname}")).to eq(:readme)
extensions.each do |ext|
%w(index readme).each do |file|
expect(described_class.type_of("#{file}.#{ext}")).to eq(:readme)
end
end
end
it 'returns nil for a README.rb file' do
it 'returns nil for a README with unrecognized extension' do
expect(described_class.type_of('README.rb')).to be_nil
end
it 'is case insensitive' do
expect(described_class.type_of('ReadMe')).to eq(:readme)
expect(described_class.type_of('index.TXT')).to eq(:readme)
end
it 'returns nil for a README file in a directory' do
expect(described_class.type_of('foo/README.md')).to be_nil
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment