acbot
V2EX  ›  GitHub

能获取到项目中,最后更新(增加/修改)过的文件吗?

  •  
  •   acbot · Apr 4, 2022 · 1816 views
    This topic created in 1566 days ago, the information mentioned may be changed or developed.

    使用 GitHub REST API 或 其他 shell 脚本(无 git 环境),有没有办法能获取到 GitHub 项目中,最后更新(增加 /修改)过的文件。 目前查看了一下官方文档 https://api.github.com/repos/{owner}/{repo}/commits?path= 这个 API 只能查询某个文件最后提交时间,另外一个 API 也仅仅是能查看整个项目最后的提交的时间,都不能满足需求。

    7 replies    2022-04-05 14:58:10 +08:00
    Puteulanus
        1
    Puteulanus  
       Apr 5, 2022
    commits 输出的第一个 commit 的 url ,get 访问返回的结果里不是有一个 files 吗
    FranzKafka95
        2
    FranzKafka95  
       Apr 5, 2022 via Android
    不是很理解,相当于你要获取远程项目的最后更改的文件是吧,这个如果没有官方 API 支持是不大可能得,不过 shell 里面是可以通过 stat 命令查看文件 modified 的时间的,如果能把文件放到本地,for 循环处理,应该可以,或者考虑一下利用 actions 帮你做这个事情?
    acbot
        3
    acbot  
    OP
       Apr 5, 2022
    @Puteulanus 没太明白,另外整个项目是第三方的,我这边只是浏览而已。
    acbot
        4
    acbot  
    OP
       Apr 5, 2022
    @FranzKafka95 原因就是这个项目太大了,所以我仅仅是想获取最后更新过的文件。当然这个在 git 环境中比较好办。
    Puteulanus
        5
    Puteulanus  
       Apr 5, 2022
    @FranzKafka95 github 项目最新修改的文件,不就是最后一个 commit 包含的变动文件吗

    比如
    https://api.github.com/repos/pi-hole/pi-hole/commits
    第一个 commit 的 url 为
    https://api.github.com/repos/pi-hole/pi-hole/commits/326cd6a1f845b3f2654e0bde9591d08d0f87e010
    JSON 里的 files 包含两个 file
    "advanced/Templates/pihole-FTL.service"
    "automated install/basic-install.sh"

    和它网页上最后一个 commit 的 changed file 一致
    https://github.com/pi-hole/pi-hole/commit/326cd6a1f845b3f2654e0bde9591d08d0f87e010
    Puteulanus
        6
    Puteulanus  
       Apr 5, 2022
    监控第三方库还有些快乐的小技巧
    比如 watch 目标库,收件箱收信规则转发去 mailgun 的域名邮箱
    mailgun 那边 receiving routes 设置 webhoook 发往 google app script
    google app script 那边用代码就能随便调自己用的服务的 API 了,比如触发 docker 构建

    这样就能获得一个第三方库的 webhook ,不用自己去轮询了
    acbot
        7
    acbot  
    OP
       Apr 5, 2022
    @Puteulanus 谢谢,之前没有看到 "files": [...]
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2647 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 10:48 · PVG 18:48 · LAX 03:48 · JFK 06:48
    ♥ Do have faith in what you're doing.