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

integrations: Remove !avatar from git and game handler. #649

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 24 additions & 13 deletions zulip/integrations/git/post-receive
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import os.path

sys.path.insert(0, os.path.dirname(__file__))
import zulip_git_config as config

VERSION = "0.9"
EMPTY_SHA = "0000000000000000000000000000000000000000"
COMMIT_ROW_TEMPLATE = '* {author_name} commited {subject} ([{commit_short_hash}]({commit_url}))\n'

if config.ZULIP_API_PATH is not None:
sys.path.append(config.ZULIP_API_PATH)
Expand All @@ -37,15 +40,26 @@ def git_repository_name() -> Text:
return os.path.basename(os.path.dirname(os.getcwd()))

def git_commit_range(oldrev: str, newrev: str) -> str:
remote_repo_cmd = ["git", "config", "--get", "remote.origin.url"]
remote_repo_url = subprocess.check_output(remote_repo_cmd).strip().decode("utf-8")

log_cmd = ["git", "log", "--reverse",
"--pretty=%aE %H %s", "%s..%s" % (oldrev, newrev)]
"--pretty=%aN%n%H%n%h%n%s", "%s..%s" % (oldrev, newrev)]
commits = ''
for ln in subprocess.check_output(log_cmd, universal_newlines=True).splitlines():
author_email, commit_id, subject = ln.split(None, 2)
if hasattr(config, "format_commit_message"):
commits += config.format_commit_message(author_email, subject, commit_id)
else:
commits += '!avatar(%s) %s\n' % (author_email, subject)
output = subprocess.check_output(log_cmd, universal_newlines=True).splitlines()
it = iter(output)
for _ in range(len(output)//4):
author_name = next(iter(it))
commit_hash = next(iter(it))
commit_short_hash = next(iter(it))
subject = next(iter(it))
commits += COMMIT_ROW_TEMPLATE.format(
author_name=author_name,
commit_short_hash=commit_short_hash,
subject=subject,
commit_url="{}/commit/{}".format(remote_repo_url, commit_hash)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the formatting, I think it'd be better to actually match the format in https://chat.zulip.org/#narrow/stream/8-commits/topic/zulip.20.2F.20master/near/1121032. Is there a reason you went with a different style?


return commits

def send_bot_message(oldrev: str, newrev: str, refname: str) -> None:
Expand All @@ -59,20 +73,17 @@ def send_bot_message(oldrev: str, newrev: str, refname: str) -> None:
new_head = newrev[:12]
old_head = oldrev[:12]

if (
oldrev == '0000000000000000000000000000000000000000'
or newrev == '0000000000000000000000000000000000000000'
):
if oldrev == EMPTY_SHA or newrev == EMPTY_SHA:
# New branch pushed or old branch removed
added = ''
removed = ''
else:
added = git_commit_range(oldrev, newrev)
removed = git_commit_range(newrev, oldrev)

if oldrev == '0000000000000000000000000000000000000000':
if oldrev == EMPTY_SHA:
message = '`%s` was pushed to new branch `%s`' % (new_head, branch)
elif newrev == '0000000000000000000000000000000000000000':
elif newrev == EMPTY_SHA:
message = 'branch `%s` was removed (was `%s`)' % (branch, old_head)
elif removed:
message = '`%s` was pushed to `%s`, **REMOVING**:\n\n%s' % (new_head, branch, removed)
Expand Down
8 changes: 0 additions & 8 deletions zulip/integrations/git/zulip_git_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ def commit_notice_destination(repo: Text, branch: Text, commit: Text) -> Optiona
# Return None for cases where you don't want a notice sent
return None

# Modify this function to change how commits are displayed; the most
# common customization is to include a link to the commit in your
# graphical repository viewer, e.g.
#
# return '!avatar(%s) [%s](https://example.com/commits/%s)\n' % (author, subject, commit_id)
def format_commit_message(author: Text, subject: Text, commit_id: Text) -> Text:
return '!avatar(%s) %s\n' % (author, subject)

## If properly installed, the Zulip API should be in your import
## path, but if not, set a custom path below
ZULIP_API_PATH = None
Expand Down