存储库

存储库#

初始化:

from github import Github

g = Github()
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 from github import Github
      3 g = Github()

ModuleNotFoundError: No module named 'github'

获取存储库主题:

repo = g.get_repo("Xinering/cocoapi")
repo.get_topics()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 repo = g.get_repo("Xinering/cocoapi")
      2 repo.get_topics()

NameError: name 'g' is not defined

计算星星的数量:

repo.stargazers_count
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 repo.stargazers_count

NameError: name 'repo' is not defined

获取未决问题列表:

repo = g.get_repo("xinetzone/d2py")
open_issues = repo.get_issues(state='open')
for issue in open_issues:
    print(issue)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 repo = g.get_repo("xinetzone/d2py")
      2 open_issues = repo.get_issues(state='open')
      3 for issue in open_issues:

NameError: name 'g' is not defined

获取标签:

repo = g.get_repo("xinetzone/d2py")
labels = repo.get_labels()
for label in labels:
    print(label)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[5], line 1
----> 1 repo = g.get_repo("xinetzone/d2py")
      2 labels = repo.get_labels()
      3 for label in labels:

NameError: name 'g' is not defined

获取存储库根目录的所有内容:

repo = g.get_repo("xinetzone/d2py")
contents = repo.get_contents("")
for content_file in contents:
    print(content_file)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 repo = g.get_repo("xinetzone/d2py")
      2 contents = repo.get_contents("")
      3 for content_file in contents:

NameError: name 'g' is not defined

递归地获取存储库的所有内容:

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)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 repo = g.get_repo("Xinering/cocoapi")
      2 contents = repo.get_contents("")
      3 while contents:

NameError: name 'g' is not defined

获取特定的内容文件:

repo = g.get_repo("xinetzone/d2py")
contents = repo.get_contents("README.md")
print(contents)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[8], line 1
----> 1 repo = g.get_repo("xinetzone/d2py")
      2 contents = repo.get_contents("README.md")
      3 print(contents)

NameError: name 'g' is not defined

在存储库中创建新文件:

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()