Add is_truncated param to git integrations push commits event.

Add is_truncated param for cases when we know that there were more commits
but we dont know actual number and want just inform about existing of the rest.
This commit is contained in:
Tomasz Kolek 2016-11-09 18:50:10 +01:00 committed by Tim Abbott
parent 81f18b829d
commit ed1d7f7997
1 changed files with 11 additions and 6 deletions

View File

@ -32,8 +32,8 @@ PUSH_TAGS_MESSAGE_TEMPLATE = u"""{user_name} {action} {tag} tag"""
TAG_WITH_URL_TEMPLATE = u"[{tag_name}]({tag_url})"
TAG_WITHOUT_URL_TEMPLATE = u"{tag_name}"
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
def get_push_commits_event_message(user_name, compare_url, branch_name, commits_data, is_truncated=False):
# type: (text_type, Optional[text_type], text_type, List[Dict[str, Any]], Optional[bool]) -> text_type
if compare_url:
pushed_text_message = PUSH_PUSHED_TEXT_WITH_URL.format(compare_url=compare_url)
else:
@ -43,7 +43,7 @@ def get_push_commits_event_message(user_name, compare_url, branch_name, commits_
user_name=user_name,
pushed_text=pushed_text_message,
branch_name=branch_name,
commits_data=get_commits_content(commits_data),
commits_data=get_commits_content(commits_data, is_truncated),
).rstrip()
def get_force_push_commits_event_message(user_name, url, branch_name, head):
@ -125,8 +125,8 @@ def get_commits_comment_action_message(user_name, action, commit_url, sha, messa
)
return content
def get_commits_content(commits_data):
# type: (List[Dict[str, Any]]) -> text_type
def get_commits_content(commits_data, is_truncated=False):
# type: (List[Dict[str, Any]], Optional[bool]) -> text_type
commits_content = u''
for commit in commits_data[:COMMITS_LIMIT]:
commits_content += COMMIT_ROW_TEMPLATE.format(
@ -137,7 +137,12 @@ def get_commits_content(commits_data):
if len(commits_data) > COMMITS_LIMIT:
commits_content += COMMITS_MORE_THAN_LIMIT_TEMPLATE.format(
commits_number=len(commits_data) - COMMITS_LIMIT)
commits_number=len(commits_data) - COMMITS_LIMIT
)
elif is_truncated:
commits_content += COMMITS_MORE_THAN_LIMIT_TEMPLATE.format(
commits_number=''
).replace(' ', ' ')
return commits_content.rstrip()
def get_short_sha(sha):