Git hook 用于发送有关存储库更改的电子邮件通知

发布于 2024-07-13 12:45:53 字数 48 浏览 9 评论 0 原文

如何配置适当的 Git 挂钩,以便在将一组更改推送到上游存储库时发送摘要电子邮件?

How do I configure the appropriate Git hook to send a summary email whenever a set of changes is pushed to the upstream repository?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

傲性难收 2024-07-20 12:45:53

另一种更现代的方法是使用 git-multimail,如 < a href="https://stackoverflow.com/questions/552360/git-push-email-notification/552362?noredirect=1#comment29250514_552362">和弦如下。


这就是你在 2009 年所做的。

你可以添加类似 this 到 $GITDIR/hooks 中的 post-receive 挂钩,或者使用源 (可在此处获取)

Another, more modern way to do this is with git-multimail, as suggested by Chords below.


This is how you did it in 2009.

You could add something like this to your post-receive hook in $GITDIR/hooks, or use the script in the contrib directory of the source (Available here)

故事未完 2024-07-20 12:45:53

这是我找到的最简单的解决方案:

1) 在 github.com 上登录您的 gitHub 帐户

2) 在 main 中选项卡上单击设置

3) 从主导航中选择服务挂钩

4) 从可用挂钩中选择电子邮件

5) 在地址字段中填写您的电子邮件地址>

6) 选中从作者发送复选框

7) 选中活动复选框

8) 单击更新设置

可选:您可以单击 >测试挂钩进行测试,检查您的收件箱,您应该会收到电子邮件。

还有根据该过程制作的图像:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

现在对于总决赛,我已经得到了经过测试和批准的答案。

当 gitHub 的 Service Hooks->Email 最多只允许 2 个收件人时,如何向所有开发团队成员发送电子邮件}

答案是Service Hook->Email@GitHub &>的组合 Google 网上论坛

  1. 首先登录您的 Google 帐户
  2. 转至 Google 网上论坛,然后点击顶部的 创建群组
  3. 输入群组名称、群组电子邮件地址(将复制/粘贴到 GitHub
    服务挂钩 -> 电子邮件地址),组描述
  4. 点击顶部的“创建”按钮后,您的新组应该是
    立即创建
  5. 之后,在左侧菜单中点击邀请成员并输入
    在您团队成员的电子邮件地址中,
  6. 然后点击发送邀请(当您的成员接受
    邀请)他们现在是该组的正式成员
  7. 在左侧菜单中单击所有成员并选中第四个
    名为交付的列,每个团队成员都应该有选择
    所有电子邮件
  8. 之后我想感谢先生。 克莱门特·埃科菲和
    请遵循他的指南@ Clement Escoffier::Send Github 向 Google Group 提交有关如何
    完成它。 {谢谢克莱门特:)}
  9. 如果链接不可用,这里是我的 gDocs @ 的另一个链接
    PDF 版 Clements 指南

Here is the simplest solution I've found:

1) Log in to your gitHub account on github.com

2) In the main tab click on Settings

3) From the main navigation choose Service Hooks

4) From Available Hooks choose Email

5) Fill in your email address in field Address

6) Check the checkbox Send from Author

7) Check the checkbox Active

8) Click on Update Settings

Optional: You can click on Test Hook for testing, check your inbox you should receive email.

Also there are images made according to the process:

enter image description here

enter image description here

enter image description here

enter image description here

And now for the grand final I have the answer which is tested and approved at my side.

How to send email to ALL development team members, when gitHub's Service Hooks->Email allows only at most 2 recipients }.

The answer is combination of Service Hook->Email @ GitHub && Google groups

  1. First login to your google account
  2. Go to Google Groups and at the top click on Create Group
  3. Type in Group Name, Group email address (will copy/paste into GitHub
    Service Hook->Email Address), Group description
  4. After that hit Create button at the top, your new group should be
    created now
  5. After that in the menu to the left hit Invite members and type
    in the email addresses of your team mates
  6. After that hit Send invites (when your members accept
    invitation) they are now formally members of this group
  7. In the menu on the left click on All Members and check the 4th
    column called Delivery, every team member should have option
    All Email.
  8. After that I would like to credit Mr. Clement Escoffier and
    please do follow his guidelines @ Clement Escoffier::Send Github commits to a Google Group on how to
    finish it. {Thank you Clement :)}
  9. If the link becomes unavailable here is another link to my gDocs @
    PDF version of Clements guide
