我有一个GitHub Enterprise的实例,我正在尝试在没有受保护分支的存储库的GHE中对我的组织进行审计。我能够使用PyGitHub找到哪些存储库分支受到保护。但我试图找出Python逻辑,它只会给我没有任何受保护分支的存储库。 GitHub的API仅提供受保护的分支。
到目前为止,这是我的代码:
from github import Github
g = Github(access_token, base_url='<github-enterprise-url>/api/v3')
for repo in g.get_organization('orgName').get_repos():
for branch in repo.get_branches():
b = repo.get_branch(branch.name)
u = g.get_user()
if b.protected:
print("Repo is --> ",repo.name, "| Repo ID is ", repo.id ,"| Branch --> ", b.name, " (protected)")
else:
print("Repo is --> ",repo.name, "| Repo ID is ", repo.id ,"| Branch --> ", b.name, " (not protected)")
我得到的输出是:
Repo is --> puppet | Repo ID is 2 | Branch --> dev (protected)
Repo is --> puppet | Repo ID is 2 | Branch --> master (not protected)
Repo is --> java | Repo ID is 3 | Branch --> master (not protected)
Repo is --> foobar| Repo ID is 7 | Branch --> master (not protected)
Repo is --> afu.github.io | Repo ID is 8 | Branch --> master (protected)
我如何使用Python只给出了逻辑中没有不受保护的分支的回购?