如果特定文件发生更改,post-receive git 挂钩是否可用于发送电子邮件通知

Can the post-receive git hook be used to send email notification if a particular file changes

我是配置 git 挂钩的新手,了解 post-receive 可用于在成功推送请求后发送通知。我想知道如何在 PR 提交更改特定配置文件时使用它发送电子邮件通知。或者当配置文件更新成功时发送通知? PR 通知通常会发送所有已修改文件的列表,但我们如何才能单独突出显示/通知有关特定文件的更改?

您编写 的post-接收挂钩 可以做任何您编写的。有一些发送电子邮件的例子,你大概可以从其中一个开始并修改它以达到你想要的结果,除了一个巨大的绊脚石:

I would like to know how I could use it to send an email notification whenever a PR has a commit that changes a specific config file.

Git 没有拉取请求(在 GitHub 意义上,就是这样)。有一个 Git 命令,git request-pull,它生成可以发送的电子邮件消息,但仅此而已。它不会调用任何 post-接收挂钩。

Or maybe send the notification when the config file has been updated successfully?

这个,你可以做到,前提是你可以设置一个post-接收钩子:

A PR notification generally sends a list of all files that have been modified, but how can we highlight/ notify changes regarding a specific file alone?

来自 GitHub 的拉取请求通知 由 GitHub 生成。他们不会 运行 任意 post- 接收挂钩。您可以写 actions; 是否可以在操作中生成电子邮件,如果可以,如何生成电子邮件,我不知道,但请参阅 How to run post-receive hook on GitHub 开始使用。

GitHub 操作特定于 GitHub:它们无法从其他 Git 托管站点获得。 (其他网站通常有非常相似但不相同的内容。)使用 标签来回答有关 GitHub Actions 的问题。