shell - 如何使用 GitHub API 在 GitHub 组织中检索 1000 多个存储库的列表
问题描述
我正在使用以下脚本在我的一个 GitHub Enterprise 组织中生成一个存储库列表,它工作正常;但是,默认情况下,它一次只能获取 100 个 repos。
如何修改它以生成整个列表?我的 GitHub 组织中有大约 2000 个存储库。
curl --silent --user "myusername:mypassword" "https://github.***.com/api/v3/orgs/myorg/repos?page=1&per_page=2000" | npx jq '.[].clone_url' | while read repo
do
repo="${repo%\"}"
repo="${repo#\"}"
echo "$repo"
done > repolist.txt
我无法在page=*&per_page=*
这里调整,无论我使用什么数字组合,当我执行上面的 shell 脚本时,repolist.txt
都会生成一个名为的文件,其中包含 GitHub org 中前 100 个 repos 的列表。
解决方案
来自文档
您可以指定要接收的物品数量(最多 100 个);
使用此值,您可以制作total_pages=$(($public_repos / 100 + 1))
和迭代total_pages
增加您的page
道具。
下面是一个小代码,只需添加您的凭据和组织名称:
#!/bin/bash
user=""
password=""
org=""
public_repos=$(curl -s -u "${user}:${password}" "https://api.github.com/orgs/${org}" | jq .public_repos)
per_page=100
total_pages=$(($public_repos / $per_page + 1))
for page in $(seq 1 $total_pages); do
curl -s -u "${user}:${password}"\
"https://api.github.com/orgs/${org}/repos?page=${page}&per_page=${per_page}" | \
jq -r '.[].clone_url'
done
推荐阅读
- python - 如何检测阈值图像中的黑色区域
- php - 注意:试图获取非对象的属性“num_rows”
- python - plotly area chart, how can I set fill opacity?
- c# - WPF 高频事件和更新 UI
- aurelia - Aurelia repeat.for 生成额外元素
- postgresql - 从wildfly访问postgresql的编码错误
- javascript - 如何在 angular5+ 中对组件进行单元测试时提供注入值
- mysql - 为什么我的具有节点和 mysql 后端的 react 应用程序在本地工作,但在 Heroku 上却没有?
- vb.net - 如何从 vb.net 的 DataGridViewComboBoxColumn 中的 Sql 服务器数据库中获取值
- python - 未排序时使用 Openpyxl 比较两个 Excel 文件中的数据值