披肩女神 2024-07-20 12:45:53

这是我每次有人推送到存储库时向用户发送电子邮件通知的方式。

设置 Git 提交电子邮件通知

它基于安迪·帕金斯的剧本。 我将其更改为使用 SMTP 发送电子邮件。 当然也可以使用gmail的SMTP。

This is my way of send email notification to users every time some one push to the repository.

Setting Up Git Commit Email Notification

It's based on Andy Parkins's scripts. I change it to used SMTP to send email. Of course, gmail's SMTP can also be used.

じее 2024-07-20 12:45:53

罗宾·索默git-notifier 还生成以下格式的非常好的摘要:

Subject: [git/git-notifier] master: Adding www target to Makefile. (7dc1f95)

Repository : ssh://<removed>/git-notifier

On branch  : master

>---------------------------------------------------------------

commit 7dc1f95c97275618d5bde1aaf6760cd7ff6a6ef7
Author: Robin Sommer <[email protected]>
Date:   Sun Dec 19 20:21:38 2010 -0800

    Adding www target to Makefile.

>---------------------------------------------------------------

 Makefile |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index e184c66..9c9951b 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,8 @@ VERSION   = 0.1

 DISTFILES = git-notifier README COPYING

+WWW = $(HOME)/www/git-notifier
+
 all:

 dist:
@@ -13,3 +15,7 @@ dist:
    cp $(DISTFILES) git-notifier-$(VERSION)
    tar czvf git-notifier-$(VERSION).tgz git-notifier-$(VERSION)
    rm -rf git-notifier-$(VERSION)
+
+www: dist
+   rst2html.py README >$(WWW)/index.html
+   cp git-notifier-$(VERSION).tgz $(WWW)

Robin Sommer's git-notifier generates also very nice summaries in the following format:

Subject: [git/git-notifier] master: Adding www target to Makefile. (7dc1f95)

Repository : ssh://<removed>/git-notifier

On branch  : master

>---------------------------------------------------------------

commit 7dc1f95c97275618d5bde1aaf6760cd7ff6a6ef7
Author: Robin Sommer <[email protected]>
Date:   Sun Dec 19 20:21:38 2010 -0800

    Adding www target to Makefile.

>---------------------------------------------------------------

 Makefile |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index e184c66..9c9951b 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,8 @@ VERSION   = 0.1

 DISTFILES = git-notifier README COPYING

+WWW = $(HOME)/www/git-notifier
+
 all:

 dist:
@@ -13,3 +15,7 @@ dist:
    cp $(DISTFILES) git-notifier-$(VERSION)
    tar czvf git-notifier-$(VERSION).tgz git-notifier-$(VERSION)
    rm -rf git-notifier-$(VERSION)
+
+www: dist
+   rst2html.py README >$(WWW)/index.html
+   cp git-notifier-$(VERSION).tgz $(WWW)
初懵 2024-07-20 12:45:53

设置 hooks.showrev 没有产生明显的区别吗? :-/

示例配置:

# less users/cj.git/config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
[hooks]
        mailinglist = [email protected]
        showrev = "git show -C %s; echo"
        emailprefix = "[sabu gitosis server] "

setting hooks.showrev is making no distinguishable difference? :-/

Sample conf:

# less users/cj.git/config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
[hooks]
        mailinglist = [email protected]
        showrev = "git show -C %s; echo"
        emailprefix = "[sabu gitosis server] "
晨光如昨 2024-07-20 12:45:53

我设法做到了这一点,但不得不选择使用 contrib 脚本,而不是 Alexandre Julliard 的其他(perl)脚本。 它看起来更奇特并且更可配置,但是使用 postfix 我没有可以接受“-s”的邮件命令? 这是我的方式:

http://pastie.textmate.org/695323

展示一些会很高兴更多信息,如完整补丁、gitweb 链接和提交图,但这个脚本只能执行第一个 - 如果我使用 hooks.showrev 似乎。

无论如何,干杯并感谢您的建议!

I managed to do this, but had to opt for using the contrib script, not the other (perl) script by Alexandre Julliard. It seems fancier and more configurable, but with postfix I had no mail command which would accept "-s"? Here's my way:

