kazamori / github-api-tools

CLI tools for GitHub API
Apache License 2.0
3 stars 0 forks source link

Add issue statistics #1

Open t2y opened 3 years ago

t2y commented 3 years ago

Repository class sets attributes related to pull requests only. Add some functions to analyze issue statistics.

class Repository:

    def __enter__(self):
        self.set_extra_attributes()
        return self

    def set_extra_attributes(self):
        self.pulls = list(self.get_pulls())
t2y commented 1 year ago

Now is the time to implement issues.

t2y commented 1 year ago

issue object is like this.

ipdb> pp vars(issue)
{'_CompletableGithubObject__completed': False,
 '_active_lock_reason': <github.GithubObject._ValuedAttribute object at 0x7f496194dcf0>,
 '_assignee': <github.GithubObject._ValuedAttribute object at 0x7f496194d9f0>,
 '_assignees': <github.GithubObject._ValuedAttribute object at 0x7f496194e1d0>,
 '_body': <github.GithubObject._ValuedAttribute object at 0x7f496194da80>,
 '_closed_at': <github.GithubObject._ValuedAttribute object at 0x7f496194e920>,
 '_closed_by': NotSet,
 '_comments': <github.GithubObject._ValuedAttribute object at 0x7f496194e980>,
 '_comments_url': <github.GithubObject._ValuedAttribute object at 0x7f496194e9e0>,
 '_created_at': <github.GithubObject._ValuedAttribute object at 0x7f496194eaa0>,
 '_events_url': <github.GithubObject._ValuedAttribute object at 0x7f496194ea40>,
 '_headers': {'access-control-allow-origin': '*',
              'access-control-expose-headers': 'ETag, Link, Location, '
                                               'Retry-After, X-GitHub-OTP, '
                                               'X-RateLimit-Limit, '
                                               'X-RateLimit-Remaining, '
                                               'X-RateLimit-Used, '
                                               'X-RateLimit-Resource, '
                                               'X-RateLimit-Reset, '
                                               'X-OAuth-Scopes, '
                                               'X-Accepted-OAuth-Scopes, '
                                               'X-Poll-Interval, '
                                               'X-GitHub-Media-Type, '
                                               'X-GitHub-SSO, '
                                               'X-GitHub-Request-Id, '
                                               'Deprecation, Sunset',
              'cache-control': 'private, max-age=60, s-maxage=60',
              'content-encoding': 'gzip',
              'content-security-policy': "default-src 'none'",
              'content-type': 'application/json; charset=utf-8',
              'date': 'Thu, 10 Aug 2023 14:00:52 GMT',
              'etag': 'W/"1d0765b016747b51ec67981bea77148963accb7d58001e411e974800bc50b7a3"',
              'github-authentication-token-expiration': '2023-11-08 21:45:30 '
                                                        '+0900',
              'referrer-policy': 'origin-when-cross-origin, '
                                 'strict-origin-when-cross-origin',
              'server': 'GitHub.com',
              'strict-transport-security': 'max-age=31536000; '
                                           'includeSubdomains; preload',
              'transfer-encoding': 'chunked',
              'vary': 'Accept, Authorization, Cookie, X-GitHub-OTP, '
                      'Accept-Encoding, Accept, X-Requested-With',
              'x-content-type-options': 'nosniff',
              'x-frame-options': 'deny',
              'x-github-api-version-selected': '2022-11-28',
              'x-github-media-type': 'github.v3; format=json',
              'x-github-request-id': 'EE28:70FB:14B97D7:15B5965:64D4ED94',
              'x-ratelimit-limit': '5000',
              'x-ratelimit-remaining': '4993',
              'x-ratelimit-reset': '1691679185',
              'x-ratelimit-resource': 'core',
              'x-ratelimit-used': '7',
              'x-xss-protection': '0'},
 '_html_url': <github.GithubObject._ValuedAttribute object at 0x7f496194eb30>,
 '_id': <github.GithubObject._ValuedAttribute object at 0x7f496194eb90>,
 '_labels': <github.GithubObject._ValuedAttribute object at 0x7f496194ec50>,
 '_labels_url': <github.GithubObject._ValuedAttribute object at 0x7f496194ec20>,
 '_locked': <github.GithubObject._ValuedAttribute object at 0x7f496194ee60>,
 '_milestone': <github.GithubObject._ValuedAttribute object at 0x7f496194ef20>,
 '_number': <github.GithubObject._ValuedAttribute object at 0x7f496194eef0>,
 '_pull_request': NotSet,
 '_rawData': {'active_lock_reason': None,
              'assignee': {'avatar_url': 'https://avatars.githubusercontent.com/u/96569?v=4',
                           'events_url': 'https://api.github.com/users/t2y/events{/privacy}',
                           'followers_url': 'https://api.github.com/users/t2y/followers',
                           'following_url': 'https://api.github.com/users/t2y/following{/other_user}',
                           'gists_url': 'https://api.github.com/users/t2y/gists{/gist_id}',
                           'gravatar_id': '',
                           'html_url': 'https://github.com/t2y',
                           'id': 96569,
                           'login': 't2y',
                           'node_id': 'MDQ6VXNlcjk2NTY5',
                           'organizations_url': 'https://api.github.com/users/t2y/orgs',
                           'received_events_url': 'https://api.github.com/users/t2y/received_events',
                           'repos_url': 'https://api.github.com/users/t2y/repos',
                           'site_admin': False,
                           'starred_url': 'https://api.github.com/users/t2y/starred{/owner}{/repo}',
                           'subscriptions_url': 'https://api.github.com/users/t2y/subscriptions',
                           'type': 'User',
                           'url': 'https://api.github.com/users/t2y'},
              'assignees': [{'avatar_url': 'https://avatars.githubusercontent.com/u/96569?v=4',
                             'events_url': 'https://api.github.com/users/t2y/events{/privacy}',
                             'followers_url': 'https://api.github.com/users/t2y/followers',
                             'following_url': 'https://api.github.com/users/t2y/following{/other_user}',
                             'gists_url': 'https://api.github.com/users/t2y/gists{/gist_id}',
                             'gravatar_id': '',
                             'html_url': 'https://github.com/t2y',
                             'id': 96569,
                             'login': 't2y',
                             'node_id': 'MDQ6VXNlcjk2NTY5',
                             'organizations_url': 'https://api.github.com/users/t2y/orgs',
                             'received_events_url': 'https://api.github.com/users/t2y/received_events',
                             'repos_url': 'https://api.github.com/users/t2y/repos',
                             'site_admin': False,
                             'starred_url': 'https://api.github.com/users/t2y/starred{/owner}{/repo}',
                             'subscriptions_url': 'https://api.github.com/users/t2y/subscriptions',
                             'type': 'User',
                             'url': 'https://api.github.com/users/t2y'}],
              'author_association': 'MEMBER',
              'body': '*Repository* class sets attributes related to pull '
                      'requests only. Add some functions to analyze issue '
                      'statistics.\r\n'
                      '\r\n'
                      '```python\r\n'
                      'class Repository:\r\n'
                      '\r\n'
                      '    def __enter__(self):\r\n'
                      '        self.set_extra_attributes()\r\n'
                      '        return self\r\n'
                      '\r\n'
                      '    def set_extra_attributes(self):\r\n'
                      '        self.pulls = list(self.get_pulls())\r\n'
                      '```',
              'closed_at': None,
              'comments': 1,
              'comments_url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/1/comments',
              'created_at': '2021-06-02T02:20:45Z',
              'events_url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/1/events',
              'html_url': 'https://github.com/kazamori/github-api-tools/issues/1',
              'id': 908995468,
              'labels': [{'color': 'a2eeef',
                          'default': True,
                          'description': 'New feature or request',
                          'id': 1937907186,
                          'name': 'enhancement',
                          'node_id': 'MDU6TGFiZWwxOTM3OTA3MTg2',
                          'url': 'https://api.github.com/repos/kazamori/github-api-tools/labels/enhancement'}],
              'labels_url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/1/labels{/name}',
              'locked': False,
              'milestone': None,
              'node_id': 'MDU6SXNzdWU5MDg5OTU0Njg=',
              'number': 1,
              'performed_via_github_app': None,
              'reactions': {'+1': 0,
                            '-1': 0,
                            'confused': 0,
                            'eyes': 0,
                            'heart': 0,
                            'hooray': 0,
                            'laugh': 0,
                            'rocket': 0,
                            'total_count': 0,
                            'url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/1/reactions'},
              'repository_url': 'https://api.github.com/repos/kazamori/github-api-tools',
              'state': 'open',
              'state_reason': None,
              'timeline_url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/1/timeline',
              'title': 'Add issue statistics',
              'updated_at': '2023-08-10T13:42:56Z',
              'url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/1',
              'user': {'avatar_url': 'https://avatars.githubusercontent.com/u/96569?v=4',
                       'events_url': 'https://api.github.com/users/t2y/events{/privacy}',
                       'followers_url': 'https://api.github.com/users/t2y/followers',
                       'following_url': 'https://api.github.com/users/t2y/following{/other_user}',
                       'gists_url': 'https://api.github.com/users/t2y/gists{/gist_id}',
                       'gravatar_id': '',
                       'html_url': 'https://github.com/t2y',
                       'id': 96569,
                       'login': 't2y',
                       'node_id': 'MDQ6VXNlcjk2NTY5',
                       'organizations_url': 'https://api.github.com/users/t2y/orgs',
                       'received_events_url': 'https://api.github.com/users/t2y/received_events',
                       'repos_url': 'https://api.github.com/users/t2y/repos',
                       'site_admin': False,
                       'starred_url': 'https://api.github.com/users/t2y/starred{/owner}{/repo}',
                       'subscriptions_url': 'https://api.github.com/users/t2y/subscriptions',
                       'type': 'User',
                       'url': 'https://api.github.com/users/t2y'}},
 '_repository': NotSet,
 '_requester': <github.Requester.Requester object at 0x7f4961af24a0>,
 '_state': <github.GithubObject._ValuedAttribute object at 0x7f496194ef80>,
 '_state_reason': <github.GithubObject._ValuedAttribute object at 0x7f496194efe0>,
 '_title': <github.GithubObject._ValuedAttribute object at 0x7f496194f040>,
 '_updated_at': <github.GithubObject._ValuedAttribute object at 0x7f496194f100>,
 '_url': <github.GithubObject._ValuedAttribute object at 0x7f496194f0a0>,
 '_user': <github.GithubObject._ValuedAttribute object at 0x7f496194f220>}
