2

Is there a way to notify people on changes to specific files after they get merged into the Repo on GitHub? Specifically, there is a private repo that we have, with multiple people on it.

We'd like to be able to figure out a way to send emails for the files that people may be interested in, alongside the changes to those files.

Almost every solution I have found online seems to deal with public repos. Such as GitHub File Watcher, RSS feeds, and some of the other options given here. The most promising seems to be Commit Hawk but that is for slack integration. Post-receive hooks apparently do not work with repos hosted on GitHub, and CODEOWNERS seems to require code reviews from whoever gets notified, since it designates them as owners of the files in question.

Marlon Richert
  • 5,250
  • 1
  • 18
  • 27
  • GitHub Actions may help you. – dan1st Jul 26 '21 at 17:31
  • Is there a GitHub action that can allow me to do something like this? I know that Commit Hawk uses GitHub actions but I am currently completely unfamiliar with how they work. – Sternutation Jul 26 '21 at 17:40
  • GitHub Actions lets you execute shell codebon every commit. You can use this for checking the files and e.g. sending out E-Mails, trigger webhooks or other notifications. – dan1st Jul 26 '21 at 17:42
  • So in theory, with Actions I should be able to make it so that a certain number of users get e-mailed about changes to specific files? As in say, I create a mailing list, and a list of files that those users need to be notified about. Using actions, I should be able to set it up so that they get e-mailed? – Sternutation Jul 26 '21 at 19:18
  • Yes, it might be some work but it should be possible and actions like [this](https://github.com/marketplace/actions/send-email) might help you. However, you might need to create your own action. – dan1st Jul 28 '21 at 14:20

1 Answers1

2

It is possible to use GitHub Actions for this.

This allows you to run code on every push. That code can then check the changed files and send E-Mails (or other notifications) to users that should be notified.

How you could do this

The commit SHA of the old version (before the push) can be obtained using ${{ github.event.before }} and the commit SHA of the new version (after the push) can be obtained using The commit SHA of the old version (before the push) can be obtained using${{ github.event.after }}`.

Those commit hashes can then be compared with the command git diff --name-only ${{ github.event.before }} ${{ github.event.after }}.

Those changes could then be processed and an E-Mail sent to the people you want to notify.


My action

I have created an action that does exactly this.

You basically create a workflow like this:

name: 'Notify users on file change'
on:
  push:
    branches: [ master ]
jobs:
  notif:
    runs-on: ubuntu-latest
    steps:
      - uses: danthe1st/email-filechange-notif-action@v1
        with: 
          # Address to send E-Mails from
          senderEmail: ${{ secrets.SENDER_EMAIL }}
          # optional, The subject of the E-Mails to send
          subjectLine: 'GitHub file change notification'
          # A file in the repository or HTTP address that contains file patterns with E-Mail addresses that should be notified on file changes
          mailingList: ${{ secrets.MAILING_LIST }}
          # The SMTP server used to send E-Mails
          smtpServer: ${{ secrets.SMTP_SERVER }}
          # optional, The SMTP port used to send E-Mails
          smtpPort: 587
          # The SMTP user name used to send E-Mails
          smtpUsername: ${{ secrets.SMTP_USER }}
          # The SMTP password used to send E-Mails
          smtpPassword: ${{ secrets.SMTP_PASSWORD }}

Aside from creating the workflow file, you need to set up the secrets with information about your E-Mail server and let mailingList point to a text file formatted like this:

/path/** some@email.com
/path/to/fixed/file someone@example.com
*.md yet.someone@else.com
dan1st
  • 12,568
  • 8
  • 34
  • 67