http://pastie.textmate.org/695323

It would be nice to show some more info, like the full patch, gitweb link and commit graph as well, but this script can only do the first - if I play around with hooks.showrev it seems.

Anyway, cheers and thanks for the suggestions!

爱格式化 2024-07-20 12:45:53

如果您使用 Windows,scm-notifier 会很有帮助。

If you use windows, scm-notifier would be helpful.

爱她像谁 2024-07-20 12:45:53

不完全是一个完整的答案,因为它是特定于 Github 的,但是如果您碰巧使用 Github,那么配置“服务挂钩”非常容易。
对于您想要监控的每个存储库,请输入“设置/服务挂钩”。
有大量可用的集成,例如 Trac、Twitter、Amazon SNS、Jira、Asana、Bugzilla、FogBugz、IRC、Jabber、Pivo​​tal Tracker、Trello 和 Email...
只需选择电子邮件并为其提供群组电子邮件地址即可。
我们使用电子邮件通知来同步我们的开发人员。

Not exactly a full answer since it is Github-specific, but if you happen to use Github it is extremely easy to configure "Service Hooks".
For each repository you wish to monitor, enter Settings / Service Hooks.
There are plenty of available integrations, such as Trac, Twitter, Amazon SNS, Jira, Asana, Bugzilla, FogBugz, IRC, Jabber, Pivotal Tracker, Trello and Email....
Simply select email and feed it with a group email address.
We use the email notifications to sync our developers.

世态炎凉 2024-07-20 12:45:53

如果您使用 GitLab,则可以使用“Email-on-push”项目服务来实现此目的,它可以在项目设置中的服务下找到。

If you use GitLab you can use the 'Email-on-push' project service for this, it can be found under services in project settings.

爺獨霸怡葒院 2024-07-20 12:45:53

您可以使用预提交:

#!/usr/bin/env ruby

require 'mail'

Mail.defaults do
  delivery_method :smtp,
    address: 'smtp.gmail.com',
    port: 587,
    user_name: '...',
    password: '...',
    authentication: 'plain',
    enable_starttls_auto: true
end

changes=`git diff --cached --unified=0 Gemfile Bowerfile`

unless changes.empty?
  Mail.deliver do
    from     '...'
    to       '...'
    subject  '[PROJECT] Plese confirm team can use libraries'
    body     changes
  end
end

安装:

cd project
cp pre-commit .git/hooks
chmod +x .git/hooks/pre-commit
gem install mail

测试:

echo "# some change" >> Gemfile && git commit -m 'some change' Gemfile

You can use pre-commit:

#!/usr/bin/env ruby

require 'mail'

Mail.defaults do
  delivery_method :smtp,
    address: 'smtp.gmail.com',
    port: 587,
    user_name: '...',
    password: '...',
    authentication: 'plain',
    enable_starttls_auto: true
end

changes=`git diff --cached --unified=0 Gemfile Bowerfile`

unless changes.empty?
  Mail.deliver do
    from     '...'
    to       '...'
    subject  '[PROJECT] Plese confirm team can use libraries'
    body     changes
  end
end

Install:

cd project
cp pre-commit .git/hooks
chmod +x .git/hooks/pre-commit
gem install mail

Test:

echo "# some change" >> Gemfile && git commit -m 'some change' Gemfile
萌无敌 2024-07-20 12:45:53

在您的存储库下的 GitLab 中:

  1. 单击“设置”。
  2. 当设置展开时,您将看到集成。 点击
    它。

将打开一个新页面推送电子邮件

  1. 找到并选择从提交者发送
  2. 另外,输入位于以下位置的收件人(以逗号分隔):
    最后一个字段。

此外,还有一个禁用代码差异选项,可以排除通知正文中可能敏感的代码差异。 它是可选的。

更多细节:
单击 这里

In GitLab under your repository:

  1. Click on Setting.
  2. When setting expands there you will see Integrations. Click on
    it.

There opens a new page Emails on push

  1. Locate and select Send from committer.
  2. Also, enter the Recipients with comma separated located at the
    last field.

Also there is an option for Disable code diffs which exclude possibly sensitive code diffs in notification body. It is optional.

For more details:
Click Here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文