Ami*_*ani 10 github github-api
如何批量归档我的存储库?我希望能够对它们进行排序,并找出一种不归档我的活动存储库的方法。
自 GitHub 通知功能推出以来,我的帐户中就有数百个旧的 GitHub 存储库,现在我收到了所有这些存储库的漏洞通知。以下是我的通知,最后一次使用的项目可能是在 6 年前:
您可以使用 GitHub API 以及两个工具来实现此目的。我将使用:
就是这样:
获取我们帐户中所有 GitHub 存储库的列表,并将它们保存在文件中:
hub api --paginate users/amingilani/repos | jq -r '.[]."full_name"' > repos_names.txt
手动浏览该文件,删除您不想存档的任何存储库
将所有存储库归档到文件中:
cat repos_names.txt | xargs -I {} -n 1 hub api -X PATCH -F archived=true /repos/{}
注:自2020年起:
gh repo list已发布( 2021 年第一季度提交 00cb921中包含gh1.7.0):它确实考虑了分页,因为它类似于以下别名:set -e
repos() {
local owner="${1?}"
shift 1
gh api graphql --paginate -f owner="$owner" "$@" -f query='
query($owner: String!, $per_page: Int = 100, $endCursor: String) {
repositoryOwner(login: $owner) {
repositories(first: $per_page, after: $endCursor, ownerAffiliations: OWNER) {
nodes {
nameWithOwner
description
primaryLanguage { name }
isFork
pushedAt
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
' | jq -r '.data.repositoryOwner.repositories.nodes[] | [.nameWithOwner,.pushedAt,.description,.primaryLanguage.name,.isFork] | @tsv' | sort
}
repos "$@"
Run Code Online (Sandbox Code Playgroud)
gh repo list --no-archived可以将列表限制为您尚未归档的存储库
gh repo archive然后,可以针对该列表中的每个元素,将 GitHub 存储库存档。
gh repo list <org> | awk '{NF=1}1' | \
while read in; do gh repo archive -y "$in"; done
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3321 次 |
| 最近记录: |