Github文件更改通知

c6ubokkw  于 2023-02-28  发布在  Git
关注(0)|答案(6)|浏览(205)

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

vh0rcniy

vh0rcniy1#

如果你想让人们通过电子邮件得到通知,并且你想让他们管理自己的通知,那么https://app.github-file-watcher.com/应该可以做到这一点--它监视任何公共repo,并通过电子邮件通知你任何文件、特定文件或符合你标准的一些文件的更改。

9nvpjoqh

9nvpjoqh2#

我知道这已经有一段时间了,但我在寻找类似的东西时偶然发现了这个帖子。我研究了库珀的GitHub文件观察器,但它不适用于私有repos,也不是开源的。
所以我最终建立了自己的解决方案:https://github.com/jesalg/commit-hawk .把这个贴在这里,以防万一有人还在寻找这样的工具。

7uhlpewt

7uhlpewt3#

post-receive hook中使用git diff-tree

git diff-tree --name-status -rz

您可以对结果进行grep,以检查某些文件是否被修改(状态“M”),如in this answer所述。
您可以使用--name-status选项将find many examples on gist.github.comthis one一起使用。

kcugc4gi

kcugc4gi4#

GitHub(截至2019年12月)在预览中有一些新的通知功能,包括CODEOWNERS的概念,它允许相当细粒度地控制如何配置更改通知。
要使预览功能正常工作,需要启用该功能,但接下来需要做的只是在root、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
1hdlvixo

1hdlvixo5#

我知道这真的是一个老问题了,但是这里有一个解决方案,您可以通过Github Webhook部署在repo上。您还可以自定义和更改代码以查找特定的文件模式,并通过电子邮件、松弛、文本或其他方式通知您。希望这对您有所帮助。
下面是它的代码:https://github.com/DevScoreInc/samples/tree/master/github-file-monitor
下面是一个演示,详细说明了如何进行配置:https://youtu.be/6HgxIkT8EQ4

4dbbbstv

4dbbbstv6#

如果你拥有repo的维护者权限,你可以在GitHub的Settings -〉Webhook菜单中配置push webhook,并在payload中查找修改过的文件。
下面是一个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")

相关问题