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
=== modified file 'apps/patchmetrics/gerrit.py'
--- apps/patchmetrics/gerrit.py 2012-07-02 07:37:08 +0000
+++ apps/patchmetrics/gerrit.py 2013-03-27 15:04:32 +0000
@@ -13,9 +13,8 @@
13 GERRIT_ID_KEY,13 GERRIT_ID_KEY,
14 GERRIT_NUMBER_KEY,14 GERRIT_NUMBER_KEY,
15 GERRIT_PROJECT_KEY,15 GERRIT_PROJECT_KEY,
16 GERRIT_QUERY_FORMAT,16 GERRIT_QUERY_LIMIT,
17 GERRIT_QUERY_OWNER,17 GERRIT_QUERY_OWNER,
18 GERRIT_QUERY_PG_SIZE,
19 GERRIT_QUERY_RESUME_SORTKEY,18 GERRIT_QUERY_RESUME_SORTKEY,
20 GERRIT_SANITIZABLE_VALUE,19 GERRIT_SANITIZABLE_VALUE,
21 GERRIT_STATUS_KEY,20 GERRIT_STATUS_KEY,
@@ -58,34 +57,30 @@
58 'JSON_COMPACT' for JSON format without spaces, also57 'JSON_COMPACT' for JSON format without spaces, also
59 possible to specify 'JSON'.58 possible to specify 'JSON'.
60 """59 """
61 params = {GERRIT_QUERY_FORMAT: return_format,
62 GERRIT_QUERY_PG_SIZE: page_size}
63 query_params = {GERRIT_QUERY_OWNER: email,60 query_params = {GERRIT_QUERY_OWNER: email,
61 GERRIT_QUERY_LIMIT: page_size,
64 GERRIT_QUERY_RESUME_SORTKEY: resume_key}62 GERRIT_QUERY_RESUME_SORTKEY: resume_key}
65 return rest_api_request(ROOT_REST_URL, CHANGES_QUERY_PATH, params,63 return rest_api_request(ROOT_REST_URL, CHANGES_QUERY_PATH, query_params)
66 query_params)64
6765
6866def rest_api_request(url, path, query_params):
69def rest_api_request(url, path, params, query_params):
70 """Calls the gerrit REST interface and return the JSON response.67 """Calls the gerrit REST interface and return the JSON response.
7168
72 :param url: the root URL of the web service.69 :param url: the root URL of the web service.
73 :param path: the path of the REST interface, after the URL.70 :param path: the path of the REST interface, after the URL.
74 :param params: the parameters for the query, can be a dictionary or tuple.
75 :param query_params: the parameters for the gerrit query interface, must71 :param query_params: the parameters for the gerrit query interface, must
76 be a dictionary.72 be a dictionary.
77 """73 """
78 request_url = create_request_query_url(url, path, params, query_params)74 request_url = create_request_query_url(url, path, query_params)
79 return gerrit_request(request_url)75 return gerrit_request(request_url)
8076
8177
82def create_request_query_url(url, path, params, query_params):78def create_request_query_url(url, path, query_params):
83 """Creates the full query URL from the various elements.79 """Creates the full query URL from the various elements.
8480
85 :param url: the root URL of the web service, without path to the REST81 :param url: the root URL of the web service, without path to the REST
86 interface.82 interface.
87 :param path: the path of the REST interface, after the URL.83 :param path: the path of the REST interface, after the URL.
88 :param params: the parameters for the query, can be a dictionary or tuple.
89 :param query_params: the parameters for the gerrit query interface, must84 :param query_params: the parameters for the gerrit query interface, must
90 be a dictionary.85 be a dictionary.
91 """86 """
@@ -93,9 +88,8 @@
93 url += '/'88 url += '/'
94 if not path.endswith('/'):89 if not path.endswith('/'):
95 path += '/'90 path += '/'
91
96 request_url = url + path + QUERY_STRING_START92 request_url = url + path + QUERY_STRING_START
97
98 request_url += urllib.urlencode(params)
99 request_url += create_gerrit_rest_query(query_params)93 request_url += create_gerrit_rest_query(query_params)
10094
101 return request_url95 return request_url
@@ -115,18 +109,13 @@
115 type(query_params).__name__)109 type(query_params).__name__)
116110
117 params_list = []111 params_list = []
118 # Where we will store the query.
119 gerrit_query = ''112 gerrit_query = ''
120 for key, value in query_params.iteritems():113 for key, value in query_params.iteritems():
121 # We cannot have None values here, we just skip them.114 # We cannot have None values here.
122 if value is not None:115 if value:
123 # We need string, and remove white chars.116 # We need string, remove white chars and quote values.
124 value = str(value).strip()117 # gerrit accepts single or double quotes and curly brackets.
125 # Some emails need to be quoted, and only double quotes are118 value = ("\"%s\"" % str(value).strip())
126 # accepted by gerrit.
127 if key == GERRIT_QUERY_OWNER:
128 value = ("\"%s\"" % value)
129 # We need strings here, and we remove white spaces.
130 params_list.append(":".join((key, urllib.quote(value))))119 params_list.append(":".join((key, urllib.quote(value))))
131 # The resulting query string, without separators or prefixes, should be in120 # The resulting query string, without separators or prefixes, should be in
132 # the form of:121 # the form of:
@@ -134,8 +123,8 @@
134 # This is a normal query, more complex queries need to be thought of, since123 # This is a normal query, more complex queries need to be thought of, since
135 # we can express also OR, AND and NOT operators. By default it is an AND.124 # we can express also OR, AND and NOT operators. By default it is an AND.
136 if params_list:125 if params_list:
137 gerrit_query = QUERY_STRING_SEP + GERRIT_QUERY_PREFIX + \126 gerrit_query = (GERRIT_QUERY_PREFIX +
138 GERRIT_QUERY_SEPARATOR.join(params_list)127 GERRIT_QUERY_SEPARATOR.join(params_list))
139128
140 return gerrit_query129 return gerrit_query
141130
142131
=== modified file 'apps/patchmetrics/gerrit_values.py'
--- apps/patchmetrics/gerrit_values.py 2012-06-27 08:25:59 +0000
+++ apps/patchmetrics/gerrit_values.py 2013-03-27 15:04:32 +0000
@@ -26,6 +26,9 @@
2626
27# Gerrit query parameters27# Gerrit query parameters
28GERRIT_QUERY_OWNER = 'owner'28GERRIT_QUERY_OWNER = 'owner'
29GERRIT_QUERY_RESUME_SORTKEY = 'resume_sortkey'
30GERRIT_QUERY_LIMIT = 'limit'
31
32# Deprecated keys, or not anymore in the docs.
29GERRIT_QUERY_FORMAT = 'format'33GERRIT_QUERY_FORMAT = 'format'
30GERRIT_QUERY_PG_SIZE = 'n'34GERRIT_QUERY_PG_SIZE = 'n'
31GERRIT_QUERY_RESUME_SORTKEY = 'resume_sortkey'

Subscribers

People subscribed via source and target branches