Created
September 26, 2016 21:53
-
-
Save carlos-jenkins/3e590d9c74e4af7f239bde5c2c61ae58 to your computer and use it in GitHub Desktop.
Get open/closed Github issues and pull requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
from logging import getLogger as get_logger # noqa | |
from datetime import datetime | |
from github import Github | |
log = get_logger(__name__) | |
def repository_statistics(connection, repository, itype): | |
assert itype in ['issue', 'pr'] | |
statistics = { | |
'closed': 0, | |
'open': 0 | |
} | |
for issue in connection.search_issues('', repo=repository, type=itype): | |
statistics[issue.state] += 1 | |
return statistics | |
def repository_issues(connection, repository): | |
return repository_statistics(connection, repository, itype='issue') | |
def repository_pull_requests(connection, repository): | |
return repository_statistics(connection, repository, itype='pr') | |
# EXAMPLE | |
print('Login in...') | |
g = Github( | |
login_or_token='TOKENHERE', | |
base_url='https://github.hpe.com/api/v3' | |
) | |
print('Fetching issues...') | |
start = datetime.now() | |
issues = repository_issues(g, 'hpe-networking/provision-sdk') | |
elapsed = datetime.now() - start | |
print('Issues:: closed: {} open: {} elapsed time (s): {}'.format( | |
issues['closed'], | |
issues['open'], | |
elapsed.total_seconds() | |
)) | |
print('Fetching pull requests...') | |
start = datetime.now() | |
pull_requests = repository_pull_requests(g, 'REPOSITORYNAME') | |
elapsed = datetime.now() - start | |
print('Pull Requests:: closed: {} open: {} elapsed time (s): {}'.format( | |
pull_requests['closed'], | |
pull_requests['open'], | |
elapsed.total_seconds() | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment