使用 PyGitHub 查询特定日期的 GitHub 提交

query github commits from a certain date using pygithub

提问人:Darren Oakey 提问时间:11/17/2023 更新时间:11/17/2023 访问量:18

问:

具有以下代码:

from github import Github
...
g = github(token)
query = f'org:{org_name} author:{username} since=2021-10-19T00:00:00Z'
commits = g.search_commits(query, sort='author-date', order='desc')

如果我那里有“since”参数 - 我得到 0 个结果。如果我把它拿出来,我会得到几百个——这就是问题所在。我正在做一些可以以这种方式工作的处理,所以想要增量 - 即缓存结果,几天后当我调用它时 - 只找到自我上次阅读以来的新提交。

从文档来看,这应该有效 - 但是......它没有 - 我做错了什么。

蟒蛇 github pyGitHub

评论


答:

1赞 Tấn Nguyên 11/17/2023 #1

简短的回答: 尝试使用:withcommitter-date:<2023-01-01T01:00:00Z>, >=, <, <=

长答案: 基本上,pygithub 将请求转发到 REST,如此链接中所述 https://pygithub.readthedocs.io/en/stable/github.html?highlight=search_commits#github.MainClass.Github.search_commits

search_commits(query: str, sort: Opt[str] = NotSet, order: Opt[str] = NotSet, **qualifiers) → PaginatedList[Commit]

Calls:  
GET /search/commits

Parameters: 
query – string
sort – string (‘author-date’, ‘committer-date’)
order – string (‘asc’, ‘desc’)
qualifiers – keyword dict query qualifiers
Return type:    
PaginatedList of github.Commit.Commit

有一个你可以用的,比如。有关正确的语法,可以参考 https://docs.github.com/en/search-github/searching-on-github/searching-commits#search-by-authored-or-committed-datecommitter-datecommitter-date:<2023-01-01T01:00:00Z

Qualifier   Example
author-date:YYYY-MM-DD  author-date:<2016-01-01 matches commits authored before 2016-01-01.
committer-date:YYYY-MM-DD   committer-date:>2016-01-01 matches commits committed after 2016-01-01.

以及此处的更多通用语法:https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates

您还可以在此处测试搜索语法

https://github.com/search?q=repo:neozhu/CleanArchitectureWithBlazorServer committer-date:<2023-01-01T01:00:00Z&type=commits