integration: Refactor get_issue_event_message to use kwarg.

Previously, some call sites for the function provided optional
arguments as positional arguments. These changes will allow the
arguments to be passed as keyword arguments to the function and
fix up the call sites of the function to pass keyword arguments
instead.
This commit is contained in:
Joelute
2023-03-16 15:36:47 -04:00
committed by Tim Abbott
parent a2c578e84d
commit a2a9e53423
5 changed files with 42 additions and 37 deletions

View File

@@ -235,6 +235,7 @@ def get_pull_request_event_message(
def get_issue_event_message(
*,
user_name: str,
action: str,
url: str,

View File

@@ -322,12 +322,12 @@ def get_issue_action_body(payload: WildValue, action: str, include_title: bool)
message = issue["content"]["raw"].tame(check_string)
return get_issue_event_message(
get_actor_info(payload),
action,
issue["links"]["html"]["href"].tame(check_string),
issue["id"].tame(check_int),
message,
assignee,
user_name=get_actor_info(payload),
action=action,
url=issue["links"]["html"]["href"].tame(check_string),
number=issue["id"].tame(check_int),
message=message,
assignee=assignee,
title=issue["title"].tame(check_string) if include_title else None,
)

View File

@@ -161,11 +161,11 @@ def get_issue_body(helper: Helper) -> str:
issue = payload["issue"]
assignee = issue["assignee"]
return get_issue_event_message(
get_sender_name(payload),
action,
issue["html_url"].tame(check_string),
issue["number"].tame(check_int),
issue["body"].tame(check_none_or(check_string)),
user_name=get_sender_name(payload),
action=action,
url=issue["html_url"].tame(check_string),
number=issue["number"].tame(check_int),
message=issue["body"].tame(check_none_or(check_string)),
assignee=assignee["login"].tame(check_string) if assignee else None,
title=issue["title"].tame(check_string) if include_title else None,
)
@@ -185,11 +185,11 @@ def get_issue_comment_body(helper: Helper) -> str:
action += "({}) on".format(comment["html_url"].tame(check_string))
return get_issue_event_message(
get_sender_name(payload),
action,
issue["html_url"].tame(check_string),
issue["number"].tame(check_int),
comment["body"].tame(check_string),
user_name=get_sender_name(payload),
action=action,
url=issue["html_url"].tame(check_string),
number=issue["number"].tame(check_int),
message=comment["body"].tame(check_string),
title=issue["title"].tame(check_string) if include_title else None,
)

View File

@@ -95,11 +95,11 @@ def get_issue_created_event_body(payload: WildValue, include_title: bool) -> str
stringified_description = None
return get_issue_event_message(
get_issue_user_name(payload),
"created",
get_object_url(payload),
payload["object_attributes"]["iid"].tame(check_int),
stringified_description,
user_name=get_issue_user_name(payload),
action="created",
url=get_object_url(payload),
number=payload["object_attributes"]["iid"].tame(check_int),
message=stringified_description,
assignees=replace_assignees_username_with_name(get_assignees(payload)),
title=payload["object_attributes"]["title"].tame(check_string) if include_title else None,
)
@@ -107,10 +107,10 @@ def get_issue_created_event_body(payload: WildValue, include_title: bool) -> str
def get_issue_event_body(payload: WildValue, action: str, include_title: bool) -> str:
return get_issue_event_message(
get_issue_user_name(payload),
action,
get_object_url(payload),
payload["object_attributes"]["iid"].tame(check_int),
user_name=get_issue_user_name(payload),
action=action,
url=get_object_url(payload),
number=payload["object_attributes"]["iid"].tame(check_int),
title=payload["object_attributes"]["title"].tame(check_string) if include_title else None,
)
@@ -159,8 +159,12 @@ def get_merge_request_open_or_updated_body(
action=action,
url=pull_request["url"].tame(check_string),
number=pull_request["iid"].tame(check_int),
target_branch=pull_request["source_branch"].tame(check_string) if action == "created" else None,
base_branch=pull_request["target_branch"].tame(check_string) if action == "created" else None,
target_branch=pull_request["source_branch"].tame(check_string)
if action == "created"
else None,
base_branch=pull_request["target_branch"].tame(check_string)
if action == "created"
else None,
message=pull_request["description"].tame(check_string),
assignees=replace_assignees_username_with_name(get_assignees(payload)),
type="MR",

View File

@@ -100,11 +100,11 @@ def format_issues_event(payload: WildValue, include_title: bool = False) -> str:
issue_nr = payload["issue"]["number"].tame(check_int)
assignee = payload["issue"]["assignee"]
return get_issue_event_message(
payload["sender"]["login"].tame(check_string),
payload["action"].tame(check_string),
get_issue_url(payload["repository"]["html_url"].tame(check_string), issue_nr),
issue_nr,
payload["issue"]["body"].tame(check_string),
user_name=payload["sender"]["login"].tame(check_string),
action=payload["action"].tame(check_string),
url=get_issue_url(payload["repository"]["html_url"].tame(check_string), issue_nr),
number=issue_nr,
message=payload["issue"]["body"].tame(check_string),
assignee=assignee["login"].tame(check_string) if assignee else None,
title=payload["issue"]["title"].tame(check_string) if include_title else None,
)
@@ -122,13 +122,13 @@ def format_issue_comment_event(payload: WildValue, include_title: bool = False)
action += "({}) on".format(comment["html_url"].tame(check_string))
return get_issue_event_message(
payload["sender"]["login"].tame(check_string),
action,
get_issue_url(
user_name=payload["sender"]["login"].tame(check_string),
action=action,
url=get_issue_url(
payload["repository"]["html_url"].tame(check_string), issue["number"].tame(check_int)
),
issue["number"].tame(check_int),
comment["body"].tame(check_string),
number=issue["number"].tame(check_int),
message=comment["body"].tame(check_string),
title=issue["title"].tame(check_string) if include_title else None,
)