Return 仅在使用 PyGithub 时出现问题
Return only issues using PyGithub
我正在尝试获取存储库中的问题数量,但下面的代码正在返回问题和拉取请求。我怎样才能得到问题?我想我在这里遗漏了一些简单的东西。我阅读了 api 文档,它指出 GitHub 将所有拉取请求视为问题。
repo = g.get_repo("someRepo")
label = repo.get_label('someLabel')
myIssues = repo.get_issues(state='open',labels=[label])
count = 0
for issue in myIssues:
count = count + 1
print(count)
对于只是问题的问题,pull_request
是 None
。
>>> repo = g.get_repo("PyGithub/PyGithub")
>>> open_issues = repo.get_issues(state='open')
>>> for issue in open_issues:
... print(issue)
...
Issue(title="Correct Repository.create_git_tag_and_release()", number=1362)
Issue(title="search_topics returns different number of repositories compared to searching in browser.", number=1352)
>>> print(open_issues[0].pull_request)
<github.IssuePullRequest.IssuePullRequest object at 0x7f320954cb70>
>>> print(open_issues[1].pull_request)
None
>>>
因此您只能计算 issue.pull_request 为 None
的那些问题。
repo = g.get_repo("someRepo")
label = repo.get_label('someLabel')
myIssues = repo.get_issues(state='open',labels=[label])
count = 0
for issue in myIssues:
if not issue.pull_request:
count = count + 1
print(count)
您还可以按如下方式替换您的计数逻辑:
count = sum(not issue.pull_request for issue in myIssues)
我正在尝试获取存储库中的问题数量,但下面的代码正在返回问题和拉取请求。我怎样才能得到问题?我想我在这里遗漏了一些简单的东西。我阅读了 api 文档,它指出 GitHub 将所有拉取请求视为问题。
repo = g.get_repo("someRepo")
label = repo.get_label('someLabel')
myIssues = repo.get_issues(state='open',labels=[label])
count = 0
for issue in myIssues:
count = count + 1
print(count)
对于只是问题的问题,pull_request
是 None
。
>>> repo = g.get_repo("PyGithub/PyGithub")
>>> open_issues = repo.get_issues(state='open')
>>> for issue in open_issues:
... print(issue)
...
Issue(title="Correct Repository.create_git_tag_and_release()", number=1362)
Issue(title="search_topics returns different number of repositories compared to searching in browser.", number=1352)
>>> print(open_issues[0].pull_request)
<github.IssuePullRequest.IssuePullRequest object at 0x7f320954cb70>
>>> print(open_issues[1].pull_request)
None
>>>
因此您只能计算 issue.pull_request 为 None
的那些问题。
repo = g.get_repo("someRepo")
label = repo.get_label('someLabel')
myIssues = repo.get_issues(state='open',labels=[label])
count = 0
for issue in myIssues:
if not issue.pull_request:
count = count + 1
print(count)
您还可以按如下方式替换您的计数逻辑:
count = sum(not issue.pull_request for issue in myIssues)