Show More
@@ -63,14 +63,16 b' class SummaryController(BaseRepoControll' | |||
|
63 | 63 | @cache_region('long_term') |
|
64 | 64 | def _generate_readme(cache_key): |
|
65 | 65 | readme_data = None |
|
66 |
readme_ |
|
|
66 | readme_node = None | |
|
67 | readme_filename = None | |
|
67 | 68 | commit = self._get_landing_commit_or_none(db_repo) |
|
68 | 69 | if commit: |
|
69 | 70 | log.debug("Searching for a README file.") |
|
70 |
readme_ |
|
|
71 |
if readme_ |
|
|
72 |
readme_data = self._render_readme_or_none(commit, readme_ |
|
|
73 | return readme_data, readme_file | |
|
71 | readme_node = ReadmeFinder(default_renderer).search(commit) | |
|
72 | if readme_node: | |
|
73 | readme_data = self._render_readme_or_none(commit, readme_node) | |
|
74 | readme_filename = readme_node.path | |
|
75 | return readme_data, readme_filename | |
|
74 | 76 | |
|
75 | 77 | invalidator_context = CacheKey.repo_context_cache( |
|
76 | 78 | _generate_readme, repo_name, CacheKey.CACHE_TYPE_README) |
@@ -93,13 +95,13 b' class SummaryController(BaseRepoControll' | |||
|
93 | 95 | log.exception( |
|
94 | 96 | "Problem getting commit when trying to render the README.") |
|
95 | 97 | |
|
96 |
def _render_readme_or_none(self, commit, readme_ |
|
|
98 | def _render_readme_or_none(self, commit, readme_node): | |
|
97 | 99 | log.debug( |
|
98 |
'Found README file `%s` rendering...', readme_ |
|
|
100 | 'Found README file `%s` rendering...', readme_node.path) | |
|
99 | 101 | renderer = MarkupRenderer() |
|
100 | node = commit.get_node(readme_file) | |
|
101 | 102 | try: |
|
102 |
return renderer.render( |
|
|
103 | return renderer.render( | |
|
104 | readme_node.content, filename=readme_node.file) | |
|
103 | 105 | except Exception: |
|
104 | 106 | log.exception( |
|
105 | 107 | "Exception while trying to render the README") |
@@ -987,7 +987,7 b' class ReadmeFinder:' | |||
|
987 | 987 | matches = self._match_readmes(nodes) |
|
988 | 988 | matches = self._sort_according_to_priority(matches) |
|
989 | 989 | if matches: |
|
990 |
return matches[0] |
|
|
990 | return matches[0] | |
|
991 | 991 | |
|
992 | 992 | paths = self._match_paths(nodes) |
|
993 | 993 | paths = self._sort_paths_according_to_priority(paths) |
@@ -54,29 +54,29 b' class CommitUtility:' | |||
|
54 | 54 | def test_no_matching_file_returns_none(commit_util): |
|
55 | 55 | commit = commit_util.commit_with_files(['LIESMICH']) |
|
56 | 56 | finder = ReadmeFinder(default_renderer='rst') |
|
57 |
filen |
|
|
58 |
assert filen |
|
|
57 | filenode = finder.search(commit) | |
|
58 | assert filenode is None | |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | def test_matching_file_returns_the_file_name(commit_util): |
|
62 | 62 | commit = commit_util.commit_with_files(['README']) |
|
63 | 63 | finder = ReadmeFinder(default_renderer='rst') |
|
64 |
filen |
|
|
65 |
assert filen |
|
|
64 | filenode = finder.search(commit) | |
|
65 | assert filenode.path == 'README' | |
|
66 | 66 | |
|
67 | 67 | |
|
68 | 68 | def test_matching_file_with_extension(commit_util): |
|
69 | 69 | commit = commit_util.commit_with_files(['README.rst']) |
|
70 | 70 | finder = ReadmeFinder(default_renderer='rst') |
|
71 |
filen |
|
|
72 |
assert filen |
|
|
71 | filenode = finder.search(commit) | |
|
72 | assert filenode.path == 'README.rst' | |
|
73 | 73 | |
|
74 | 74 | |
|
75 | 75 | def test_prefers_readme_without_extension(commit_util): |
|
76 | 76 | commit = commit_util.commit_with_files(['README.rst', 'Readme']) |
|
77 | 77 | finder = ReadmeFinder() |
|
78 |
filen |
|
|
79 |
assert filen |
|
|
78 | filenode = finder.search(commit) | |
|
79 | assert filenode.path == 'Readme' | |
|
80 | 80 | |
|
81 | 81 | |
|
82 | 82 | @pytest.mark.parametrize('renderer, expected', [ |
@@ -87,20 +87,20 b' def test_prefers_renderer_extensions(com' | |||
|
87 | 87 | commit = commit_util.commit_with_files( |
|
88 | 88 | ['readme.rst', 'readme.md', 'readme.txt']) |
|
89 | 89 | finder = ReadmeFinder(default_renderer=renderer) |
|
90 |
filen |
|
|
91 |
assert filen |
|
|
90 | filenode = finder.search(commit) | |
|
91 | assert filenode.path == expected | |
|
92 | 92 | |
|
93 | 93 | |
|
94 | 94 | def test_finds_readme_in_subdirectory(commit_util): |
|
95 | 95 | commit = commit_util.commit_with_files(['doc/README.rst', 'LIESMICH']) |
|
96 | 96 | finder = ReadmeFinder() |
|
97 |
filen |
|
|
98 |
assert filen |
|
|
97 | filenode = finder.search(commit) | |
|
98 | assert filenode.path == 'doc/README.rst' | |
|
99 | 99 | |
|
100 | 100 | |
|
101 | 101 | def test_prefers_subdirectory_with_priority(commit_util): |
|
102 | 102 | commit = commit_util.commit_with_files( |
|
103 | 103 | ['Doc/Readme.rst', 'Docs/Readme.rst']) |
|
104 | 104 | finder = ReadmeFinder() |
|
105 |
filen |
|
|
106 |
assert filen |
|
|
105 | filenode = finder.search(commit) | |
|
106 | assert filenode.path == 'Doc/Readme.rst' |
General Comments 0
You need to be logged in to leave comments.
Login now