Show More
@@ -64,30 +64,12 b' class SummaryController(BaseRepoControll' | |||
|
64 | 64 | def _generate_readme(cache_key): |
|
65 | 65 | readme_data = None |
|
66 | 66 | readme_file = None |
|
67 | try: | |
|
68 |
|
|
|
69 | commit = db_repo.get_landing_commit() | |
|
70 | if isinstance(commit, EmptyCommit): | |
|
71 | raise EmptyRepositoryError() | |
|
72 | ||
|
67 | commit = self._get_landing_commit_or_none(db_repo) | |
|
68 | if commit: | |
|
69 | log.debug("Searching for a README file.") | |
|
73 | 70 | readme_file = ReadmeFinder(default_renderer).search(commit) |
|
74 | ||
|
75 | # Render the readme if one was found | |
|
76 | 71 |
|
|
77 | renderer = MarkupRenderer() | |
|
78 | node = commit.get_node(readme_file) | |
|
79 | log.debug('Found README file `%s` rendering...', | |
|
80 | readme_file) | |
|
81 | readme_data = renderer.render( | |
|
82 | node.content, filename=readme_file) | |
|
83 | except CommitError: | |
|
84 | log.exception( | |
|
85 | "Problem getting commit when trying to render the README.") | |
|
86 | except EmptyRepositoryError: | |
|
87 | log.debug("Repository is empty, no README to render.") | |
|
88 | except Exception: | |
|
89 | log.exception("Exception while trying to render the README") | |
|
90 | ||
|
72 | readme_data = self._render_readme_or_none(commit, readme_file) | |
|
91 | 73 | return readme_data, readme_file |
|
92 | 74 | |
|
93 | 75 | invalidator_context = CacheKey.repo_context_cache( |
@@ -99,6 +81,29 b' class SummaryController(BaseRepoControll' | |||
|
99 | 81 | |
|
100 | 82 | return computed |
|
101 | 83 | |
|
84 | def _get_landing_commit_or_none(self, db_repo): | |
|
85 | log.debug("Getting the landing commit.") | |
|
86 | try: | |
|
87 | commit = db_repo.get_landing_commit() | |
|
88 | if not isinstance(commit, EmptyCommit): | |
|
89 | return commit | |
|
90 | else: | |
|
91 | log.debug("Repository is empty, no README to render.") | |
|
92 | except CommitError: | |
|
93 | log.exception( | |
|
94 | "Problem getting commit when trying to render the README.") | |
|
95 | ||
|
96 | def _render_readme_or_none(self, commit, readme_file): | |
|
97 | log.debug( | |
|
98 | 'Found README file `%s` rendering...', readme_file) | |
|
99 | renderer = MarkupRenderer() | |
|
100 | node = commit.get_node(readme_file) | |
|
101 | try: | |
|
102 | return renderer.render(node.content, filename=readme_file) | |
|
103 | except Exception: | |
|
104 | log.exception( | |
|
105 | "Exception while trying to render the README") | |
|
106 | ||
|
102 | 107 | @LoginRequired() |
|
103 | 108 | @HasRepoPermissionAnyDecorator( |
|
104 | 109 | 'repository.read', 'repository.write', 'repository.admin') |
General Comments 0
You need to be logged in to leave comments.
Login now