t2y commented 1 year ago

I want to get these items.

t2y commented 1 year ago

issue comments data is like this.

[{'author_association': 'MEMBER',
  'body': 'Now is the time to implement issues.\r\n'
          '\r\n'
          '* '
          'https://pygithub.readthedocs.io/en/stable/github_objects/Issue.html',
  'created_at': '2023-08-10T13:42:55Z',
  'html_url': 'https://github.com/kazamori/github-api-tools/issues/1#issuecomment-1673251314',
  'id': 1673251314,
  'issue_url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/1',
  'node_id': 'IC_kwDODu1XzM5ju8ny',
  'performed_via_github_app': None,
  'reactions': {'+1': 0,
                '-1': 0,
                'confused': 0,
                'eyes': 0,
                'heart': 0,
                'hooray': 0,
                'laugh': 0,
                'rocket': 0,
                'total_count': 0,
                'url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/comments/1673251314/reactions'},
  'updated_at': '2023-08-10T13:42:55Z',
  'url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/comments/1673251314',
  'user': {'avatar_url': 'https://avatars.githubusercontent.com/u/96569?v=4',
           'events_url': 'https://api.github.com/users/t2y/events{/privacy}',
           'followers_url': 'https://api.github.com/users/t2y/followers',
           'following_url': 'https://api.github.com/users/t2y/following{/other_user}',
           'gists_url': 'https://api.github.com/users/t2y/gists{/gist_id}',
           'gravatar_id': '',
           'html_url': 'https://github.com/t2y',
           'id': 96569,
           'login': 't2y',
           'node_id': 'MDQ6VXNlcjk2NTY5',
           'organizations_url': 'https://api.github.com/users/t2y/orgs',
           'received_events_url': 'https://api.github.com/users/t2y/received_events',
           'repos_url': 'https://api.github.com/users/t2y/repos',
           'site_admin': False,
           'starred_url': 'https://api.github.com/users/t2y/starred{/owner}{/repo}',
           'subscriptions_url': 'https://api.github.com/users/t2y/subscriptions',
           'type': 'User',
           'url': 'https://api.github.com/users/t2y'}},
 {'author_association': 'MEMBER',
  'body': 'issue object is like this.\r\n'
          '\r\n'
          '```\r\n'
          'ipdb> pp vars(issue)\r\n'
          "{'_CompletableGithubObject__completed': False,\r\n"
          " '_active_lock_reason': <github.GithubObject._ValuedAttribute "
          'object at 0x7f496194dcf0>,\r\n'
          " '_assignee': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194d9f0>,\r\n'
          " '_assignees': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194e1d0>,\r\n'
          " '_body': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194da80>,\r\n'
          " '_closed_at': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194e920>,\r\n'
          " '_closed_by': NotSet,\r\n"
          " '_comments': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194e980>,\r\n'
          " '_comments_url': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194e9e0>,\r\n'
          " '_created_at': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194eaa0>,\r\n'
          " '_events_url': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194ea40>,\r\n'
          " '_headers': {'access-control-allow-origin': '*',\r\n"
          "              'access-control-expose-headers': 'ETag, Link, "
          "Location, '\r\n"
          "                                               'Retry-After, "
          "X-GitHub-OTP, '\r\n"
          "                                               'X-RateLimit-Limit, "
          "'\r\n"
          '                                               '
          "'X-RateLimit-Remaining, '\r\n"
          "                                               'X-RateLimit-Used, "
          "'\r\n"
          '                                               '
          "'X-RateLimit-Resource, '\r\n"
          "                                               'X-RateLimit-Reset, "
          "'\r\n"
          "                                               'X-OAuth-Scopes, "
          "'\r\n"
          '                                               '
          "'X-Accepted-OAuth-Scopes, '\r\n"
          "                                               'X-Poll-Interval, "
          "'\r\n"
          '                                               '
          "'X-GitHub-Media-Type, '\r\n"
          "                                               'X-GitHub-SSO, '\r\n"
          '                                               '
          "'X-GitHub-Request-Id, '\r\n"
          "                                               'Deprecation, "
          "Sunset',\r\n"
          "              'cache-control': 'private, max-age=60, "
          "s-maxage=60',\r\n"
          "              'content-encoding': 'gzip',\r\n"
          '              \'content-security-policy\': "default-src '
          '\'none\'",\r\n'
          "              'content-type': 'application/json; charset=utf-8',\r\n"
          "              'date': 'Thu, 10 Aug 2023 14:00:52 GMT',\r\n"
          "              'etag': "
          '\'W/"1d0765b016747b51ec67981bea77148963accb7d58001e411e974800bc50b7a3"\',\r\n'
          "              'github-authentication-token-expiration': '2023-11-08 "
          "21:45:30 '\r\n"
          "                                                        '+0900',\r\n"
          "              'referrer-policy': 'origin-when-cross-origin, '\r\n"
          '                                 '
          "'strict-origin-when-cross-origin',\r\n"
          "              'server': 'GitHub.com',\r\n"
          "              'strict-transport-security': 'max-age=31536000; '\r\n"
          "                                           'includeSubdomains; "
          "preload',\r\n"
          "              'transfer-encoding': 'chunked',\r\n"
          "              'vary': 'Accept, Authorization, Cookie, X-GitHub-OTP, "
          "'\r\n"
          "                      'Accept-Encoding, Accept, "
          "X-Requested-With',\r\n"
          "              'x-content-type-options': 'nosniff',\r\n"
          "              'x-frame-options': 'deny',\r\n"
          "              'x-github-api-version-selected': '2022-11-28',\r\n"
          "              'x-github-media-type': 'github.v3; format=json',\r\n"
          "              'x-github-request-id': "
          "'EE28:70FB:14B97D7:15B5965:64D4ED94',\r\n"
          "              'x-ratelimit-limit': '5000',\r\n"
          "              'x-ratelimit-remaining': '4993',\r\n"
          "              'x-ratelimit-reset': '1691679185',\r\n"
          "              'x-ratelimit-resource': 'core',\r\n"
          "              'x-ratelimit-used': '7',\r\n"
          "              'x-xss-protection': '0'},\r\n"
          " '_html_url': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194eb30>,\r\n'
          " '_id': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194eb90>,\r\n'
          " '_labels': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194ec50>,\r\n'
          " '_labels_url': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194ec20>,\r\n'
          " '_locked': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194ee60>,\r\n'
          " '_milestone': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194ef20>,\r\n'
          " '_number': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194eef0>,\r\n'
          " '_pull_request': NotSet,\r\n"
          " '_rawData': {'active_lock_reason': None,\r\n"
          "              'assignee': {'avatar_url': "
          "'https://avatars.githubusercontent.com/u/96569?v=4',\r\n"
          "                           'events_url': "
          "'https://api.github.com/users/t2y/events{/privacy}',\r\n"
          "                           'followers_url': "
          "'https://api.github.com/users/t2y/followers',\r\n"
          "                           'following_url': "
          "'https://api.github.com/users/t2y/following{/other_user}',\r\n"
          "                           'gists_url': "
          "'https://api.github.com/users/t2y/gists{/gist_id}',\r\n"
          "                           'gravatar_id': '',\r\n"
          "                           'html_url': 'https://github.com/t2y',\r\n"
          "                           'id': 96569,\r\n"
          "                           'login': 't2y',\r\n"
          "                           'node_id': 'MDQ6VXNlcjk2NTY5',\r\n"
          "                           'organizations_url': "
          "'https://api.github.com/users/t2y/orgs',\r\n"
          "                           'received_events_url': "
          "'https://api.github.com/users/t2y/received_events',\r\n"
          "                           'repos_url': "
          "'https://api.github.com/users/t2y/repos',\r\n"
          "                           'site_admin': False,\r\n"
          "                           'starred_url': "
          "'https://api.github.com/users/t2y/starred{/owner}{/repo}',\r\n"
          "                           'subscriptions_url': "
          "'https://api.github.com/users/t2y/subscriptions',\r\n"
          "                           'type': 'User',\r\n"
          "                           'url': "
          "'https://api.github.com/users/t2y'},\r\n"
          "              'assignees': [{'avatar_url': "
          "'https://avatars.githubusercontent.com/u/96569?v=4',\r\n"
          "                             'events_url': "
          "'https://api.github.com/users/t2y/events{/privacy}',\r\n"
          "                             'followers_url': "
          "'https://api.github.com/users/t2y/followers',\r\n"
          "                             'following_url': "
          "'https://api.github.com/users/t2y/following{/other_user}',\r\n"
          "                             'gists_url': "
          "'https://api.github.com/users/t2y/gists{/gist_id}',\r\n"
          "                             'gravatar_id': '',\r\n"
          "                             'html_url': "
          "'https://github.com/t2y',\r\n"
          "                             'id': 96569,\r\n"
          "                             'login': 't2y',\r\n"
          "                             'node_id': 'MDQ6VXNlcjk2NTY5',\r\n"
          "                             'organizations_url': "
          "'https://api.github.com/users/t2y/orgs',\r\n"
          "                             'received_events_url': "
          "'https://api.github.com/users/t2y/received_events',\r\n"
          "                             'repos_url': "
          "'https://api.github.com/users/t2y/repos',\r\n"
          "                             'site_admin': False,\r\n"
          "                             'starred_url': "
          "'https://api.github.com/users/t2y/starred{/owner}{/repo}',\r\n"
          "                             'subscriptions_url': "
          "'https://api.github.com/users/t2y/subscriptions',\r\n"
          "                             'type': 'User',\r\n"
          "                             'url': "
          "'https://api.github.com/users/t2y'}],\r\n"
          "              'author_association': 'MEMBER',\r\n"
          "              'body': '*Repository* class sets attributes related "
          "to pull '\r\n"
          "                      'requests only. Add some functions to analyze "
          "issue '\r\n"
          "                      'statistics.\\r\\n'\r\n"
          "                      '\\r\\n'\r\n"
          "                      '```python\\r\\n'\r\n"
          "                      'class Repository:\\r\\n'\r\n"
          "                      '\\r\\n'\r\n"
          "                      '    def __enter__(self):\\r\\n'\r\n"
          "                      '        "
          "self.set_extra_attributes()\\r\\n'\r\n"
          "                      '        return self\\r\\n'\r\n"
          "                      '\\r\\n'\r\n"
          "                      '    def "
          "set_extra_attributes(self):\\r\\n'\r\n"
          "                      '        self.pulls = "
          "list(self.get_pulls())\\r\\n'\r\n"
          "                      '```',\r\n"
          "              'closed_at': None,\r\n"
          "              'comments': 1,\r\n"
          "              'comments_url': "
          "'https://api.github.com/repos/kazamori/github-api-tools/issues/1/comments',\r\n"
          "              'created_at': '2021-06-02T02:20:45Z',\r\n"
          "              'events_url': "
          "'https://api.github.com/repos/kazamori/github-api-tools/issues/1/events',\r\n"
          "              'html_url': "
          "'https://github.com/kazamori/github-api-tools/issues/1',\r\n"
          "              'id': 908995468,\r\n"
          "              'labels': [{'color': 'a2eeef',\r\n"
          "                          'default': True,\r\n"
          "                          'description': 'New feature or "
          "request',\r\n"
          "                          'id': 1937907186,\r\n"
          "                          'name': 'enhancement',\r\n"
          "                          'node_id': 'MDU6TGFiZWwxOTM3OTA3MTg2',\r\n"
          "                          'url': "
          "'https://api.github.com/repos/kazamori/github-api-tools/labels/enhancement'}],\r\n"
          "              'labels_url': "
          "'https://api.github.com/repos/kazamori/github-api-tools/issues/1/labels{/name}',\r\n"
          "              'locked': False,\r\n"
          "              'milestone': None,\r\n"
          "              'node_id': 'MDU6SXNzdWU5MDg5OTU0Njg=',\r\n"
          "              'number': 1,\r\n"
          "              'performed_via_github_app': None,\r\n"
          "              'reactions': {'+1': 0,\r\n"
          "                            '-1': 0,\r\n"
          "                            'confused': 0,\r\n"
          "                            'eyes': 0,\r\n"
          "                            'heart': 0,\r\n"
          "                            'hooray': 0,\r\n"
          "                            'laugh': 0,\r\n"
          "                            'rocket': 0,\r\n"
          "                            'total_count': 0,\r\n"
          "                            'url': "
          "'https://api.github.com/repos/kazamori/github-api-tools/issues/1/reactions'},\r\n"
          "              'repository_url': "
          "'https://api.github.com/repos/kazamori/github-api-tools',\r\n"
          "              'state': 'open',\r\n"
          "              'state_reason': None,\r\n"
          "              'timeline_url': "
          "'https://api.github.com/repos/kazamori/github-api-tools/issues/1/timeline',\r\n"
          "              'title': 'Add issue statistics',\r\n"
          "              'updated_at': '2023-08-10T13:42:56Z',\r\n"
          "              'url': "
          "'https://api.github.com/repos/kazamori/github-api-tools/issues/1',\r\n"
          "              'user': {'avatar_url': "
          "'https://avatars.githubusercontent.com/u/96569?v=4',\r\n"
          "                       'events_url': "
          "'https://api.github.com/users/t2y/events{/privacy}',\r\n"
          "                       'followers_url': "
          "'https://api.github.com/users/t2y/followers',\r\n"
          "                       'following_url': "
          "'https://api.github.com/users/t2y/following{/other_user}',\r\n"
          "                       'gists_url': "
          "'https://api.github.com/users/t2y/gists{/gist_id}',\r\n"
          "                       'gravatar_id': '',\r\n"
          "                       'html_url': 'https://github.com/t2y',\r\n"
          "                       'id': 96569,\r\n"
          "                       'login': 't2y',\r\n"
          "                       'node_id': 'MDQ6VXNlcjk2NTY5',\r\n"
          "                       'organizations_url': "
          "'https://api.github.com/users/t2y/orgs',\r\n"
          "                       'received_events_url': "
          "'https://api.github.com/users/t2y/received_events',\r\n"
          "                       'repos_url': "
          "'https://api.github.com/users/t2y/repos',\r\n"
          "                       'site_admin': False,\r\n"
          "                       'starred_url': "
          "'https://api.github.com/users/t2y/starred{/owner}{/repo}',\r\n"
          "                       'subscriptions_url': "
          "'https://api.github.com/users/t2y/subscriptions',\r\n"
          "                       'type': 'User',\r\n"
          "                       'url': "
          "'https://api.github.com/users/t2y'}},\r\n"
          " '_repository': NotSet,\r\n"
          " '_requester': <github.Requester.Requester object at "
          '0x7f4961af24a0>,\r\n'
          " '_state': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194ef80>,\r\n'
          " '_state_reason': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194efe0>,\r\n'
          " '_title': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194f040>,\r\n'
          " '_updated_at': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194f100>,\r\n'
          " '_url': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194f0a0>,\r\n'
          " '_user': <github.GithubObject._ValuedAttribute object at "
          '0x7f496194f220>}\r\n'
          '```',
  'created_at': '2023-08-10T14:02:02Z',
  'html_url': 'https://github.com/kazamori/github-api-tools/issues/1#issuecomment-1673283866',
  'id': 1673283866,
  'issue_url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/1',
  'node_id': 'IC_kwDODu1XzM5jvEka',
  'performed_via_github_app': None,
  'reactions': {'+1': 0,
                '-1': 0,
                'confused': 0,
                'eyes': 0,
                'heart': 0,
                'hooray': 0,
                'laugh': 0,
                'rocket': 0,
                'total_count': 0,
                'url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/comments/1673283866/reactions'},
  'updated_at': '2023-08-10T14:02:02Z',
  'url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/comments/1673283866',
  'user': {'avatar_url': 'https://avatars.githubusercontent.com/u/96569?v=4',
           'events_url': 'https://api.github.com/users/t2y/events{/privacy}',
           'followers_url': 'https://api.github.com/users/t2y/followers',
           'following_url': 'https://api.github.com/users/t2y/following{/other_user}',
           'gists_url': 'https://api.github.com/users/t2y/gists{/gist_id}',
           'gravatar_id': '',
           'html_url': 'https://github.com/t2y',
           'id': 96569,
           'login': 't2y',
           'node_id': 'MDQ6VXNlcjk2NTY5',
           'organizations_url': 'https://api.github.com/users/t2y/orgs',
           'received_events_url': 'https://api.github.com/users/t2y/received_events',
           'repos_url': 'https://api.github.com/users/t2y/repos',
           'site_admin': False,
           'starred_url': 'https://api.github.com/users/t2y/starred{/owner}{/repo}',
           'subscriptions_url': 'https://api.github.com/users/t2y/subscriptions',
           'type': 'User',
           'url': 'https://api.github.com/users/t2y'}},
 {'author_association': 'MEMBER',
  'body': 'I want to get these items.\r\n'
          '\r\n'
          '* title => issue.title\r\n'
          '* created date => issue.created_at\r\n'
          '* description => issue.body\r\n'
          '* labels => issue.labels\r\n'
          '* number of comments => issue.comments\r\n'
          '* comments => issue.comments_url\r\n'
          '  * need to fetch the given url',
  'created_at': '2023-08-10T14:15:37Z',
  'html_url': 'https://github.com/kazamori/github-api-tools/issues/1#issuecomment-1673308936',
  'id': 1673308936,
  'issue_url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/1',
  'node_id': 'IC_kwDODu1XzM5jvKsI',
  'performed_via_github_app': None,
  'reactions': {'+1': 0,
                '-1': 0,
                'confused': 0,
                'eyes': 0,
                'heart': 0,
                'hooray': 0,
                'laugh': 0,
                'rocket': 0,
                'total_count': 0,
                'url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/comments/1673308936/reactions'},
  'updated_at': '2023-08-10T14:15:37Z',
  'url': 'https://api.github.com/repos/kazamori/github-api-tools/issues/comments/1673308936',
  'user': {'avatar_url': 'https://avatars.githubusercontent.com/u/96569?v=4',
           'events_url': 'https://api.github.com/users/t2y/events{/privacy}',
           'followers_url': 'https://api.github.com/users/t2y/followers',
           'following_url': 'https://api.github.com/users/t2y/following{/other_user}',
           'gists_url': 'https://api.github.com/users/t2y/gists{/gist_id}',
           'gravatar_id': '',
           'html_url': 'https://github.com/t2y',
           'id': 96569,
           'login': 't2y',
           'node_id': 'MDQ6VXNlcjk2NTY5',
           'organizations_url': 'https://api.github.com/users/t2y/orgs',
           'received_events_url': 'https://api.github.com/users/t2y/received_events',
           'repos_url': 'https://api.github.com/users/t2y/repos',
           'site_admin': False,
           'starred_url': 'https://api.github.com/users/t2y/starred{/owner}{/repo}',
           'subscriptions_url': 'https://api.github.com/users/t2y/subscriptions',
           'type': 'User',
           'url': 'https://api.github.com/users/t2y'}}]
