From 8203d81166299bc11c6725c0b56e402d79d51ef9 Mon Sep 17 00:00:00 2001 From: Niloth P <20315308+Niloth-p@users.noreply.github.com> Date: Thu, 3 Jul 2025 04:46:44 +0530 Subject: [PATCH 1/2] codebase: Switch from format() to f-strings. --- .../codebase/zulip_codebase_mirror | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/zulip/integrations/codebase/zulip_codebase_mirror b/zulip/integrations/codebase/zulip_codebase_mirror index ac8840320..2c567327c 100755 --- a/zulip/integrations/codebase/zulip_codebase_mirror +++ b/zulip/integrations/codebase/zulip_codebase_mirror @@ -47,7 +47,7 @@ user_agent = "Codebase To Zulip Mirroring script (zulip-devel@googlegroups.com)" # find some form of JSON loader/dumper, with a preference order for speed. json_implementations = ["ujson", "cjson", "simplejson", "json"] -while len(json_implementations): +while json_implementations: try: json = __import__(json_implementations.pop(0)) break @@ -125,11 +125,8 @@ def handle_event(event: Dict[str, Any]) -> None: else: if new_ref: branch = f"new branch {branch}" - content = "{} pushed {} commit(s) to {} in project {}:\n\n".format( - actor_name, - num_commits, - branch, - project, + content = ( + f"{actor_name} pushed {num_commits} commit(s) to {branch} in project {project}:\n\n" ) for commit in raw_props.get("commits"): ref = commit.get("ref") @@ -162,11 +159,8 @@ def handle_event(event: Dict[str, Any]) -> None: content = "" if body is not None and len(body) > 0: - content = "{} added a comment to ticket [#{}]({}):\n\n~~~ quote\n{}\n\n".format( - actor_name, - num, - url, - body, + content = ( + f"{actor_name} added a comment to ticket [#{num}]({url}):\n\n~~~ quote\n{body}\n\n" ) if "status_id" in changes: @@ -228,15 +222,7 @@ def handle_event(event: Dict[str, Any]) -> None: subject = f"Deployment to {environment}" - content = "{} deployed [{}]({}) [through]({}) [{}]({}) to the **{}** environment.".format( - actor_name, - start_ref, - start_ref_url, - between_url, - end_ref, - end_ref_url, - environment, - ) + content = f"{actor_name} deployed [{start_ref}]({start_ref_url}) [through]({between_url}) [{end_ref}]({end_ref_url}) to the **{environment}** environment." if servers is not None: content += "\n\nServers deployed to: %s" % ( ", ".join(f"`{server}`" for server in servers) From 954fc1bf40256911df7e3e873bedfc2832052187 Mon Sep 17 00:00:00 2001 From: Niloth P <20315308+Niloth-p@users.noreply.github.com> Date: Thu, 3 Jul 2025 04:49:27 +0530 Subject: [PATCH 2/2] codebase: Use backticks for branch names in message templates. --- zulip/integrations/codebase/zulip_codebase_mirror | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/zulip/integrations/codebase/zulip_codebase_mirror b/zulip/integrations/codebase/zulip_codebase_mirror index 2c567327c..6a6aee712 100755 --- a/zulip/integrations/codebase/zulip_codebase_mirror +++ b/zulip/integrations/codebase/zulip_codebase_mirror @@ -121,13 +121,11 @@ def handle_event(event: Dict[str, Any]) -> None: subject = f"Push to {branch} on {project}" if deleted_ref: - content = f"{actor_name} deleted branch {branch} from {project}" + content = f"{actor_name} deleted branch `{branch}` from {project}" else: if new_ref: - branch = f"new branch {branch}" - content = ( - f"{actor_name} pushed {num_commits} commit(s) to {branch} in project {project}:\n\n" - ) + branch = f"new branch `{branch}`" + content = f"{actor_name} pushed {num_commits} commit(s) to `{branch}` in project {project}:\n\n" for commit in raw_props.get("commits"): ref = commit.get("ref") url = make_url(f"projects/{project_link}/repositories/{repo_link}/commit/{ref}")