使用PyGithub仅返回问题

2024-09-29 23:25:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图获取存储库中的问题数量,但下面的代码返回问题和请求。我怎样才能得到问题?我想我错过了一些简单的东西。我阅读了api文档,其中说明GitHub将所有pull请求视为问题

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)

Tags: 代码文档githubapiget数量countrepo
1条回答
网友
1楼 · 发布于 2024-09-29 23:25:04

对于只是问题的问题,pull_requestNone

>>> 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_请求为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)

相关问题 更多 >

    热门问题