t2y commented 1 year ago

Ah, PyGithub provides a simple API to get comments. It's useful.

ipdb> for comment in issue.get_comments(): print(comment)
IssueComment(user=NamedUser(login="t2y"), id=1673251314)
IssueComment(user=NamedUser(login="t2y"), id=1673283866)
IssueComment(user=NamedUser(login="t2y"), id=1673308936)
IssueComment(user=NamedUser(login="t2y"), id=1673311984)
t2y commented 1 year ago

I added an initial implementation for testing.

How to run

$ gh-cli-issues --verbose --disable-cache --repository kazamori/github-api-tools 
$ jq . github-api-tools-issues.json  # stored as JSONL
terapyon commented 1 year ago

@t2y

I tried to get issue comment, but I found a bug. I got same comment in "comments_" filed. Please check it.

$ jq . github-api-tools-issues-1.json 
{
  "body": "*Repository* class sets attributes related to pull requests only. Add some functions to analyze issue statistics.\r\n\r\n```python\r\nclass Repository:\r\n\r\n    def __enter__(self):\r\n        self.set_extra_attributes()\r\n        return self\r\n\r\n    def set_extra_attributes(self):\r\n        self.pulls = list(self.get_pulls())\r\n```",
  "comments": 6,
  "comments_": [
    {
      "created_at": "2023-08-10 15:50:45+00:00",
      "body": "I added an initial implementation for testing.\r\n\r\n### How to run\r\n\r\n```bash\r\n$ gh-cli-issues --verbose --disable-cache --repository kazamori/github-api-tools \r\n$ jq . github-api-tools-issues.json  # stored as JSONL\r\n```",
      "user.login": "t2y"
    },
    {
      "created_at": "2023-08-10 15:50:45+00:00",
      "body": "I added an initial implementation for testing.\r\n\r\n### How to run\r\n\r\n```bash\r\n$ gh-cli-issues --verbose --disable-cache --repository kazamori/github-api-tools \r\n$ jq . github-api-tools-issues.json  # stored as JSONL\r\n```",
      "user.login": "t2y"
    },
    {
      "created_at": "2023-08-10 15:50:45+00:00",
      "body": "I added an initial implementation for testing.\r\n\r\n### How to run\r\n\r\n```bash\r\n$ gh-cli-issues --verbose --disable-cache --repository kazamori/github-api-tools \r\n$ jq . github-api-tools-issues.json  # stored as JSONL\r\n```",
      "user.login": "t2y"
    },
    {
      "created_at": "2023-08-10 15:50:45+00:00",
      "body": "I added an initial implementation for testing.\r\n\r\n### How to run\r\n\r\n```bash\r\n$ gh-cli-issues --verbose --disable-cache --repository kazamori/github-api-tools \r\n$ jq . github-api-tools-issues.json  # stored as JSONL\r\n```",
      "user.login": "t2y"
    },
    {
      "created_at": "2023-08-10 15:50:45+00:00",
      "body": "I added an initial implementation for testing.\r\n\r\n### How to run\r\n\r\n```bash\r\n$ gh-cli-issues --verbose --disable-cache --repository kazamori/github-api-tools \r\n$ jq . github-api-tools-issues.json  # stored as JSONL\r\n```",
      "user.login": "t2y"
    },
    {
      "created_at": "2023-08-10 15:50:45+00:00",
      "body": "I added an initial implementation for testing.\r\n\r\n### How to run\r\n\r\n```bash\r\n$ gh-cli-issues --verbose --disable-cache --repository kazamori/github-api-tools \r\n$ jq . github-api-tools-issues.json  # stored as JSONL\r\n```",
      "user.login": "t2y"
    }
  ],
  "created_at": "2021-06-02 02:20:45+00:00",
  "html_url": "https://github.com/kazamori/github-api-tools/issues/1",
  "labels_": [
    "enhancement"
  ],
  "number": 1,
  "title": "Add issue statistics",
  "user.login": "t2y"
}
terapyon commented 1 year ago

