简体   繁体   English

Git 挂钩发送 email 回购变更通知

[英]Git hook to send email notification on repo changes

How do I configure the appropriate Git hook to send a summary email whenever a set of changes is pushed to the upstream repository?如何配置适当的 Git 挂钩,以便在将一组更改推送到上游存储库时发送摘要 email?

Another, more modern way to do this is with git-multimail , as suggested by Chords below.另一种更现代的方法是使用git-multimail ,正如下面Chords所建议的那样。


This is how you did it in 2009.这就是你在 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)您可以将类似内容添加到 $GITDIR/hooks 中的接收后挂钩中,或者使用源代码的 contrib 目录中的脚本(可在此处获得)

Here is the simplest solution I've found:这是我找到的最简单的解决方案:

1) Log in to your gitHub account on github.com 1) 在github.com登录你的gitHub账号

2) In the main tab click on Settings 2) 在主选项卡中单击设置

3) From the main navigation choose Service Hooks 3) 从主导航中选择Service Hooks

4) From Available Hooks choose Email 4) 从可用挂钩中选择 Email

5) Fill in your email address in field Address 5) 在Address字段填写你的email地址

6) Check the checkbox Send from Author 6) 选中从作者发送的复选框

7) Check the checkbox Active 7) 选中活动复选框

8) Click on Update Settings 8) 点击更新设置

Optional: You can click on Test Hook for testing, check your inbox you should receive email.可选:您可以点击Test Hook进行测试,检查您的收件箱您应该收到 email。

Also there are images made according to the process:还有根据流程制作的图片:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

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 } .如何将 email 发送给所有开发团队成员,当 gitHub 的 Service Hooks->Email 最多只允许 2 个收件人时}

The answer is combination of Service Hook->Email @ GitHub && Google groups答案是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 Go 到Google Groups并点击顶部的Create Group
  3. Type in Group Name, Group email address (will copy/paste into GitHub Service Hook->Email Address), Group description输入群组名称,群组 email 地址(将复制/粘贴到 GitHub Service Hook->Email Address),群组描述
  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之后在左侧的菜单中点击邀请成员并输入您队友的 email 地址
  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 .在左侧的菜单中单击All Members并选中名为Delivery的第 4 列,每个团队成员都应该有选项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.之后,我想感谢 Clement Escoffier先生,请遵循他的指导方针@Clement Escoffier::Send Github 提交给 Google Group以了解如何完成它。 {Thank you Clement:)} {谢谢克莱门特:)}
  9. If the link becomes unavailable here is another link to my gDocs @ PDF version of Clements guide如果链接不可用,这里是我的 gDocs @ PDF 版本的 Clements 指南的另一个链接

This is my way of send email notification to users every time some one push to the repository.这是我每次向存储库推送时向用户发送 email 通知的方式。

Setting Up Git Commit Email Notification 设置 Git 提交 Email 通知

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.我改成用SMTP发email,当然gmail的SMTP也可以用。

Robin Sommer 's git-notifier generates also very nice summaries in the following format: Robin Sommergit-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 <robin@icir.org>
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)

setting hooks.showrev is making no distinguishable difference?设置 hooks.showrev 没有明显区别? :-/ :-/

Sample conf:示例配置文件:

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

I managed to do this, but had to opt for using the contrib script, not the other (perl) script by Alexandre Julliard.我设法做到了这一点,但不得不选择使用 contrib 脚本,而不是 Alexandre Julliard 的其他 (perl) 脚本。 It seems fancier and more configurable, but with postfix I had no mail command which would accept "-s"?它看起来更漂亮,更可配置,但是使用 postfix 我没有接受“-s”的邮件命令? Here's my way:这是我的方式:

http://pastie.textmate.org/695323 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.显示更多信息会很好,比如完整的补丁、gitweb 链接和提交图,但这个脚本只能做第一个——如果我玩 hooks.showrev 似乎。

Anyway, cheers and thanks for the suggestions!无论如何,干杯并感谢您的建议!

If you use windows, scm-notifier would be helpful.如果您使用 windows, scm-notifier会有所帮助。

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".不完全是一个完整的答案,因为它是特定于 Github 的,但是如果您碰巧使用 Github,那么配置“服务挂钩”将非常容易。
For each repository you wish to monitor, enter Settings / Service Hooks.对于您希望监控的每个存储库,输入 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....有很多可用的集成,例如 Trac、Twitter、Amazon SNS、Jira、Asana、Bugzilla、FogBugz、IRC、Jabber、Pivotal Tracker、Trello 和 Email……
Simply select email and feed it with a group email address.只需输入 select email 并为其提供一组 email 地址。
We use the email notifications to sync our developers.我们使用 email 通知来同步我们的开发人员。

If you use GitLab you can use the 'Email-on-push' project service for this, it can be found under services in project settings.如果您使用 GitLab,您可以为此使用“电子邮件推送”项目服务,它可以在项目设置的服务下找到。

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

In GitLab under your repository:在您的存储库下的GitLab中:

  1. Click on Setting.单击设置。
  2. When setting expands there you will see Integrations .当设置在那里展开时,您将看到Integrations Click on it.点击它。

There opens a new page Emails on push推送时打开一个新页面电子邮件

  1. Locate and select Send from committer .找到 select从 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更多详情:点击这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM