Github file change notification
Asked Answered
N

7

59

Is there a way to notify people on change of some certain files? Specifically, I would like to track change of *.sql files and and notify our developers on a change. How can I configure post commit hooks to notify?

Nunuance answered 3/10, 2013 at 21:45 Comment(2)
How to 'Watch' only a directory in a GitHub repository?Cortes
sourcegraph.com/code-monitoring is another optionObedience
T
43

If you want folks to get notified via email, and you want them to manage their own notifications, then https://app.github-file-watcher.com/ should do the trick - it monitors any public repo, and will notify you via email of changes to any file, a specific file, or some files that match your criteria.

Tutti answered 12/4, 2017 at 0:32 Comment(2)
Cool but apparently this only supports files on master branch. https://mcmap.net/q/272635/-how-to-39-watch-39-only-a-directory-in-a-github-repository atom feed solution works for any branch.Thesda
Hopefully, the person won't take it down without sending an email to all subscribers, so we know it will no longer notify us. Still, an awesome idea from the person. Thank you for putting it here!Rectify
P
14

I know it's been a while but I stumbled upon this thread when I was looking for something similar. I looked into Cooper's GitHub File Watcher but it didn't work with private repos nor was it open source.

So I just ended up building my own solution: https://github.com/jesalg/commit-hawk. Posting this here just in case someone is still looking for a tool like that.

Pone answered 21/7, 2019 at 19:53 Comment(0)
E
11

Use git diff-tree in your post-receive hook:

 git diff-tree --name-status -rz

You can grep the result to check if certain files are modified (status 'M'), as described in this answer.
you can find many examples on gist.github.com, with this one using the --name-status option.

Eleen answered 4/10, 2013 at 5:35 Comment(0)
A
8

GitHub (as of 12/2019) has some new notification features in preview, including the concept of CODEOWNERS, which allows fairly granular control of how notifications can be configured for changes.

The Preview feature needs to be enabled for it to work, but then all that needs to be done is to create a CODEOWNERS file in either root, docs/, or .github/.

Here is an example file from the documentation:

# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
*       @global-owner1 @global-owner2

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
# modifies JS files, only @js-owner and not the global
# owner(s) will be requested for a review.
*.js    @js-owner

# You can also use email addresses if you prefer. They'll be
# used to look up users just like we do for commit author
# emails.
*.go [email protected]

# In this example, @doctocat owns any files in the build/logs
# directory at the root of the repository and any of its
# subdirectories.
/build/logs/ @doctocat

# The `docs/*` pattern will match files like
# `docs/getting-started.md` but not further nested files like
# `docs/build-app/troubleshooting.md`.
docs/*  [email protected]

# In this example, @octocat owns any file in an apps directory
# anywhere in your repository.
apps/ @octocat

# In this example, @doctocat owns any file in the `/docs`
# directory in the root of your repository.
/docs/ @doctocat
Astern answered 10/12, 2019 at 4:19 Comment(0)
T
4

I know this is really an old question, but here is a solution you can deploy via a github webhook on a repo. You can also customize and change the code to look for specific file patterns and notify you via email, slack, text or other means. Hope this is helpful.

Here is the code for it: https://github.com/DevScoreInc/samples/tree/master/github-file-monitor

Here is a demo that shows exactly how to configure this: https://youtu.be/6HgxIkT8EQ4

Tarsuss answered 25/3, 2020 at 4:22 Comment(1)
this isn't working now. Error: Page not found. The requested URL was not found on this server.Hades
F
1

If you have maintainer access to the repo, you can configure the push webhook in GitHub from the Settings -> Webhook menu and look for modified files in the payload.

Here's a sample Python FastAPI code:

WATCHED_BRANCHES = ["master", "prod"]
WATCHED_FILES = ["/file_a.py", "/file_b.py"]


@router.post("/webhooks/github", include_in_schema=False)
async def github_webhook(request: Request, response: Response):
    message = await request.json()

    if not message["ref"].split("/")[-1] in WATCHED_BRANCHES:
        return

    modified_files = [f for c in message["commits"] for f in c["modified"]]
    modified_watched_files = [
        w for w in WATCHED_FILES if any([(w in f) for f in modified_files])
    ]

    if modified_watched_files:
        print(f"{modified_watched_files} modified")
Franciskus answered 24/2, 2023 at 9:36 Comment(0)
B
0

Another thing you can do is use the github RSS feeds, there is one for each file. See here. Many thanks to @CanSpice.

If you use an RSS reader, you just add this feed to it, if not, there are platforms that can transform a new entry in an RSS feed into a notification, for example Home Assistant can do this.

Blown answered 13/1 at 5:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.