1 Star 0 Fork 7

cunshunxia/dev-tools

forked from OpenCloudOS/dev-tools 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
get_all_repo_name.py 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
ZoeDong 提交于 2023-11-02 12:51 +08:00 . add script to get all repo name in gitee
import requests
import argparse
def get_gitee_organization_repos(organization, access_token):
url = f"https://gitee.com/api/v5/orgs/{organization}/repos"
headers = {"Authorization": f"token {access_token}"}
params = {"page": 1, "per_page": 100}
repos = []
while True:
print("Getting repo infomation:", params)
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
data = response.json()
if not data:
break
repos.extend(data)
params["page"] += 1
return repos
def get_gitee_organization_repo_info(organization, access_token):
repos = get_gitee_organization_repos(organization, access_token)
repo_info = {}
for repo in repos:
if repo["private"]:
repo_info[repo["name"]] = "private"
elif repo["public"]:
repo_info[repo["name"]] = "public"
elif repo["internal"]:
repo_info[repo["name"]] = "internal"
return repo_info
def write_repo_info(repo_info, file_name, with_visibility):
print(repo_info)
with open(file_name, "w") as file:
for pkgs, visibility in repo_info.items():
if with_visibility:
file.write(f"{pkgs}\t{visibility}\n")
else:
file.write(f"{pkgs}\n")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Get all repo name in Gitee group.')
parser.add_argument('token', type=str, help='The access token for the Gitee group, if the user does not have permission, some repos will be invisible.')
parser.add_argument('--with_visibility', default=True, type=bool, help='Whether the output file with repository visibility, default True.')
parser.add_argument('--organization', default="opencloudos-stream", type=str, help='The organization name.')
parser.add_argument('--output_file', default="repo_info_list", type=str, help='The repo name list file.')
args = parser.parse_args()
repo_info = get_gitee_organization_repo_info(args.organization, args.token)
write_repo_info(repo_info, args.output_file, args.with_visibility)
print(f"已将 {args.organization} 组织内的所有软件包名写入文件:{args.output_file}")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cunshunxia/dev-tools.git
git@gitee.com:cunshunxia/dev-tools.git
cunshunxia
dev-tools
dev-tools
master

搜索帮助