mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
Add git integrations method to build message for issues events.
This commit is contained in:
@@ -20,10 +20,10 @@ PUSH_COMMITS_MESSAGE_TEMPLATE = u"""{user_name} {pushed_text} to branch {branch_
|
|||||||
FORCE_PUSH_COMMITS_MESSAGE_TEMPLATE = u"{user_name} [force pushed]({url}) to branch {branch_name}. Head is now {head}"
|
FORCE_PUSH_COMMITS_MESSAGE_TEMPLATE = u"{user_name} [force pushed]({url}) to branch {branch_name}. Head is now {head}"
|
||||||
REMOVE_BRANCH_MESSAGE_TEMPLATE = u"{user_name} deleted branch {branch_name}"
|
REMOVE_BRANCH_MESSAGE_TEMPLATE = u"{user_name} deleted branch {branch_name}"
|
||||||
|
|
||||||
PULL_REQUEST_MESSAGE_TEMPLATE = u"{user_name} {action} [{type}]({url})"
|
PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE = u"{user_name} {action} [{type}]({url})"
|
||||||
PULL_REQUEST_ASSIGNEE_INFO_TEMPLATE = u"(assigned to {assignee})"
|
PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE = u"(assigned to {assignee})"
|
||||||
PULL_REQUEST_BRANCH_INFO_TEMPLATE = u"\nfrom `{target}` to `{base}`"
|
PULL_REQUEST_BRANCH_INFO_TEMPLATE = u"\nfrom `{target}` to `{base}`"
|
||||||
PULL_REQUEST_CONTENT_MESSAGE_TEMPLATE = u"\n~~~ quote\n{message}\n~~~"
|
PULL_REQUEST_OR_ISSUE_CONTENT_MESSAGE_TEMPLATE = u"\n~~~ quote\n{message}\n~~~"
|
||||||
|
|
||||||
def get_push_commits_event_message(user_name, compare_url, branch_name, commits_data):
|
def get_push_commits_event_message(user_name, compare_url, branch_name, commits_data):
|
||||||
# type: (text_type, Optional[text_type], text_type, List[Dict[str, Any]]) -> text_type
|
# type: (text_type, Optional[text_type], text_type, List[Dict[str, Any]]) -> text_type
|
||||||
@@ -58,27 +58,38 @@ def get_remove_branch_event_message(user_name, branch_name):
|
|||||||
def get_pull_request_event_message(
|
def get_pull_request_event_message(
|
||||||
user_name, action, url,
|
user_name, action, url,
|
||||||
target_branch=None, base_branch=None,
|
target_branch=None, base_branch=None,
|
||||||
pr_message=None, assignee=None, type='PR'
|
message=None, assignee=None, type='PR'
|
||||||
):
|
):
|
||||||
# type: (text_type, text_type, text_type, Optional[text_type], Optional[text_type], Optional[text_type], Optional[text_type], Optional[text_type]) -> text_type
|
# type: (text_type, text_type, text_type, Optional[text_type], Optional[text_type], Optional[text_type], Optional[text_type], Optional[text_type]) -> text_type
|
||||||
main_message = PULL_REQUEST_MESSAGE_TEMPLATE.format(
|
main_message = PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE.format(
|
||||||
user_name=user_name,
|
user_name=user_name,
|
||||||
action=action,
|
action=action,
|
||||||
type=type,
|
type=type,
|
||||||
url=url
|
url=url
|
||||||
)
|
)
|
||||||
if assignee:
|
if assignee:
|
||||||
main_message += PULL_REQUEST_ASSIGNEE_INFO_TEMPLATE.format(assignee=assignee)
|
main_message += PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE.format(assignee=assignee)
|
||||||
|
|
||||||
if target_branch and base_branch:
|
if target_branch and base_branch:
|
||||||
main_message += PULL_REQUEST_BRANCH_INFO_TEMPLATE.format(
|
main_message += PULL_REQUEST_BRANCH_INFO_TEMPLATE.format(
|
||||||
target=target_branch,
|
target=target_branch,
|
||||||
base=base_branch
|
base=base_branch
|
||||||
)
|
)
|
||||||
if pr_message:
|
if message:
|
||||||
main_message += '\n' + PULL_REQUEST_CONTENT_MESSAGE_TEMPLATE.format(message=pr_message)
|
main_message += '\n' + PULL_REQUEST_OR_ISSUE_CONTENT_MESSAGE_TEMPLATE.format(message=message)
|
||||||
return main_message.rstrip()
|
return main_message.rstrip()
|
||||||
|
|
||||||
|
def get_issue_event_message(user_name, action, url, message=None, assignee=None):
|
||||||
|
# type: (text_type, text_type, text_type, Optional[text_type], Optional[text_type]) -> text_type
|
||||||
|
return get_pull_request_event_message(
|
||||||
|
user_name,
|
||||||
|
action,
|
||||||
|
url,
|
||||||
|
message=message,
|
||||||
|
assignee=assignee,
|
||||||
|
type='Issue'
|
||||||
|
)
|
||||||
|
|
||||||
def get_commits_content(commits_data):
|
def get_commits_content(commits_data):
|
||||||
# type: (List[Dict[str, Any]]) -> text_type
|
# type: (List[Dict[str, Any]]) -> text_type
|
||||||
commits_content = u''
|
commits_content = u''
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ def get_pull_request_created_or_updated_body(payload, action):
|
|||||||
get_pull_request_url(pull_request),
|
get_pull_request_url(pull_request),
|
||||||
target_branch=pull_request['source']['branch']['name'],
|
target_branch=pull_request['source']['branch']['name'],
|
||||||
base_branch=pull_request['destination']['branch']['name'],
|
base_branch=pull_request['destination']['branch']['name'],
|
||||||
pr_message=pull_request['description'],
|
message=pull_request['description'],
|
||||||
assignee=assignee
|
assignee=assignee
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user