Sternutation
Sternutation

Reputation: 63

Github file change notifications

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.

Upvotes: 4

Views: 2591

Answers (1)

dan1st
dan1st

Reputation: 16338

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/** [email protected]
/path/to/fixed/file [email protected]
*.md [email protected]

Upvotes: 2

Related Questions