go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.65k stars 5.45k forks source link

Add GITEA_REPO_MEMBERS_EMAILS env key for hooks #17199

Closed ivptr closed 3 years ago

ivptr commented 3 years ago

Feature Description

It would be nice to add GITEA_REPO_MEMBERS_EMAILS environment key, containing emails of all users having access to repository (collaborators, owners and its team members).

That way it would be possible to send email notifications about commits to all involved parties, as mentioned in #1457.

Screenshots

No response

zeripath commented 3 years ago

Which kind of hook do you mean here? a githook?

wxiaoguang commented 3 years ago

Another question, what is the purpose of "sending email notifications about commits"? In old days people liked to know the committing actions, but as today, the code repository becomes larger and larger, most people do not care about every trivial commit anymore.

I also do not think passing emails via environment is a good idea. Think about you have a large org contains more than a thousand users, the environment will be filled by a lot of emails which are not very useful.

ivptr commented 3 years ago

This feature request is in line with explanation for post-receive Git hook: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks "The post-receive hook runs after the entire process is completed and can be used to update other services or notify users":

I just want to notify all users having access to repository (collaborators, owners and its team members).

Is there another way to fetch such emails if GITEA_REPO_MEMBERS_EMAILS environment key is a no go? Maybe calling /usr/local/bin/gitea using some param?

wxiaoguang commented 3 years ago

Gitea has API: https://try.gitea.io/api/swagger#/repository/repoListCollaborators

ivptr commented 3 years ago

API seems to be overkill for this, it needs ENABLE_SWAGGER enabled and authorization.

Also that lists collaborators only, how about owners and its team members?

Is it possible to get such data using Gitea command line, similar to /usr/local/bin/gitea -c /etc/gitea/app.ini admin user list

noerw commented 3 years ago

I agree that for your use case using the API instead of hardcoded, instance-wide variables is much cleaner.

Exposing this specific env variable is not a reasonable request. What might be an option, is to add a config option with an allow list of env vars on the gitea process that are passed through to git hooks, though I doubt there is much demand for such a feature

ivptr commented 3 years ago

This should be accessible from command line. Also it lacks owners/team members info.

Ended up with SQL queries:

mailingList = [pusher_email]

# Get owner's email when it's not organization
rows_count = cursor.execute("SELECT email FROM repository, user WHERE repository.name = %s AND repository.owner_name = %s AND user.id=repository.owner_id AND user.type=0", (repoName, repoUserName))
records = cursor.fetchall()
for row in records:
    mailingList.append(str(row[0]))

# Get collaborators' emails
rows_count = cursor.execute("SELECT email FROM repository, user, collaboration WHERE repository.name = %s AND repository.owner_name = %s AND collaboration.repo_id=repository.id AND collaboration.user_id=user.id", (repoName, repoUserName))
records = cursor.fetchall()
for row in records:
    mailingList.append(str(row[0]))

# Get organization team members' emails
rows_count = cursor.execute("SELECT email FROM user, team_user WHERE team_user.uid=user.id AND team_user.team_id IN (SELECT team.id FROM repository, user, team WHERE repository.name = %s AND repository.owner_name = %s AND user.id=repository.owner_id AND user.type=1 AND team.org_id=user.id)", (repoName, repoUserName))
records = cursor.fetchall()
for row in records:
    mailingList.append(str(row[0]))
zeripath commented 3 years ago

This is a substantial amount of data that would have to be generated for every single git request. Data that is not used by our hooks and therefore not by every user or repo.

We've been very careful to state that we do not consider the environment variables that Gitea sets for git hooks to represent a form of API and that whilst they have been (relatively) stable we will not promise this and we will not consider changes to them to be breaking. We will not add additional data that we would not use.

Please use the API or add the functionality directly to Gitea where it could be turned off or only used on repos that it is appropriate for.