integrations: Add user url for star event in Github Integration.

Fixes #25672.
This commit is contained in:
dhruv302003
2023-06-03 17:35:08 +05:30
committed by Tim Abbott
parent b09a2637c4
commit 67125acaa6
2 changed files with 7 additions and 2 deletions

View File

@@ -25,7 +25,7 @@ class GitHubWebhookTest(WebhookTestCase):
self.check_webhook("ping", TOPIC_REPO, expected_message) self.check_webhook("ping", TOPIC_REPO, expected_message)
def test_star_event(self) -> None: def test_star_event(self) -> None:
expected_message = "Codertocat starred the repository [Codertocat/Hello-World](https://github.com/Codertocat/Hello-World)." expected_message = "[Codertocat](https://github.com/Codertocat) starred the repository [Codertocat/Hello-World](https://github.com/Codertocat/Hello-World)."
expected_topic = "Hello-World" expected_topic = "Hello-World"
self.check_webhook("star", expected_topic, expected_message) self.check_webhook("star", expected_topic, expected_message)

View File

@@ -597,9 +597,10 @@ Check [{name}]({html_url}) {status} ({conclusion}). ([{short_hash}]({commit_url}
def get_star_body(helper: Helper) -> str: def get_star_body(helper: Helper) -> str:
payload = helper.payload payload = helper.payload
template = "{user} {action} the repository [{repo}]({url})." template = "[{user}]({user_url}) {action} the repository [{repo}]({url})."
return template.format( return template.format(
user=payload["sender"]["login"].tame(check_string), user=payload["sender"]["login"].tame(check_string),
user_url=get_sender_url(payload),
action="starred" if payload["action"].tame(check_string) == "created" else "unstarred", action="starred" if payload["action"].tame(check_string) == "created" else "unstarred",
repo=get_repository_full_name(payload), repo=get_repository_full_name(payload),
url=payload["repository"]["html_url"].tame(check_string), url=payload["repository"]["html_url"].tame(check_string),
@@ -627,6 +628,10 @@ def get_sender_name(payload: WildValue) -> str:
return payload["sender"]["login"].tame(check_string) return payload["sender"]["login"].tame(check_string)
def get_sender_url(payload: WildValue) -> str:
return payload["sender"]["html_url"].tame(check_string)
def get_branch_name_from_ref(ref_string: str) -> str: def get_branch_name_from_ref(ref_string: str) -> str:
return re.sub(r"^refs/heads/", "", ref_string) return re.sub(r"^refs/heads/", "", ref_string)