Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update "stream", "subject" occurrences in the Git integration. #857

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions zulip/integrations/git/post-receive
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions zulip/integrations/git/zulip_git_config.py
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
Expand All @@ -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
Expand Down
Loading