mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
github_webhook: change double quotes to single quotes for consistency.
This commit is contained in:
@@ -22,20 +22,20 @@ class UnknownEventType(Exception):
|
||||
|
||||
def github_generic_subject(noun, topic_focus, blob):
|
||||
# issue and pull_request objects have the same fields we're interested in
|
||||
return "%s: %s %d: %s" % (topic_focus, noun, blob['number'], blob['title'])
|
||||
return '%s: %s %d: %s' % (topic_focus, noun, blob['number'], blob['title'])
|
||||
|
||||
def github_generic_content(noun, payload, blob):
|
||||
action = 'synchronized' if payload['action'] == 'synchronize' else payload['action']
|
||||
|
||||
# issue and pull_request objects have the same fields we're interested in
|
||||
content = ("%s %s [%s %s](%s)"
|
||||
content = ('%s %s [%s %s](%s)'
|
||||
% (payload['sender']['login'],
|
||||
action,
|
||||
noun,
|
||||
blob['number'],
|
||||
blob['html_url']))
|
||||
if payload['action'] in ('opened', 'reopened'):
|
||||
content += "\n\n~~~ quote\n%s\n~~~" % (blob['body'],)
|
||||
content += '\n\n~~~ quote\n%s\n~~~' % (blob['body'],)
|
||||
return content
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ def api_github_v2(user_profile, event, payload, branches, default_stream, commit
|
||||
|
||||
subject = github_generic_subject(noun, topic_focus, issue)
|
||||
comment = payload['comment']
|
||||
content = ("%s [commented](%s) on [%s %d](%s)\n\n~~~ quote\n%s\n~~~"
|
||||
content = ('%s [commented](%s) on [%s %d](%s)\n\n~~~ quote\n%s\n~~~'
|
||||
% (comment['user']['login'],
|
||||
comment['html_url'],
|
||||
noun,
|
||||
@@ -106,16 +106,16 @@ def api_github_v2(user_profile, event, payload, branches, default_stream, commit
|
||||
created=payload['created'])
|
||||
elif event == 'commit_comment':
|
||||
comment = payload['comment']
|
||||
subject = "%s: commit %s" % (topic_focus, comment['commit_id'])
|
||||
subject = '%s: commit %s' % (topic_focus, comment['commit_id'])
|
||||
|
||||
content = ("%s [commented](%s)"
|
||||
content = ('%s [commented](%s)'
|
||||
% (comment['user']['login'],
|
||||
comment['html_url']))
|
||||
|
||||
if comment['line'] is not None:
|
||||
content += " on `%s`, line %d" % (comment['path'], comment['line'])
|
||||
content += ' on `%s`, line %d' % (comment['path'], comment['line'])
|
||||
|
||||
content += "\n\n~~~ quote\n%s\n~~~" % (comment['body'],)
|
||||
content += '\n\n~~~ quote\n%s\n~~~' % (comment['body'],)
|
||||
|
||||
else:
|
||||
raise UnknownEventType(u'Event %s is unknown and cannot be handled' % (event,))
|
||||
@@ -155,14 +155,14 @@ def api_github_landing(request, user_profile, event=REQ,
|
||||
'exclude_commits': exclude_commits,
|
||||
'emphasize_branch_in_topic': emphasize_branch_in_topic,
|
||||
}))
|
||||
f.write("\n")
|
||||
f.write('\n')
|
||||
except Exception:
|
||||
logging.exception("Error while capturing Github event")
|
||||
logging.exception('Error while capturing Github event')
|
||||
|
||||
if not stream:
|
||||
stream = 'commits'
|
||||
|
||||
short_ref = re.sub(r'^refs/heads/', '', payload.get('ref', ""))
|
||||
short_ref = re.sub(r'^refs/heads/', '', payload.get('ref', ''))
|
||||
kwargs = dict()
|
||||
|
||||
if emphasize_branch_in_topic and short_ref:
|
||||
@@ -173,12 +173,12 @@ def api_github_landing(request, user_profile, event=REQ,
|
||||
allowed_events.add('pull_request')
|
||||
|
||||
if not exclude_issues:
|
||||
allowed_events.add("issues")
|
||||
allowed_events.add("issue_comment")
|
||||
allowed_events.add('issues')
|
||||
allowed_events.add('issue_comment')
|
||||
|
||||
if not exclude_commits:
|
||||
allowed_events.add("push")
|
||||
allowed_events.add("commit_comment")
|
||||
allowed_events.add('push')
|
||||
allowed_events.add('commit_comment')
|
||||
|
||||
if event not in allowed_events:
|
||||
return json_success()
|
||||
@@ -199,19 +199,19 @@ def api_github_landing(request, user_profile, event=REQ,
|
||||
else:
|
||||
target_stream, subject, content = api_github_v1(user_profile, event, payload, branches, stream, **kwargs)
|
||||
|
||||
request.client = get_client("ZulipGitHubWebhook")
|
||||
request.client = get_client('ZulipGitHubWebhook')
|
||||
return send_message_backend(request, user_profile,
|
||||
message_type_name="stream",
|
||||
message_type_name='stream',
|
||||
message_to=[target_stream],
|
||||
forged=False, subject_name=subject,
|
||||
message_content=content)
|
||||
|
||||
def build_commit_list_content(commits, branch, compare_url, pusher):
|
||||
if compare_url is not None:
|
||||
push_text = "[pushed](%s)" % (compare_url,)
|
||||
push_text = '[pushed](%s)' % (compare_url,)
|
||||
else:
|
||||
push_text = "pushed"
|
||||
content = ("%s %s to branch %s\n\n"
|
||||
push_text = 'pushed'
|
||||
content = ('%s %s to branch %s\n\n'
|
||||
% (pusher,
|
||||
push_text,
|
||||
branch))
|
||||
@@ -219,11 +219,11 @@ def build_commit_list_content(commits, branch, compare_url, pusher):
|
||||
truncated_commits = commits[:COMMITS_IN_LIST_LIMIT]
|
||||
for commit in truncated_commits:
|
||||
short_id = commit['id'][:7]
|
||||
(short_commit_msg, _, _) = commit['message'].partition("\n")
|
||||
content += "* [%s](%s): %s\n" % (short_id, commit['url'],
|
||||
(short_commit_msg, _, _) = commit['message'].partition('\n')
|
||||
content += '* [%s](%s): %s\n' % (short_id, commit['url'],
|
||||
short_commit_msg)
|
||||
if num_commits > COMMITS_IN_LIST_LIMIT:
|
||||
content += ("\n[and %d more commits]"
|
||||
content += ('\n[and %d more commits]'
|
||||
% (num_commits - COMMITS_IN_LIST_LIMIT,))
|
||||
|
||||
return content
|
||||
@@ -233,11 +233,11 @@ def build_message_from_gitlog(user_profile, name, ref, commits, before, after, u
|
||||
subject = name
|
||||
|
||||
if re.match(r'^0+$', after):
|
||||
content = "%s deleted branch %s" % (pusher,
|
||||
content = '%s deleted branch %s' % (pusher,
|
||||
short_ref)
|
||||
# 'created' and 'forced' are github flags; the second check is for beanstalk
|
||||
elif (forced and not created) or (forced is None and len(commits) == 0):
|
||||
content = ("%s [force pushed](%s) to branch %s. Head is now %s"
|
||||
content = ('%s [force pushed](%s) to branch %s. Head is now %s'
|
||||
% (pusher,
|
||||
url,
|
||||
short_ref,
|
||||
|
||||
Reference in New Issue
Block a user