I want to get more information of comment. It is "comment_id" or "comment_uid".

Like this:

  "comments_": [
    {
      "created_at": "2023-08-10 15:50:45+00:00",
      "comment_id": "issuecomment-1674044913",
      "body": "",
      "user.login": ""
    }, ...
t2y commented 1 year ago

@terapyon Thanks for reviewing. I added an issue comment two attributes: id and html_url. Are these attributes satisfy your requirement?

    {
      "body": "Now is the time to implement issues.\r\n\r\n* https://pygithub.readthedocs.io/en/stable/github_objects/Issue.html",
      "created_at": "2023-08-10 13:42:55+00:00",
      "html_url": "https://github.com/kazamori/github-api-tools/issues/1#issuecomment-1673251314",
      "id": 1673251314,
      "user.login": "t2y"
    },
terapyon commented 1 year ago

@t2y perfect!! Thank you added attributes and fix the bug soon.

terapyon commented 1 year ago

@t2y I want to get the issues (include comment) by datetime range. Can you support by the tool?

t2y commented 1 year ago

The gh-cli-issues has some options from common_option.py. I haven't implemented all the options. But, --from and --to already exist.

(misc) $ gh-cli-issues -h
usage: gh-cli-issues [-h] [--from DATEFROM] [--to DATETO] [--disable-cache] [--nop] [--repository [REPOSITORIES ...]] [--user USER] [--verbose] [--version]

options:
  -h, --help            show this help message and exit
  --from DATEFROM       filter created_at FROM: e.g. 2020-04-06
  --to DATETO           filter created_at TO: e.g. 2020-04-06
  --disable-cache       disable cache
  --nop                 use as a separator for option handling of positional argument
  --repository [REPOSITORIES ...]
                        set repositories
  --user USER           set user to filter assignee of pull request
  --verbose             set verbose mode
  --version             show version
t2y commented 1 year ago

args.datefrom passed into PyGitHub as since parameter.

    def get_issues(self):
        since = NotSet if self.args.datefrom is None else self.args.datefrom
        for issue in self.repo.get_issues(since=since):
            ...
t2y commented 1 year ago

It seems --from option is valid and filtered results that were last updated after the given time.

$ gh-cli-issues --verbose --disable-cache --repository cocoa-mhlw/cocoa --from "2022-09-15"
2023-09-02 12:25:31,777 DEBUG Namespace(datefrom=datetime.datetime(2022, 9, 15, 0, 0, tzinfo=<UTC>), dateto=datetime.datetime(2023, 9, 2, 12, 25, 31, 776773, tzinfo=<UTC>), enable_cache=False, nop=False, repositories=['cocoa-mhlw/cocoa'], user=None, verbose=True, version='0.0.4', api=<GithubAPI.ISSUES: 'issues'>)
2023-09-02 12:25:32,250 INFO Repository: cocoa
2023-09-02 12:25:32,250 INFO           : https://github.com/cocoa-mhlw/cocoa
2023-09-02 12:25:32,865 INFO #1197: COCOA公開Webミーティングスクリプト comments (0)
2023-09-02 12:25:34,002 DEBUG  - labels: ['documentation']
2023-09-02 12:25:34,002 INFO #1144: COCOAの総括(オープンソースコミュニティとして) comments (14)
2023-09-02 12:25:35,547 DEBUG  - labels: ['discussion']
2023-09-02 12:25:35,547 INFO #1121: 遠距離の信号を接触判定および表示から除外することを検討する comments (10)
2023-09-02 12:25:36,730 DEBUG  - labels: ['enhancement', 'waiting-for-confirmation']
2023-09-02 12:25:36,730 INFO #627: アプリ内で表示される陽性登録方法の説明が不統一 comments (2)
2023-09-02 12:25:37,961 DEBUG  - labels: ['design', 'confirmed']
2023-09-02 12:25:37,965 INFO wrote data into cocoa-issues.json
t2y commented 1 year ago

But --to option has not been implemented yet. The GitHub REST API doesn't have the parameter, so I have to implement in github-api-tools.

t2y commented 1 year ago

Additionally, I found that state=open is the default behavior. I think state=all is desirable.

t2y commented 1 year ago

Also, GitHub considers a pull request as an issue. So, we can get pull requests with issues. :thinking:

Note: GitHub's REST API considers every pull request an issue, but not every issue is a pull request. For this reason, "Issues" endpoints may return both issues and pull requests in the response. You can identify pull requests by the pull_request key. Be aware that the id of a pull request returned from "Issues" endpoints will be an issue id. To find out the pull request id, use the "List pull requests" endpoint.

https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#list-repository-issues

t2y commented 1 year ago

I implemented filtering assignee by --user option. You can run like this.

$ gh-cli-issues --verbose --disable-cache --repository kazamori/github-api-tools --user t2y
t2y commented 1 year ago

@terapyon I updated github-api-tools with some improvements. The --from option can be set as a date string, but --to option has no effect since GitHub REST API doesn't have the feature. Could you accept your requirements only --from option?