使用日期查询使用 GitHub API 搜索存储库

问题描述

如果我向 GitHub API 发出以下 GET 请求,我会得到大约 58 个条目:

https://api.github.com/search/repositories?&per_page=250&sort=updated&order=asc&q=%22github-octocat%22

但是,带有任何日期参数的以下内容返回 0 个条目:

创建日期: ( created:>=2010-09-01 )

https://api.github.com/search/repositories?&per_page=250&sort=updated&order=asc&q=%22github-octocat+created:>=2010-09-01%22

日期范围:created:2012-08-13..2020-08-14

https://api.github.com/search/repositories?&per_page=250&sort=updated&order=asc&q=%22github-octocat+created:2012-08-13..2020-08-14%22

在 GitHub 文档中,在 @L_502_0@ 部分下,语法概述如下:

SEARCH_KEYWORD_1 SEARCH_KEYWORD_N QUALIFIER_1 QUALIFIER_N

Search by when a repository was created or last updated 上的 GitHub 文档概述了上述两种格式的日期格式,Query for values between a range 概述了它们的有效组合。我怀疑这些示例并非用于此用途,因为这些示例使用了用于浏览器的 URL,例如 https://github.com/search?q=case+pushed%3A%3E%3D2013-03-06+fork%3Aonly&type=Repositories,而不是 api.github.com,这也很令人困惑。

我正在尝试应用以下资源中显示的模式以获得日期范围过滤器:

非常感谢任何指点。

解决方法

即使 GitHub 文档概述了这样的语法:

SEARCH_KEYWORD_1 SEARCH_KEYWORD_N QUALIFIER_1 QUALIFIER_N

日期或类似的参数无效,除非放在 q 参数之外。而不是在双引号内包含 date 限定符(如下所示的 %22):

q=%22mysearch+pushed%3A2017-09-01..2020-10-01+sort:updated%22

将它们拉出来,并在 q 参数的右引号后添加:

q=%22mystring%22+pushed%3A2017-09-01..2020-10-01+sort:updated