From 51cfa412e7611fc9c294566e6c53e37290f89ee6 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 18 2017 07:40:11 +0000 Subject: Link to the doc when the documentation is activated but has no content New user of pagure may not know how the documentation works in pagure. So they will see the settings page, activate the documentation and if they do not upload anything to the documentation git repo, nothing will happen and they may wonder why. So in addition to the error message that nothing was found in the git repo, this commit adds a link to the relevant section of pagure's documentation. Fixes https://pagure.io/pagure/issue/1562 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/docs_server.py b/pagure/docs_server.py index a72331d..d1f9cc1 100644 --- a/pagure/docs_server.py +++ b/pagure/docs_server.py @@ -158,7 +158,14 @@ def view_docs(repo, username=None, namespace=None, filename=None): if not repo_obj.is_empty: commit = repo_obj[repo_obj.head.target] else: - flask.abort(404, 'No content found is the repository') + flask.abort( + 404, + flask.Markup( + 'No content found is the repository, you may want to read ' + 'the ' + 'Using the doc repository of your project documentation' + ) + ) branchname = 'master' content = None diff --git a/tests/test_pagure_flask_docs.py b/tests/test_pagure_flask_docs.py index 8930885..0715734 100644 --- a/tests/test_pagure_flask_docs.py +++ b/tests/test_pagure_flask_docs.py @@ -154,6 +154,26 @@ class PagureFlaskDocstests(tests.Modeltests): output = self.app.get('/test/docs', follow_redirects=True) self.assertEqual(output.status_code, 404) + def test_view_docs_empty_repo(self): + """ Test the view_docs endpoint when the git repo is empty. """ + tests.create_projects(self.session) + repo = pygit2.init_repository( + os.path.join(self.path, 'docs', 'test.git'), bare=True) + + # Turn on the docs project since it's off by default + repo = pagure.get_authorized_project(self.session, 'test') + repo.settings = {'project_documentation': True} + self.session.add(repo) + self.session.commit() + + output = self.app.get('/test/docs') + self.assertEqual(output.status_code, 404) + self.assertIn( + '

No content found is the repository, you may want to read ' + 'the Using the doc repository of your project ' + 'documentation

', output.data) + def test_view_docs(self): """ Test the view_docs endpoint. """ tests.create_projects(self.session)