diff --git a/app.py b/app.py index 97552ec..52af241 100644 --- a/app.py +++ b/app.py @@ -20,6 +20,8 @@ default_config = { "HTTPS": True, "SENTRY_CONFIG": {}, "RATELIMIT_STORAGE_URL": "redis://", + "REPO_URL": "https://github.com/codl/forget", + "COMMIT_URL": "https://github.com/codl/forget/commit/{hash}", } app.config.update(default_config) diff --git a/lib/version.py b/lib/version.py new file mode 100644 index 0000000..bed2811 --- /dev/null +++ b/lib/version.py @@ -0,0 +1,11 @@ +from app import app +import re + +version_re = re.compile('(?P.+)-(?P[0-9]+)-g(?P[0-9a-f]+)') + +def url_for_version(ver): + match = version_re.match(ver) + if not match: + return app.config['REPO_URL'] + return app.config['COMMIT_URL'].format(hash=match.group('hash')) + diff --git a/routes.py b/routes.py index 91db87f..6c51f75 100644 --- a/routes.py +++ b/routes.py @@ -13,6 +13,7 @@ from zipfile import BadZipFile from twitter import TwitterError from urllib.error import URLError import version +import lib.version @app.before_request def load_viewer(): @@ -26,7 +27,10 @@ def load_viewer(): @app.context_processor def inject_version(): - return dict(version=version.version) + return dict( + version=version.version, + repo_url=lib.version.url_for_version(version.version), + ) @app.context_processor def inject_sentry(): diff --git a/templates/lib/layout.html b/templates/lib/layout.html index 1144f6f..d5e9593 100644 --- a/templates/lib/layout.html +++ b/templates/lib/layout.html @@ -33,9 +33,8 @@ {% block body %}{% endblock %}