我有一个 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 只为我提供逻辑中没有不受保护的分支的存储库?