Merge lp:~milo/linaro-patchmetrics/bug1155533 into lp:linaro-patchmetrics

Proposed by Milo Casagrande
Status: Merged
Merged at revision: 373
Proposed branch: lp:~milo/linaro-patchmetrics/bug1155533
Merge into: lp:linaro-patchmetrics
Diff against target: 117 lines (+20/-28)
2 files modified
apps/patchmetrics/gerrit.py (+16/-27)
apps/patchmetrics/gerrit_values.py (+4/-1)
To merge this branch: bzr merge lp:~milo/linaro-patchmetrics/bug1155533
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+155757@code.launchpad.net

Commit message

Fixed gerrit query string as per new upstream release.

Description of the change

Android gerrit instance has been updated to a new release, and they sligthly
change the query parameters necessary to retrieve results.

In particular, the default format returned with the query is json, and there
is no need to specify that (we already force that in the header).

Doing that, we are now using a full gerrit query, made of documented query
parameters.

In the changes I hade to introduce a new gerrit query param, and remove usage
of the unsupported ones.

To post a comment you must log in.
Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apps/patchmetrics/gerrit.py'
2--- apps/patchmetrics/gerrit.py 2012-07-02 07:37:08 +0000
3+++ apps/patchmetrics/gerrit.py 2013-03-27 15:04:32 +0000
4@@ -13,9 +13,8 @@
5 GERRIT_ID_KEY,
6 GERRIT_NUMBER_KEY,
7 GERRIT_PROJECT_KEY,
8- GERRIT_QUERY_FORMAT,
9+ GERRIT_QUERY_LIMIT,
10 GERRIT_QUERY_OWNER,
11- GERRIT_QUERY_PG_SIZE,
12 GERRIT_QUERY_RESUME_SORTKEY,
13 GERRIT_SANITIZABLE_VALUE,
14 GERRIT_STATUS_KEY,
15@@ -58,34 +57,30 @@
16 'JSON_COMPACT' for JSON format without spaces, also
17 possible to specify 'JSON'.
18 """
19- params = {GERRIT_QUERY_FORMAT: return_format,
20- GERRIT_QUERY_PG_SIZE: page_size}
21 query_params = {GERRIT_QUERY_OWNER: email,
22+ GERRIT_QUERY_LIMIT: page_size,
23 GERRIT_QUERY_RESUME_SORTKEY: resume_key}
24- return rest_api_request(ROOT_REST_URL, CHANGES_QUERY_PATH, params,
25- query_params)
26-
27-
28-def rest_api_request(url, path, params, query_params):
29+ return rest_api_request(ROOT_REST_URL, CHANGES_QUERY_PATH, query_params)
30+
31+
32+def rest_api_request(url, path, query_params):
33 """Calls the gerrit REST interface and return the JSON response.
34
35 :param url: the root URL of the web service.
36 :param path: the path of the REST interface, after the URL.
37- :param params: the parameters for the query, can be a dictionary or tuple.
38 :param query_params: the parameters for the gerrit query interface, must
39 be a dictionary.
40 """
41- request_url = create_request_query_url(url, path, params, query_params)
42+ request_url = create_request_query_url(url, path, query_params)
43 return gerrit_request(request_url)
44
45
46-def create_request_query_url(url, path, params, query_params):
47+def create_request_query_url(url, path, query_params):
48 """Creates the full query URL from the various elements.
49
50 :param url: the root URL of the web service, without path to the REST
51 interface.
52 :param path: the path of the REST interface, after the URL.
53- :param params: the parameters for the query, can be a dictionary or tuple.
54 :param query_params: the parameters for the gerrit query interface, must
55 be a dictionary.
56 """
57@@ -93,9 +88,8 @@
58 url += '/'
59 if not path.endswith('/'):
60 path += '/'
61+
62 request_url = url + path + QUERY_STRING_START
63-
64- request_url += urllib.urlencode(params)
65 request_url += create_gerrit_rest_query(query_params)
66
67 return request_url
68@@ -115,18 +109,13 @@
69 type(query_params).__name__)
70
71 params_list = []
72- # Where we will store the query.
73 gerrit_query = ''
74 for key, value in query_params.iteritems():
75- # We cannot have None values here, we just skip them.
76- if value is not None:
77- # We need string, and remove white chars.
78- value = str(value).strip()
79- # Some emails need to be quoted, and only double quotes are
80- # accepted by gerrit.
81- if key == GERRIT_QUERY_OWNER:
82- value = ("\"%s\"" % value)
83- # We need strings here, and we remove white spaces.
84+ # We cannot have None values here.
85+ if value:
86+ # We need string, remove white chars and quote values.
87+ # gerrit accepts single or double quotes and curly brackets.
88+ value = ("\"%s\"" % str(value).strip())
89 params_list.append(":".join((key, urllib.quote(value))))
90 # The resulting query string, without separators or prefixes, should be in
91 # the form of:
92@@ -134,8 +123,8 @@
93 # This is a normal query, more complex queries need to be thought of, since
94 # we can express also OR, AND and NOT operators. By default it is an AND.
95 if params_list:
96- gerrit_query = QUERY_STRING_SEP + GERRIT_QUERY_PREFIX + \
97- GERRIT_QUERY_SEPARATOR.join(params_list)
98+ gerrit_query = (GERRIT_QUERY_PREFIX +
99+ GERRIT_QUERY_SEPARATOR.join(params_list))
100
101 return gerrit_query
102
103
104=== modified file 'apps/patchmetrics/gerrit_values.py'
105--- apps/patchmetrics/gerrit_values.py 2012-06-27 08:25:59 +0000
106+++ apps/patchmetrics/gerrit_values.py 2013-03-27 15:04:32 +0000
107@@ -26,6 +26,9 @@
108
109 # Gerrit query parameters
110 GERRIT_QUERY_OWNER = 'owner'
111+GERRIT_QUERY_RESUME_SORTKEY = 'resume_sortkey'
112+GERRIT_QUERY_LIMIT = 'limit'
113+
114+# Deprecated keys, or not anymore in the docs.
115 GERRIT_QUERY_FORMAT = 'format'
116 GERRIT_QUERY_PG_SIZE = 'n'
117-GERRIT_QUERY_RESUME_SORTKEY = 'resume_sortkey'

Subscribers

People subscribed via source and target branches