存储库#
初始化:
from github import Github
g = Github()
获取存储库主题:
repo = g.get_repo("Xinering/cocoapi")
repo.get_topics()
['coco', 'cocoapi', 'python3', 'zipfile']
计算星星的数量:
repo.stargazers_count
73
获取未决问题列表:
repo = g.get_repo("xinetzone/d2py")
open_issues = repo.get_issues(state='open')
for issue in open_issues:
print(issue)
Issue(title="项目建设", number=3)
Issue(title="2023 年度计划", number=2)
获取标签:
repo = g.get_repo("xinetzone/d2py")
labels = repo.get_labels()
for label in labels:
print(label)
Label(name="bug")
Label(name="documentation")
Label(name="duplicate")
Label(name="enhancement")
Label(name="good first issue")
Label(name="help wanted")
Label(name="invalid")
Label(name="question")
Label(name="wontfix")
获取存储库根目录的所有内容:
repo = g.get_repo("xinetzone/d2py")
contents = repo.get_contents("")
for content_file in contents:
print(content_file)
ContentFile(path=".github")
ContentFile(path=".gitignore")
ContentFile(path="CONTRIBUTING.md")
ContentFile(path="LICENSE")
ContentFile(path="README.md")
ContentFile(path="SECURITY.md")
ContentFile(path="doc")
ContentFile(path="pyproject.toml")
ContentFile(path="readthedocs.yml")
ContentFile(path="src")
ContentFile(path="tasks.py")
递归地获取存储库的所有内容:
repo = g.get_repo("Xinering/cocoapi")
contents = repo.get_contents("")
while contents:
file_content = contents.pop(0)
if file_content.type == "dir":
contents.extend(repo.get_contents(file_content.path))
else:
print(file_content)
ContentFile(path=".gitignore")
ContentFile(path=".travis.yml")
ContentFile(path="README.txt")
ContentFile(path="license.txt")
ContentFile(path="LuaAPI/CocoApi.lua")
ContentFile(path="LuaAPI/MaskApi.lua")
ContentFile(path="LuaAPI/cocoDemo.lua")
ContentFile(path="LuaAPI/env.lua")
ContentFile(path="LuaAPI/init.lua")
ContentFile(path="MatlabAPI/CocoApi.m")
ContentFile(path="MatlabAPI/CocoEval.m")
ContentFile(path="MatlabAPI/CocoUtils.m")
ContentFile(path="MatlabAPI/MaskApi.m")
ContentFile(path="MatlabAPI/cocoDemo.m")
ContentFile(path="MatlabAPI/evalDemo.m")
ContentFile(path="MatlabAPI/gason.m")
ContentFile(path="PythonAPI/Makefile")
ContentFile(path="PythonAPI/pycocoDemo.ipynb")
ContentFile(path="PythonAPI/pycocoEvalDemo.ipynb")
ContentFile(path="PythonAPI/setup.py")
ContentFile(path="common/gason.cpp")
ContentFile(path="common/gason.h")
ContentFile(path="common/maskApi.c")
ContentFile(path="common/maskApi.h")
ContentFile(path="results/captions_val2014_fakecap_results.json")
ContentFile(path="results/instances_val2014_fakebbox100_results.json")
ContentFile(path="results/instances_val2014_fakesegm100_results.json")
ContentFile(path="results/person_keypoints_val2014_fakekeypoints100_results.json")
ContentFile(path="results/val2014_fake_eval_res.txt")
ContentFile(path="LuaAPI/rocks/coco-scm-1.rockspec")
ContentFile(path="MatlabAPI/private/gasonMex.cpp")
ContentFile(path="MatlabAPI/private/gasonMex.mexa64")
ContentFile(path="MatlabAPI/private/gasonMex.mexmaci64")
ContentFile(path="MatlabAPI/private/getPrmDflt.m")
ContentFile(path="MatlabAPI/private/maskApiMex.c")
ContentFile(path="PythonAPI/pycocotools/__init__.py")
ContentFile(path="PythonAPI/pycocotools/_mask.pyx")
ContentFile(path="PythonAPI/pycocotools/coco.py")
ContentFile(path="PythonAPI/pycocotools/cocoeval.py")
ContentFile(path="PythonAPI/pycocotools/mask.py")
获取特定的内容文件:
repo = g.get_repo("xinetzone/d2py")
contents = repo.get_contents("README.md")
print(contents)
ContentFile(path="README.md")
在存储库中创建新文件:
repo = g.get_repo("PyGithub/PyGithub")
repo.create_file("test.txt", "test", "test", branch="test")
更新存储库中的文件:
repo = g.get_repo("PyGithub/PyGithub")
contents = repo.get_contents("test.txt", ref="test")
repo.update_file(contents.path, "more tests", "more tests", contents.sha, branch="test")
删除存储库中的文件:
repo = g.get_repo("PyGithub/PyGithub")
contents = repo.get_contents("test.txt", ref="test")
repo.delete_file(contents.path, "remove test", contents.sha, branch="test")
获取过去 14 天内排名前 10 位的推荐人:
repo = g.get_repo("PyGithub/PyGithub")
contents = repo.get_top_referrers()
print(contents)
获取过去 14 天最受欢迎的 10 个内容:
repo = g.get_repo("PyGithub/PyGithub")
contents = repo.get_top_paths()
print(contents)
获取过去 14 天的克隆数量和 breakdown:
repo = g.get_repo("PyGithub/PyGithub")
contents = repo.get_clones_traffic()
contents = repo.get_clones_traffic(per="week")
print(contents)
获取过去 14 天的浏览量和细目:
repo = g.get_repo("PyGithub/PyGithub")
contents = repo.get_views_traffic()
contents = repo.get_views_traffic(per="week")
print(contents)
将存储库的通知标记为已读:
repo = g.get_repo("PyGithub/PyGithub")
repo.mark_notifications_as_read()