Skip to content

Instantly share code, notes, and snippets.

@pshchelo
Last active March 24, 2017 21:17

Revisions

  1. pshchelo revised this gist Mar 24, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gerritq.py
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # import gerritq
    # g = gerritq.GerritQuery()
    # user = 'pshchelo'
    # q = 'owner:%s+status:merged' % s
    # q = 'owner:%s+status:merged' % user
    # merged = g.changes(q)
    # print(len(merged))

  2. pshchelo revised this gist Feb 23, 2017. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions gerritq.py
    Original file line number Diff line number Diff line change
    @@ -7,11 +7,9 @@
    # user = 'pshchelo'
    # q = 'owner:%s+status:merged' % s
    # merged = g.changes(q)
    # print(len(merged)
    # print(len(merged))

    import json
    import pprint
    import sys

    import requests
    from six.moves.urllib_parse import urljoin
    @@ -35,6 +33,9 @@ def changes(self, query):
    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)
  3. pshchelo revised this gist Feb 23, 2017. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions gerritq.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,14 @@
    #!/usr/bin/env python

    # Usage example:
    #
    # import gerritq
    # g = gerritq.GerritQuery()
    # user = 'pshchelo'
    # q = 'owner:%s+status:merged' % s
    # merged = g.changes(q)
    # print(len(merged)

    import json
    import pprint
    import sys
  4. pshchelo created this gist Feb 23, 2017.
    32 changes: 32 additions & 0 deletions gerritq.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/usr/bin/env python

    import json
    import pprint
    import sys

    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__':
    if len(sys.argv) == 1:
    print("Requires query string as first argument")
    sys.exit(1)
    pprint.pprint(GerritQuery().changes(sys.argv[1]))