mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
error_notify: Try git describe too.
Tested for graceful degradation both with `git` not existing and the `.git` directory not existing.
This commit is contained in:
@@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.mail import mail_admins
|
from django.core.mail import mail_admins
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from typing import Any, Dict, Text
|
from typing import Any, Dict, Optional, Text
|
||||||
|
|
||||||
from zerver.models import get_system_bot
|
from zerver.models import get_system_bot
|
||||||
from zerver.lib.actions import internal_send_message
|
from zerver.lib.actions import internal_send_message
|
||||||
@@ -32,12 +33,30 @@ def user_info_str(report):
|
|||||||
user_info += " on %s deployment" % (report['deployment'],)
|
user_info += " on %s deployment" % (report['deployment'],)
|
||||||
return user_info
|
return user_info
|
||||||
|
|
||||||
|
def try_git_describe() -> Optional[str]:
|
||||||
|
try:
|
||||||
|
return subprocess.check_output(
|
||||||
|
['git',
|
||||||
|
'--git-dir', os.path.join(os.path.dirname(__file__), '../../.git'),
|
||||||
|
'describe', '--tags', '--dirty', '--long'],
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
).strip().decode('utf-8')
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
def deployment_repr() -> str:
|
def deployment_repr() -> str:
|
||||||
deployment = 'Deployed code:\n'
|
deployment = 'Deployed code:\n'
|
||||||
|
|
||||||
|
git_described = try_git_describe()
|
||||||
|
if git_described is not None:
|
||||||
|
deployment += '- git: %s\n' % (git_described,)
|
||||||
|
|
||||||
deployment += '- ZULIP_VERSION: %s\n' % (ZULIP_VERSION,)
|
deployment += '- ZULIP_VERSION: %s\n' % (ZULIP_VERSION,)
|
||||||
|
|
||||||
version_path = os.path.join(os.path.dirname(__file__), '../../version')
|
version_path = os.path.join(os.path.dirname(__file__), '../../version')
|
||||||
if os.path.exists(version_path):
|
if os.path.exists(version_path):
|
||||||
deployment += '- version: %s\n' % (open(version_path).read().strip(),)
|
deployment += '- version: %s\n' % (open(version_path).read().strip(),)
|
||||||
|
|
||||||
return deployment
|
return deployment
|
||||||
|
|
||||||
def notify_browser_error(report):
|
def notify_browser_error(report):
|
||||||
|
|||||||
Reference in New Issue
Block a user