Skip to content

Instantly share code, notes, and snippets.

@pshchelo
Last active March 24, 2017 21:17
Show Gist options
  • Save pshchelo/b31cdf85ae4e0af1043b66bdcea13ea8 to your computer and use it in GitHub Desktop.
Save pshchelo/b31cdf85ae4e0af1043b66bdcea13ea8 to your computer and use it in GitHub Desktop.
Gerrit Queries
#!/usr/bin/env python
# Usage example:
#
# import gerritq
# g = gerritq.GerritQuery()
# user = 'pshchelo'
# q = 'owner:%s+status:merged' % user
# merged = g.changes(q)
# print(len(merged))
import json
import requests
from six.moves.urllib_parse import urljoin
OOO_GERRIT_URL = 'https://review.openstack.org'
class GerritQuery(object):
def __init__(self, url=OOO_GERRIT_URL):
self.base_url = url
def changes(self, query):
url = urljoin(self.base_url, '/changes/?q=%s' % query)
resp = requests.get(url)
if not resp.ok:
return None
# sanitize ")]}'" from response
changes = resp.content[4:]
return json.loads(changes)
if __name__ == '__main__':
import pprint
import sys
if len(sys.argv) == 1:
print("Requires query string as first argument")
sys.exit(1)
pprint.pprint(GerritQuery().changes(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment