如何使用 GitHub api 查找存储库的 'm' 最旧的复刻

How to find the 'm' oldest forks of a repository using GitHub api

我需要使用 GitHub API 获取给定存储库的 'm' 最旧的复刻。为了获得 'm' 最旧的叉子,我正在尝试获取从最旧到最新排序的叉子。

以 google 的“it-cert-automation-practice”存储库为例,我尝试了以下 APIs:

https://api.github.com/repos/google/it-cert-automation-practice/forks?q=sort:created_at
https://api.github.com/repos/google/it-cert-automation-practice/forks?q=sort:oldest
https://api.github.com/repos/google/it-cert-automation-practice/forks?q=sort:updated_at&fork:true&order:asc
https://api.github.com/repos/google/it-cert-automation-practice/forks?q=sort:created_at&fork:true&order:asc

您可以使用 List forks endpoint,请考虑以下事项:

  • 使用 sort 参数,值为 oldest
  • 如果您想列出超过 100 个存储库,您将需要使用 page 参数处理分页。

查看使用 Octokit 获取 Node.js 存储库最旧的 40 个复刻的工作示例。

Get oldest forks of GitHub repository                                                                                 View in Fusebit
const owner = 'nodejs';
const repo = 'node';
const repoInfo = await github.request(`GET /repos/${owner}/${repo}`, {
  owner,
  repo,
});

const {forks_count} = repoInfo.data;

// By default it will return 30 results, you can get up to 100 using per_page parameter.
const searchResult = await github.rest.repos.listForks({
  owner,
  repo,
  sort: 'oldest',
  per_page: 40
});

console.log(searchResult.data.map(repo => `${repo.full_name} created at ${repo.created_at}`), `Found ${searchResult.data.length} of ${forks_count} total forks for ${owner}/${repo} repository`);