背景:Github没有提供统一的删除接口,页面删除流程较多
- 创建 具有删除权限的 token
settings->Developer settings->Personal access tokens->Generate new token
选择delete_repo - API文档中的删除接口(了解即可)
https://docs.github.com/en/rest/reference/repos#delete-a-repository
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world
- 构建请求脚本(Example:python)
from time import sleep
import requests
headers = {
"Accept": "application/vnd.github.v3+json",
"Authorization": "token XXXXXXXXXXXXXXXXXXXXXX", # 此处的XXX代表上面的token
"X-OAuth-Scopes": "repo"
}
with open('./repos.txt', 'r', encoding='utf-8') as f:
data = f.readlines()
url = "https://api.github.com/repos/{}/{}"
urls = []
for line in data:
name, repo = line.strip().split("/")
urls.append(url.format(name, repo))
for l in urls:
requests.delete(url=l, headers=headers)
sleep(2)
# 可直接在页面复制,调整格式,也可以利用Api获取用户的所有仓库(不赘述)
# ./repos.txt
用户名/仓库名
username/repo1
username/repo2
username/repo3