0

I want to get all comments of all Github`s issues. I've read the guide here: https://buildmedia.readthedocs.org/media/pdf/pygithub/stable/pygithub.pdf

Following the script:

from github import Github

g = Github(base_url="https://github.com/api/v3", login_or_token="XXX")
r = g.get_repo("ORG/REPO")
i = r.get_issues(state='open')
c = i.get_comments()

for issue in c:
    print(issue)

But I got the following stdout:

AttributeError: 'PaginatedList' object has no attribute 'get_comments'

I expected to see every comment from each "issue" collected by the for

help-info.de
  • 6,695
  • 16
  • 39
  • 41

1 Answers1

1

You are trying to use an attribute that is not included in PaginatedList. For more info: link

To get comments from issues, you need to extract all comments from a single issue, and keep doing that for every issue. This line is not is not achieving that c = i.get_comments(). I located this question which has a solution for the behavior you're looking for: link

Also, there's a couple of things I would like to point out in your code:

  1. g = Github(base_url="https://github.com/api/v3", login_or_token="XXX") This GitHub instance is for Github Enterprise with custom domain. Your URL is missing the domain name. The URL should be in this format: https://github.xxx.com/api/v3. If you don't have Enterprise account, you could create an instance using either your login/password or a token. Reference.

  2. Are you trying to get comments from a specific organization or from all repositories? I ask because r = g.get_repo("ORG/REPO") returns requests from an organization. To specify all repositories instead, use g.get_repo("repositories). Also, note that requests are limited to 5000 requests, and you need to use Link Header to specify more. Reference

  3. Your current code specifies comments in open issues, and doesn't consider closed issues as well. To return all comments in all issues, include open and closed issues; i = r.get_issues(state='all') Reference

abdullahalali
  • 396
  • 2
  • 5
  • 18