gitwebhookspost-receive-email

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


I am new to configuring git hooks and understand that post-receive can be used to send notifications after a successful push request. 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. Or maybe send the notification when the config file has been updated successfully? 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?


Solution

  • A post-receive hook that you write can do anything that you write it to do. There are example ones that send email, and you could presumably start with one of those and modify it to achieve your desired result, except for one huge stumbling block:

    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 does not have pull requests (in the GitHub sense, that is). There is a Git command, git request-pull, that generates email messages someone can send, but that's all it does. It won't invoke any post-receive hook.

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

    This, you can do, provided you can set up a post-receive hook:

    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?

    A Pull Request notification from GitHub is generated by GitHub. They do not run arbitrary post-receive hooks. You can write actions; whether you can generate email in an action, and if so, how, I do not know, but see How to run post-receive hook on GitHub to get started with this.

    GitHub Actions are specific to GitHub: they are not available from other Git hosting sites. (Other sites generally have something very similar, but not the same.) Use the tag for questions about GitHub Actions.