通过github api统计组织Star数

2024-08-23 19:57:46 浏览数 (3)

君子之学,博于外而尤贵精于内。——王廷相

文档如下:

https://docs.github.com/zh/rest/orgs/orgs?apiVersion=2022-11-28

代码如下:

代码语言:javascript复制
const response = await fetch('https://api.github.com/orgs/dromara/repos?per_page=100&page=1');
  if (!response.ok) {
    throw new Error(`Error fetching repos: ${response.statusText}`);
  }
  const repos = await response.json();
console.log(repos)
const list = repos.map(({name,stargazers_count})=>({name,stargazers_count}))
console.log(list)
list.reduce(
  (accumulator, currentValue) => accumulator   currentValue.stargazers_count,
  0,
);

注意这里是分页,我们把每一页的结果相加,得到githubdromara82个仓库拥有89972star

apache则非常之多,2659个仓库1122875star

0 人点赞