mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
webhooks: Change *_SUBJECT_TEMPLATE to *_TOPIC_TEMPLATE.
This commit is contained in:
@@ -10,7 +10,7 @@ from zerver.lib.request import REQ, has_request_variables
|
|||||||
from zerver.lib.response import json_error, json_success
|
from zerver.lib.response import json_error, json_success
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
AIRBRAKE_SUBJECT_TEMPLATE = '{project_name}'
|
AIRBRAKE_TOPIC_TEMPLATE = '{project_name}'
|
||||||
AIRBRAKE_MESSAGE_TEMPLATE = '[{error_class}]({error_url}): "{error_message}" occurred.'
|
AIRBRAKE_MESSAGE_TEMPLATE = '[{error_class}]({error_url}): "{error_message}" occurred.'
|
||||||
|
|
||||||
@api_key_only_webhook_view('Airbrake')
|
@api_key_only_webhook_view('Airbrake')
|
||||||
@@ -23,7 +23,7 @@ def api_airbrake_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
def get_subject(payload: Dict[str, Any]) -> str:
|
def get_subject(payload: Dict[str, Any]) -> str:
|
||||||
return AIRBRAKE_SUBJECT_TEMPLATE.format(project_name=payload['error']['project']['name'])
|
return AIRBRAKE_TOPIC_TEMPLATE.format(project_name=payload['error']['project']['name'])
|
||||||
|
|
||||||
def get_body(payload: Dict[str, Any]) -> str:
|
def get_body(payload: Dict[str, Any]) -> str:
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from zerver.models import UserProfile
|
|||||||
|
|
||||||
import ujson
|
import ujson
|
||||||
|
|
||||||
APPVEYOR_SUBJECT_TEMPLATE = '{project_name}'
|
APPVEYOR_TOPIC_TEMPLATE = '{project_name}'
|
||||||
APPVEYOR_MESSAGE_TEMPLATE = ('[Build {project_name} {build_version} {status}]({build_url})\n'
|
APPVEYOR_MESSAGE_TEMPLATE = ('[Build {project_name} {build_version} {status}]({build_url})\n'
|
||||||
'Commit [{commit_id}]({commit_url}) by {committer_name}'
|
'Commit [{commit_id}]({commit_url}) by {committer_name}'
|
||||||
' on {commit_date}: {commit_message}\n'
|
' on {commit_date}: {commit_message}\n'
|
||||||
@@ -30,7 +30,7 @@ def api_appveyor_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||||||
|
|
||||||
def get_subject_for_http_request(payload: Dict[str, Any]) -> str:
|
def get_subject_for_http_request(payload: Dict[str, Any]) -> str:
|
||||||
event_data = payload['eventData']
|
event_data = payload['eventData']
|
||||||
return APPVEYOR_SUBJECT_TEMPLATE.format(project_name=event_data['projectName'])
|
return APPVEYOR_TOPIC_TEMPLATE.format(project_name=event_data['projectName'])
|
||||||
|
|
||||||
def get_body_for_http_request(payload: Dict[str, Any]) -> str:
|
def get_body_for_http_request(payload: Dict[str, Any]) -> str:
|
||||||
event_data = payload['eventData']
|
event_data = payload['eventData']
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \
|
|||||||
get_remove_branch_event_message
|
get_remove_branch_event_message
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
BITBUCKET_SUBJECT_TEMPLATE = '{repository_name}'
|
BITBUCKET_TOPIC_TEMPLATE = '{repository_name}'
|
||||||
USER_PART = 'User {display_name}(login: {username})'
|
USER_PART = 'User {display_name}(login: {username})'
|
||||||
|
|
||||||
BITBUCKET_FORK_BODY = USER_PART + ' forked the repository into [{fork_name}]({fork_url}).'
|
BITBUCKET_FORK_BODY = USER_PART + ' forked the repository into [{fork_name}]({fork_url}).'
|
||||||
@@ -99,7 +99,7 @@ def get_push_subjects(payload: Dict[str, Any]) -> List[str]:
|
|||||||
|
|
||||||
def get_subject(payload: Dict[str, Any]) -> str:
|
def get_subject(payload: Dict[str, Any]) -> str:
|
||||||
assert(payload['repository'] is not None)
|
assert(payload['repository'] is not None)
|
||||||
return BITBUCKET_SUBJECT_TEMPLATE.format(repository_name=get_repository_name(payload['repository']))
|
return BITBUCKET_TOPIC_TEMPLATE.format(repository_name=get_repository_name(payload['repository']))
|
||||||
|
|
||||||
def get_subject_based_on_type(payload: Dict[str, Any], type: str) -> Any:
|
def get_subject_based_on_type(payload: Dict[str, Any], type: str) -> Any:
|
||||||
if type.startswith('pull_request'):
|
if type.startswith('pull_request'):
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from zerver.lib.response import json_error, json_success
|
|||||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
CIRCLECI_SUBJECT_TEMPLATE = u'{repository_name}'
|
CIRCLECI_TOPIC_TEMPLATE = u'{repository_name}'
|
||||||
CIRCLECI_MESSAGE_TEMPLATE = u'[Build]({build_url}) triggered by {username} on {branch} branch {status}.'
|
CIRCLECI_MESSAGE_TEMPLATE = u'[Build]({build_url}) triggered by {username} on {branch} branch {status}.'
|
||||||
|
|
||||||
FAILED_STATUS = 'failed'
|
FAILED_STATUS = 'failed'
|
||||||
@@ -28,7 +28,7 @@ def api_circleci_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
def get_subject(payload: Dict[str, Any]) -> str:
|
def get_subject(payload: Dict[str, Any]) -> str:
|
||||||
return CIRCLECI_SUBJECT_TEMPLATE.format(repository_name=payload['reponame'])
|
return CIRCLECI_TOPIC_TEMPLATE.format(repository_name=payload['reponame'])
|
||||||
|
|
||||||
def get_body(payload: Dict[str, Any]) -> str:
|
def get_body(payload: Dict[str, Any]) -> str:
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from zerver.lib.response import json_error, json_success
|
|||||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
CODESHIP_SUBJECT_TEMPLATE = '{project_name}'
|
CODESHIP_TOPIC_TEMPLATE = '{project_name}'
|
||||||
CODESHIP_MESSAGE_TEMPLATE = '[Build]({build_url}) triggered by {committer} on {branch} branch {status}.'
|
CODESHIP_MESSAGE_TEMPLATE = '[Build]({build_url}) triggered by {committer} on {branch} branch {status}.'
|
||||||
|
|
||||||
CODESHIP_DEFAULT_STATUS = 'has {status} status'
|
CODESHIP_DEFAULT_STATUS = 'has {status} status'
|
||||||
@@ -36,7 +36,7 @@ def api_codeship_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||||||
|
|
||||||
|
|
||||||
def get_subject_for_http_request(payload: Dict[str, Any]) -> str:
|
def get_subject_for_http_request(payload: Dict[str, Any]) -> str:
|
||||||
return CODESHIP_SUBJECT_TEMPLATE.format(project_name=payload['project_name'])
|
return CODESHIP_TOPIC_TEMPLATE.format(project_name=payload['project_name'])
|
||||||
|
|
||||||
|
|
||||||
def get_body_for_http_request(payload: Dict[str, Any]) -> str:
|
def get_body_for_http_request(payload: Dict[str, Any]) -> str:
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ from zerver.lib.response import json_error, json_success
|
|||||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
CRASHLYTICS_SUBJECT_TEMPLATE = '{display_id}: {title}'
|
CRASHLYTICS_TOPIC_TEMPLATE = '{display_id}: {title}'
|
||||||
CRASHLYTICS_MESSAGE_TEMPLATE = '[Issue]({url}) impacts at least {impacted_devices_count} device(s).'
|
CRASHLYTICS_MESSAGE_TEMPLATE = '[Issue]({url}) impacts at least {impacted_devices_count} device(s).'
|
||||||
|
|
||||||
CRASHLYTICS_SETUP_SUBJECT_TEMPLATE = "Setup"
|
CRASHLYTICS_SETUP_TOPIC_TEMPLATE = "Setup"
|
||||||
CRASHLYTICS_SETUP_MESSAGE_TEMPLATE = "Webhook has been successfully configured."
|
CRASHLYTICS_SETUP_MESSAGE_TEMPLATE = "Webhook has been successfully configured."
|
||||||
|
|
||||||
VERIFICATION_EVENT = 'verification'
|
VERIFICATION_EVENT = 'verification'
|
||||||
@@ -25,11 +25,11 @@ def api_crashlytics_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||||||
payload: Dict[str, Any]=REQ(argument_type='body')) -> HttpResponse:
|
payload: Dict[str, Any]=REQ(argument_type='body')) -> HttpResponse:
|
||||||
event = payload['event']
|
event = payload['event']
|
||||||
if event == VERIFICATION_EVENT:
|
if event == VERIFICATION_EVENT:
|
||||||
subject = CRASHLYTICS_SETUP_SUBJECT_TEMPLATE
|
subject = CRASHLYTICS_SETUP_TOPIC_TEMPLATE
|
||||||
body = CRASHLYTICS_SETUP_MESSAGE_TEMPLATE
|
body = CRASHLYTICS_SETUP_MESSAGE_TEMPLATE
|
||||||
else:
|
else:
|
||||||
issue_body = payload['payload']
|
issue_body = payload['payload']
|
||||||
subject = CRASHLYTICS_SUBJECT_TEMPLATE.format(
|
subject = CRASHLYTICS_TOPIC_TEMPLATE.format(
|
||||||
display_id=issue_body['display_id'],
|
display_id=issue_body['display_id'],
|
||||||
title=issue_body['title']
|
title=issue_body['title']
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from zerver.lib.webhooks.common import check_send_webhook_message
|
|||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
GCI_MESSAGE_TEMPLATE = u'**{actor}** {action} the task [{task_name}]({task_url}).'
|
GCI_MESSAGE_TEMPLATE = u'**{actor}** {action} the task [{task_name}]({task_url}).'
|
||||||
GCI_SUBJECT_TEMPLATE = u'{student_name}'
|
GCI_TOPIC_TEMPLATE = u'{student_name}'
|
||||||
|
|
||||||
|
|
||||||
def build_instance_url(instance_id: str) -> str:
|
def build_instance_url(instance_id: str) -> str:
|
||||||
@@ -107,7 +107,7 @@ def api_gci_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||||||
event = get_event(payload)
|
event = get_event(payload)
|
||||||
if event is not None:
|
if event is not None:
|
||||||
body = get_body_based_on_event(event)(payload)
|
body = get_body_based_on_event(event)(payload)
|
||||||
subject = GCI_SUBJECT_TEMPLATE.format(
|
subject = GCI_TOPIC_TEMPLATE.format(
|
||||||
student_name=payload['task_claimed_by']
|
student_name=payload['task_claimed_by']
|
||||||
)
|
)
|
||||||
check_send_webhook_message(request, user_profile, subject, body)
|
check_send_webhook_message(request, user_profile, subject, body)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from zerver.lib.webhooks.common import check_send_webhook_message, \
|
|||||||
UnexpectedWebhookEventType
|
UnexpectedWebhookEventType
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
PINGDOM_SUBJECT_TEMPLATE = '{name} status.'
|
PINGDOM_TOPIC_TEMPLATE = '{name} status.'
|
||||||
PINGDOM_MESSAGE_TEMPLATE = ('Service {service_url} changed its {type} status'
|
PINGDOM_MESSAGE_TEMPLATE = ('Service {service_url} changed its {type} status'
|
||||||
' from {previous_state} to {current_state}.')
|
' from {previous_state} to {current_state}.')
|
||||||
PINGDOM_MESSAGE_DESCRIPTION_TEMPLATE = 'Description: {description}.'
|
PINGDOM_MESSAGE_DESCRIPTION_TEMPLATE = 'Description: {description}.'
|
||||||
@@ -49,7 +49,7 @@ def api_pingdom_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||||||
|
|
||||||
|
|
||||||
def get_subject_for_http_request(payload: Dict[str, Any]) -> str:
|
def get_subject_for_http_request(payload: Dict[str, Any]) -> str:
|
||||||
return PINGDOM_SUBJECT_TEMPLATE.format(name=payload['check_name'])
|
return PINGDOM_TOPIC_TEMPLATE.format(name=payload['check_name'])
|
||||||
|
|
||||||
|
|
||||||
def get_body_for_http_request(payload: Dict[str, Any]) -> str:
|
def get_body_for_http_request(payload: Dict[str, Any]) -> str:
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ from zerver.lib.webhooks.common import check_send_webhook_message, \
|
|||||||
UnexpectedWebhookEventType
|
UnexpectedWebhookEventType
|
||||||
from zerver.models import Client, UserProfile
|
from zerver.models import Client, UserProfile
|
||||||
|
|
||||||
SUBJECT_TEMPLATE = "{service_url}"
|
TOPIC_TEMPLATE = "{service_url}"
|
||||||
|
|
||||||
def send_message_for_event(request: HttpRequest, user_profile: UserProfile,
|
def send_message_for_event(request: HttpRequest, user_profile: UserProfile,
|
||||||
event: Dict[str, Any]) -> None:
|
event: Dict[str, Any]) -> None:
|
||||||
event_type = get_event_type(event)
|
event_type = get_event_type(event)
|
||||||
subject = SUBJECT_TEMPLATE.format(service_url=event['check']['url'])
|
subject = TOPIC_TEMPLATE.format(service_url=event['check']['url'])
|
||||||
body = EVENT_TYPE_BODY_MAPPER[event_type](event)
|
body = EVENT_TYPE_BODY_MAPPER[event_type](event)
|
||||||
check_send_webhook_message(request, user_profile, subject, body)
|
check_send_webhook_message(request, user_profile, subject, body)
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from zerver.models import UserProfile
|
|||||||
|
|
||||||
import ujson
|
import ujson
|
||||||
|
|
||||||
ZABBIX_SUBJECT_TEMPLATE = '{hostname}'
|
ZABBIX_TOPIC_TEMPLATE = '{hostname}'
|
||||||
ZABBIX_MESSAGE_TEMPLATE = '{status} ({severity}) alert on [{hostname}]({link}).\n{trigger}\n{item}'
|
ZABBIX_MESSAGE_TEMPLATE = '{status} ({severity}) alert on [{hostname}]({link}).\n{trigger}\n{item}'
|
||||||
|
|
||||||
@api_key_only_webhook_view('Zabbix')
|
@api_key_only_webhook_view('Zabbix')
|
||||||
@@ -25,7 +25,7 @@ def api_zabbix_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
def get_subject_for_http_request(payload: Dict[str, Any]) -> str:
|
def get_subject_for_http_request(payload: Dict[str, Any]) -> str:
|
||||||
return ZABBIX_SUBJECT_TEMPLATE.format(hostname=payload['hostname'])
|
return ZABBIX_TOPIC_TEMPLATE.format(hostname=payload['hostname'])
|
||||||
|
|
||||||
def get_body_for_http_request(payload: Dict[str, Any]) -> str:
|
def get_body_for_http_request(payload: Dict[str, Any]) -> str:
|
||||||
hostname = payload['hostname']
|
hostname = payload['hostname']
|
||||||
|
|||||||
Reference in New Issue
Block a user