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

Conversation

ahmedabuamra
Copy link
Collaborator

@ahmedabuamra ahmedabuamra commented Feb 5, 2021

Fixes: #632

Message content example (on my forked repo.):
image

Please note this sample is generated with input:
5f81eb3a7071fa0dfc20335d01ad889edca27f4e e995e52896a9fa93678eedb777d6d63927913bb5 refs/heads/master

which formatting output of:
git log --reverse --pretty=%aN%n%H%n%h%n%s 5f81eb3a7071fa0dfc20335d01ad889edca27f4e..e995e52896a9fa93678eedb777d6d63927913bb5

The issue linked to this commit suggest suggests to replace the avatar with the
username only, I just needed to remove !avatar as the code already shows username.

Fixes: zulip#632
@ahmedabuamra ahmedabuamra changed the title integrations: Remove !avatar from git and game handler integrations: Remove !avatar from git and game handler. Feb 5, 2021
Comment on lines 44 to 45
log_cmd = ["git", "log", "--reverse",
"--pretty=%aE %H %s", "%s..%s" % (oldrev, newrev)]
"--pretty=-[AUTHOR]=%aN-[COMMIT]=%H-[SUBJECT]=%s", "%s..%s" % (oldrev, newrev)]
Copy link
Member

Choose a reason for hiding this comment

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

It’d be more robust and simpler to separate with newlines (--pretty=%aN%n%H%n%h%n%s). This can be parsed without any fanfare:

it = subprocess.check_output(log_cmd, universal_newlines=True).splitlines()
for author_name in it:
    commit_hash = next(it)
    commit_short_hash = next(it)
    subject = next(it)
    commits += git.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),
    )

author, commit_sha, subject = git.extract_commit_data(ln)
commits += git.COMMIT_ROW_TEMPLATE.format(
user_name=author,
commit_short_sha=commit_sha[:7],
Copy link
Member

Choose a reason for hiding this comment

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

Let Git compute the abbreviation length with %h instead of using a fixed length. In large repositories, it automatically increases the abbreviation length to avoid collisions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@andersk that makes sense, thank you.
I think we need to find a different way for get_short_sha function in this file too in zulip/zulip git webhook.

Copy link
Member

Choose a reason for hiding this comment

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

The webhook has less information since it doesn’t have the repository available to it locally.

commits += '!avatar(%s) %s\n' % (author_email, subject)
author, commit_sha, subject = git.extract_commit_data(ln)
commits += git.COMMIT_ROW_TEMPLATE.format(
user_name=author,
Copy link
Member

Choose a reason for hiding this comment

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

This is an author name, not a username. There’s no reason to rename all the variables passed to the template.

oldrev == '0000000000000000000000000000000000000000'
or newrev == '0000000000000000000000000000000000000000'
):
if (oldrev == git.EMPTY_SHA or newrev == git.EMPTY_SHA):
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary parens.

@ahmedabuamra
Copy link
Collaborator Author

@andersk thank you for your comments! I agree with all of them and will update you once resolved.

…ead.

Getting the logs run in cmd as in function `git_commit_range(oldrev, newrev)`
so I had to prefix author name with -[AUTHOR], commit with -[COMMIT]
and subject/title with -[SUBJECT] to be able to extract these info correctly.

I also tried to stick with the format proposed in this issue
zulip/zulip#3968 except for showing the author's
name before each commit and without summary.

Fixes: zulip#632
commit_short_hash=commit_short_hash,
subject=subject,
commit_url="{}/commit/{}".format(remote_repo_url, commit_hash)
)
Copy link
Sponsor 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?

@timabbott
Copy link
Sponsor Member

This looks pretty good; I merged the first commit as 9ce2ea5 (after updating the commit message to say Fixes part of #632 -- the way you had it would close the issue as soon as the first commit is merged, even if the second wasn't ready yet.

@timabbott
Copy link
Sponsor Member

@ahmedabuamra have you had a chance to resolve the feedback on this?

@ahmedabuamra
Copy link
Collaborator Author

@timabbott I am sorry for not working on it till now. I have had exams from the beginning of this month to yesterday.
I will resolve it as soon as possible. Thank you.

@zulipbot
Copy link
Member

Heads up @ahmedabuamra, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove use of removed !avatar syntax from API bots
4 participants