模板存储库创建的所有子存储库的列表?
GitHub 在 WUI 顶部的“星星”和“手表”旁边显示了从给定存储库创建的分叉数量。您可以在“分析”选项卡下显示这些用户分叉的链接列表。如何获得从 GitHub 上的模板存储库创建的所有存储库的类似列表?
根据存储库的内容进行搜索,答案就很明确了!通过README.md文件内容搜索!
使用 GitHub 的搜索引擎并提供 README.md 文件中出现的独特单词组合。这就是我为模板所做的事情 -in:readme sort:updated -user:unfor19 "tfmultienv"
sort:updated
排序
我的用户名
-user:USERNAME
。
USERNAME
,而不是硬编码
@me
。
gh
FTW:
#!/bin/bash
org_name="MYORGNAME"
repo_list=`gh repo list $org_name --limit 1000 | awk '{print $1}'`
template_repo=$1
if [ -z "$template_repo" ]
then
echo "Usage: $0 <template_repo>"
echo " List repositories generated from a given template repository"
echo "ABORTING!"
exit 1
fi
echo "Searching for repositories generated from template: $template_repo"
for repo in $repo_list
do
repo_info=`gh api repos/$repo`
echo "$repo_info" | jq -r ".template_repository.full_name" | grep "$template_repo" 2>&1 > /dev/null
if [ "$?" -eq "0" ]
then
echo "repo_using_template: $repo"
fi
done
然后,在设置 ./find_repo_by_template.sh <template_repo>
变量后,运行
org_name
获取使用该模板的存储库列表。 我的用例需要在组织内进行搜索。 如果您有不同的用例,您应该能够轻松调整我的脚本以获得所需的结果。
gh
表示特定组织的“一行”(全局搜索不起作用):
gh repo list my-org-name \
--limit 1000 \
--json name,templateRepository \
--jq '.[] | select(.templateRepository.name == "my-template-repo-name") | .name'
我猜这与 https://stackoverflow.com/a/76373786/253468 是相同的解决方案,只是使用内置的 JQ 和少几千个 API 调用,无需 shell 脚本。