You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub API的since查询参数失效问题求助

GitHub API提交筛选问题排查及参数说明

一、since参数不生效的排查点

  1. 混淆提交的两个日期字段
    GitHub API的since参数是基于**提交的仓库记录时间(commit.committer.date)**筛选的,而你代码里打印的是commit.author.date——这是代码作者本地提交的时间,和仓库中实际入库的提交时间可能完全不同。比如作者在2020年写了代码,但直到现在才合并到仓库,那committer.date就是当前日期,这条提交会被since=2020-06-06筛选出来,而你看到的author.date是2020年,就会误以为参数没生效。

  2. 多余请求头可能干扰
    你请求里加的Access-Control-Allow-Origin、Access-Control-Allow-Methods是服务端用来处理跨域的响应头,客户端发起请求时不需要携带,反而可能导致请求异常。建议只保留必要的请求头:Authorization和指定API版本的Accept头。

  3. 路径参数是否准确
    path=filename.xml是筛选仅修改了该文件的提交,如果这个文件在2020-06-06之后确实有新提交,返回最新提交是正常的。要确认路径是否正确(比如文件在子目录下,需写subdir/filename.xml),或者先去掉path参数测试全局提交的筛选是否生效。

二、page和per_page参数说明

  • per_page:设置单页返回的提交数量,最大值为100。比如设为100,就是每次请求最多返回100条符合条件的提交记录。
  • page:当符合条件的提交总数超过per_page时,GitHub API会自动分页,page用来指定获取第几页的内容,比如page=1是第一页,page=2是第二页,以此类推,用来遍历所有符合条件的提交。

修正后的代码示例

let gitCommitHashes = [];
let gitCommitDates = [];

axios.get(
  "https://api.github.com/repos/myuser/myreponame/commits?path=filename.xml&page=1&per_page=5&since=2020-06-06T00:00:00Z",
  {
    headers: {
      "Accept": "application/vnd.github.v3+json",
      "Authorization": `Bearer ${BEARER_TOKEN}`
    }   
  }
)
.then((response) => {                 
  for(let i=0;i<response.data.length;i++){
    // 打印与since筛选逻辑一致的仓库提交时间
    const commitDate = response.data[i].commit.committer.date;
    gitCommitDates.push(commitDate);              
    gitCommitHashes.push(response.data[i].sha);               
  }
  for(let i=0;i<gitCommitHashes.length;i++){              
    console.log(`${i}------>${gitCommitHashes[i]}`)
    console.log(`gitCommitDates: ${gitCommitDates[i]}`)
  }
},
(error) => {
  console.error('请求失败:', error);
});        

内容的提问来源于stack exchange,提问作者madmax821

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 03:30:46