mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 11:22:04 +00:00
zerver/webhooks: Text-wrap long lines exceeding 110.
This commit is contained in:
@@ -19,7 +19,8 @@ BITBUCKET_SUBJECT_TEMPLATE = '{repository_name}'
|
||||
USER_PART = 'User {display_name}(login: {username})'
|
||||
|
||||
BITBUCKET_FORK_BODY = USER_PART + ' forked the repository into [{fork_name}]({fork_url}).'
|
||||
BITBUCKET_COMMIT_STATUS_CHANGED_BODY = '[System {key}]({system_url}) changed status of {commit_info} to {status}.'
|
||||
BITBUCKET_COMMIT_STATUS_CHANGED_BODY = ('[System {key}]({system_url}) changed status of'
|
||||
' {commit_info} to {status}.')
|
||||
|
||||
|
||||
PULL_REQUEST_SUPPORTED_ACTIONS = [
|
||||
@@ -201,9 +202,11 @@ def get_commit_comment_body(payload: Dict[str, Any]) -> Text:
|
||||
)
|
||||
|
||||
def get_commit_status_changed_body(payload: Dict[str, Any]) -> str:
|
||||
commit_id = re.match('.*/commit/(?P<commit_id>[A-Za-z0-9]*$)', payload['commit_status']['links']['commit']['href'])
|
||||
commit_id = re.match('.*/commit/(?P<commit_id>[A-Za-z0-9]*$)',
|
||||
payload['commit_status']['links']['commit']['href'])
|
||||
if commit_id:
|
||||
commit_info = "{}/{}".format(get_repository_url(payload['repository']), commit_id.group('commit_id'))
|
||||
commit_info = "{}/{}".format(get_repository_url(payload['repository']),
|
||||
commit_id.group('commit_id'))
|
||||
else:
|
||||
commit_info = 'commit'
|
||||
|
||||
@@ -340,6 +343,8 @@ GET_SINGLE_MESSAGE_BODY_DEPENDING_ON_TYPE_MAPPER = {
|
||||
'pull_request_fulfilled': partial(get_pull_request_action_body, action='merged'),
|
||||
'pull_request_rejected': partial(get_pull_request_action_body, action='rejected'),
|
||||
'pull_request_comment_created': get_pull_request_comment_created_action_body,
|
||||
'pull_request_comment_updated': partial(get_pull_request_deleted_or_updated_comment_action_body, action='updated'),
|
||||
'pull_request_comment_deleted': partial(get_pull_request_deleted_or_updated_comment_action_body, action='deleted')
|
||||
'pull_request_comment_updated': partial(get_pull_request_deleted_or_updated_comment_action_body,
|
||||
action='updated'),
|
||||
'pull_request_comment_deleted': partial(get_pull_request_deleted_or_updated_comment_action_body,
|
||||
action='deleted')
|
||||
}
|
||||
|
||||
@@ -120,7 +120,8 @@ def api_github_v1(user_profile: UserProfile,
|
||||
"""
|
||||
commit_stream = stream
|
||||
issue_stream = 'issues'
|
||||
return api_github_v2(user_profile, event, payload, branches, stream, commit_stream, issue_stream, **kwargs)
|
||||
return api_github_v2(user_profile, event, payload, branches,
|
||||
stream, commit_stream, issue_stream, **kwargs)
|
||||
|
||||
|
||||
def api_github_v2(user_profile, event, payload, branches, default_stream,
|
||||
|
||||
@@ -93,7 +93,9 @@ class LibratoWebhookHandler(LibratoWebhookParser):
|
||||
trigger_time = datetime.fromtimestamp((self.payload['trigger_time']),
|
||||
tz=timezone_utc).strftime('%Y-%m-%d %H:%M:%S')
|
||||
alert_id, alert_name, alert_url, alert_runbook_url = self.parse_alert()
|
||||
content = alert_clear_template.format(alert_name=alert_name, alert_url=alert_url, trigger_time=trigger_time)
|
||||
content = alert_clear_template.format(alert_name=alert_name,
|
||||
alert_url=alert_url,
|
||||
trigger_time=trigger_time)
|
||||
return content
|
||||
|
||||
def handle_snapshots(self) -> Text:
|
||||
|
||||
@@ -39,9 +39,10 @@ def build_pagerduty_formatdict(message: Dict[str, Any]) -> Dict[str, Any]:
|
||||
|
||||
# This key can be missing on null
|
||||
if message['data']['incident'].get('assigned_to_user', None):
|
||||
format_dict['assigned_to_email'] = message['data']['incident']['assigned_to_user']['email']
|
||||
format_dict['assigned_to_username'] = message['data']['incident']['assigned_to_user']['email'].split('@')[0]
|
||||
format_dict['assigned_to_url'] = message['data']['incident']['assigned_to_user']['html_url']
|
||||
assigned_to_user = message['data']['incident']['assigned_to_user']
|
||||
format_dict['assigned_to_email'] = assigned_to_user['email']
|
||||
format_dict['assigned_to_username'] = assigned_to_user['email'].split('@')[0]
|
||||
format_dict['assigned_to_url'] = assigned_to_user['html_url']
|
||||
else:
|
||||
format_dict['assigned_to_email'] = 'nobody'
|
||||
format_dict['assigned_to_username'] = 'nobody'
|
||||
@@ -49,9 +50,10 @@ def build_pagerduty_formatdict(message: Dict[str, Any]) -> Dict[str, Any]:
|
||||
|
||||
# This key can be missing on null
|
||||
if message['data']['incident'].get('resolved_by_user', None):
|
||||
format_dict['resolved_by_email'] = message['data']['incident']['resolved_by_user']['email']
|
||||
format_dict['resolved_by_username'] = message['data']['incident']['resolved_by_user']['email'].split('@')[0]
|
||||
format_dict['resolved_by_url'] = message['data']['incident']['resolved_by_user']['html_url']
|
||||
resolved_by_user = message['data']['incident']['resolved_by_user']
|
||||
format_dict['resolved_by_email'] = resolved_by_user['email']
|
||||
format_dict['resolved_by_username'] = resolved_by_user['email'].split('@')[0]
|
||||
format_dict['resolved_by_url'] = resolved_by_user['html_url']
|
||||
else:
|
||||
format_dict['resolved_by_email'] = 'nobody'
|
||||
format_dict['resolved_by_username'] = 'nobody'
|
||||
|
||||
@@ -14,7 +14,8 @@ import ujson
|
||||
|
||||
|
||||
PINGDOM_SUBJECT_TEMPLATE = '{name} status.'
|
||||
PINGDOM_MESSAGE_TEMPLATE = 'Service {service_url} changed its {type} status from {previous_state} to {current_state}.'
|
||||
PINGDOM_MESSAGE_TEMPLATE = ('Service {service_url} changed its {type} status'
|
||||
' from {previous_state} to {current_state}.')
|
||||
PINGDOM_MESSAGE_DESCRIPTION_TEMPLATE = 'Description: {description}.'
|
||||
|
||||
|
||||
|
||||
@@ -131,7 +131,8 @@ def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile,
|
||||
for change in changes:
|
||||
comment = extract_comment(change)
|
||||
if comment is not None:
|
||||
content += "%s added a comment to %s:\n~~~quote\n%s\n~~~" % (performed_by, story_info, comment)
|
||||
content += "%s added a comment to %s:\n~~~quote\n%s\n~~~" % (
|
||||
performed_by, story_info, comment)
|
||||
elif event_type == "story_create_activity":
|
||||
content += "%s created %s: %s\n" % (performed_by, story_type, story_info)
|
||||
for change in changes:
|
||||
@@ -146,7 +147,8 @@ def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile,
|
||||
old_values = change.get("original_values", {})
|
||||
new_values = change["new_values"]
|
||||
if "current_state" in old_values and "current_state" in new_values:
|
||||
content += " from **%s** to **%s**" % (old_values["current_state"], new_values["current_state"])
|
||||
content += " from **%s** to **%s**" % (old_values["current_state"],
|
||||
new_values["current_state"])
|
||||
elif event_type in ["task_create_activity", "comment_delete_activity",
|
||||
"task_delete_activity", "task_update_activity",
|
||||
"story_move_from_project_activity", "story_delete_activity",
|
||||
|
||||
@@ -39,7 +39,11 @@ def api_stripe_webhook(request, user_profile,
|
||||
rest = "created"
|
||||
verb = 'is'
|
||||
|
||||
body = body_template.format(amount=amount_string, rest=rest, verb=verb, charge=charge_id, link=link)
|
||||
body = body_template.format(amount=amount_string,
|
||||
rest=rest,
|
||||
verb=verb,
|
||||
charge=charge_id,
|
||||
link=link)
|
||||
|
||||
else:
|
||||
charge_id = data_object["id"]
|
||||
@@ -83,7 +87,8 @@ def api_stripe_webhook(request, user_profile,
|
||||
# https://stripe.com/docs/api/python#event_types, but do the
|
||||
# computation just to be safe.
|
||||
days_left = int((data_object["trial_end"] - time.time() + DAY//2) // DAY)
|
||||
body_template = "The customer subscription trial with id **[{id}]({link})** will end in {days} days."
|
||||
body_template = ("The customer subscription trial with id"
|
||||
" **[{id}]({link})** will end in {days} days.")
|
||||
body = body_template.format(id=object_id, link=link, days=days_left)
|
||||
|
||||
else:
|
||||
@@ -131,7 +136,11 @@ def api_stripe_webhook(request, user_profile,
|
||||
beginning = "The"
|
||||
end = "been updated"
|
||||
|
||||
body = body_template.format(beginning=beginning, id=object_id, link=link, amount=amount_string, end=end)
|
||||
body = body_template.format(beginning=beginning,
|
||||
id=object_id,
|
||||
link=link,
|
||||
amount=amount_string,
|
||||
end=end)
|
||||
|
||||
if topic is None:
|
||||
topic = "Order {}".format(object_id)
|
||||
|
||||
@@ -73,8 +73,9 @@ def api_teamcity_webhook(request, user_profile, payload=REQ(argument_type='body'
|
||||
|
||||
# Check if this is a personal build, and if so try to private message the user who triggered it.
|
||||
if get_teamcity_property_value(message['teamcityProperties'], 'env.BUILD_IS_PERSONAL') == 'true':
|
||||
# The triggeredBy field gives us the teamcity user full name, and the "teamcity.build.triggeredBy.username"
|
||||
# property gives us the teamcity username. Let's try finding the user email from both.
|
||||
# The triggeredBy field gives us the teamcity user full name, and the
|
||||
# "teamcity.build.triggeredBy.username" property gives us the teamcity username.
|
||||
# Let's try finding the user email from both.
|
||||
teamcity_fullname = message['triggeredBy'].split(';')[0]
|
||||
teamcity_user = guess_zulip_user_from_teamcity(teamcity_fullname, user_profile.realm)
|
||||
|
||||
@@ -86,8 +87,8 @@ def api_teamcity_webhook(request, user_profile, payload=REQ(argument_type='body'
|
||||
|
||||
if teamcity_user is None:
|
||||
# We can't figure out who started this build - there's nothing we can do here.
|
||||
logging.info("Teamcity webhook couldn't find a matching Zulip user for Teamcity user '%s' or '%s'" % (
|
||||
teamcity_fullname, teamcity_shortname))
|
||||
logging.info("Teamcity webhook couldn't find a matching Zulip user for "
|
||||
"Teamcity user '%s' or '%s'" % (teamcity_fullname, teamcity_shortname))
|
||||
return json_success()
|
||||
|
||||
body = "Your personal build of " + body
|
||||
|
||||
@@ -77,7 +77,8 @@ def fill_appropriate_message_content(payload: Mapping[str, Any],
|
||||
return message_body.format(**data)
|
||||
|
||||
def get_filled_board_url_template(payload: Mapping[str, Any]) -> Text:
|
||||
return TRELLO_BOARD_URL_TEMPLATE.format(board_name=get_board_name(payload), board_url=get_board_url(payload))
|
||||
return TRELLO_BOARD_URL_TEMPLATE.format(board_name=get_board_name(payload),
|
||||
board_url=get_board_url(payload))
|
||||
|
||||
def get_board_name(payload: Mapping[str, Any]) -> Text:
|
||||
return get_action_data(payload)['board']['name']
|
||||
|
||||
Reference in New Issue
Block a user