diff --git a/zulip/integrations/git/post-receive b/zulip/integrations/git/post-receive index a07722361..bd50a9ac9 100755 --- a/zulip/integrations/git/post-receive +++ b/zulip/integrations/git/post-receive @@ -31,6 +31,14 @@ client = zulip.Client( client="ZulipGit/" + VERSION, ) +log_file_path = os.path.join(os.path.dirname(__file__), "../post-receive.log") + + +def log_error(message: str) -> None: + print(message, file=sys.stderr) + with open(log_file_path, "a") as log_file: + log_file.write(f"{message}\n") + def git_repository_name() -> str: path, name = os.path.split(os.getcwd()) @@ -90,11 +98,13 @@ def send_bot_message(oldrev: str, newrev: str, refname: str) -> None: message_data = { "type": "stream", - "to": destination["stream"], - "subject": destination["subject"], + "to": destination.get("channel", destination.get("stream")), + "topic": destination.get("topic", destination.get("subject")), "content": message, } - client.send_message(message_data) + response = client.send_message(message_data) + if response["result"] == "error": + log_error(f"Failed to send Zulip message: {response['msg']}") for ln in sys.stdin: diff --git a/zulip/integrations/git/zulip_git_config.py b/zulip/integrations/git/zulip_git_config.py index cb26b2135..bdd2f5d50 100644 --- a/zulip/integrations/git/zulip_git_config.py +++ b/zulip/integrations/git/zulip_git_config.py @@ -1,8 +1,8 @@ # from typing import Dict, Optional -# Name of the stream to send notifications to, default is "commits" -STREAM_NAME = "commits" +# Name of the channel to send notifications to, default is "commits" +CHANNEL_NAME = "commits" # Change these values to configure authentication for the plugin ZULIP_USER = "git-bot@example.com" @@ -17,16 +17,16 @@ # * branch = the name of the branch that was pushed to # * commit = the commit id # -# Returns a dictionary encoding the stream and subject to send the +# Returns a dictionary encoding the channel and topic to send the # notification to (or None to send no notification). # # The default code below will send every commit pushed to "main" to -# * stream "commits" +# * channel "commits" # * topic "main" # And similarly for branch "test-post-receive" (for use when testing). def commit_notice_destination(repo: str, branch: str, commit: str) -> Optional[Dict[str, str]]: if branch in ["main", "master", "test-post-receive"]: - return dict(stream=STREAM_NAME, subject=f"{branch}") + return dict(channel=CHANNEL_NAME, topic=f"{branch}") # Return None for cases where you don't want a notice sent return None