Github文件更改通知



有没有办法在更改某些文件时通知人们?具体来说,我想跟踪 *.sql 文件的更改,并在更改时通知我们的开发人员。如何配置提交后钩子进行通知?

如果您希望人们通过电子邮件收到通知,并且希望他们管理自己的通知,那么 https://app.github-file-watcher.com/应该可以解决问题 - 它会监控任何公共存储库,并通过电子邮件通知您对任何文件、特定文件或符合您条件的某些文件的更改。

我知道

已经有一段时间了,但是当我在寻找类似的东西时,我偶然发现了这个线程。我查看了Cooper的GitHub File Watcher,但它不适用于私有存储库,也不是开源的。

所以我最终构建了自己的解决方案:https://github.com/jesalg/commit-hawk。在这里发布这个以防万一有人仍在寻找这样的工具。

在接收后钩子中使用git diff-tree

 git diff-tree --name-status -rz

您可以 grep 结果以检查某些文件是否被修改(状态 ' M '),如本答案中所述。
您可以在 gist.github.com 上找到许多示例,这个示例使用 --name-status 选项。

>GitHub(截至2019年12月)在预览版中提供了一些新的通知功能,包括CODEOWNERS的概念,它允许相当精细地控制如何配置通知以进行更改。

需要启用预览功能才能正常工作,但是所需要做的就是在根,docs/.github/中创建CODEOWNERS文件。

下面是文档中的示例文件:

# 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 docs@example.com
# 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/*  docs@example.com
# 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
我知道

这确实是一个老问题,但这里有一个解决方案,您可以通过存储库上的 github webhook 进行部署。您还可以自定义和更改代码以查找特定的文件模式,并通过电子邮件,松弛,文本或其他方式通知您。希望这是有帮助的。

这是它的代码:https://github.com/DevScoreInc/samples/tree/master/github-file-monitor

下面是一个演示,准确展示了如何配置它:https://youtu.be/6HgxIkT8EQ4

如果你对存储库有维护者的访问权限,你可以从设置 -> Webhook 菜单中在 GitHub 中配置推送 webhook,并在有效负载中查找修改的文件。

下面是一个示例 Python FastAPI 代码:

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")

最新更新