Last active
August 29, 2015 13:56
-
-
Save eko/8832124 to your computer and use it in GitHub Desktop.
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
import requests | |
class Api(object): | |
""" This is the Github API class """ | |
def __init__(self, url, login, password): | |
self.url = url | |
self.login = login | |
self.password = password | |
def print_pull_requests(self, repository, state='open'): | |
""" Returns pull requests for current user """ | |
url = (self.url + '/repos/%s/%s/pulls?state=%s') % (repository.organization, repository.name, state) | |
request = requests.get(url, auth=(self.login, self.password)) | |
issues = request.json() | |
list = [] | |
if request.ok: | |
if issues: | |
for issue in issues: | |
if issue['user']['login'] == self.login: | |
list.append(issue) | |
else: | |
print '\033[91mAn error has occured while retrieving pull requests' | |
if list: | |
for issue in list: | |
print '\033[92m%s/%s (%s)\033[0m' % (repository.organization, repository.name, len(list)) | |
for issue in issues: | |
if issue['user']['login'] == self.login: | |
print ' %s' % issue['title'] | |
print ' \033[93m%s\033[0m' % issue['html_url'] | |
class Repository(object): | |
""" This is the repository class """ | |
def __init__(self, organization, name): | |
self.organization = organization | |
self.name = name | |
# Job | |
api = Api('https://api.github.com', 'your-login', 'password') | |
repositories = [ | |
Repository('symfony', 'symfony'), | |
Repository('symfony', 'symfony-docs') | |
] | |
for repository in repositories: | |
api.print_pull_requests(repository) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is an output example:
$ python open.py sonata-project/sandbox (2) Update some Behat tests using scenarios outline https://github.com/sonata-project/sandbox/pull/256 SONATA-427 - Fix products final review templates + add login stepper https://github.com/sonata-project/sandbox/pull/252 sonata-project/sandbox (2) Update some Behat tests using scenarios outline https://github.com/sonata-project/sandbox/pull/256 SONATA-427 - Fix products final review templates + add login stepper https://github.com/sonata-project/sandbox/pull/252 sonata-project/ecommerce (1) SONATA-427 - Add checkout process stepper + fix final review template https://github.com/sonata-project/ecommerce/pull/134 sonata-project/SonataPageBundle (2) Hamonize commands argument names base-console to base-command https://github.com/sonata-project/SonataPageBundle/pull/273 Allow sonata_page_render_block() to create blocks on-the-fly https://github.com/sonata-project/SonataPageBundle/pull/272 sonata-project/SonataPageBundle (2) Hamonize commands argument names base-console to base-command https://github.com/sonata-project/SonataPageBundle/pull/273 Allow sonata_page_render_block() to create blocks on-the-fly https://github.com/sonata-project/SonataPageBundle/pull/272 sonata-project/SonataMediaBundle (1) Add a block translation example for sonata_template_box twig node tag https://github.com/sonata-project/SonataMediaBundle/pull/481