Add open reviews to elastic-recheck status page

List open gerrit reviews on the elastic_recheck status page. Listing the
reviews here can help us prioritize reviews of them. Currently one has
to manually dig through the launchpad notes for gerrit review links,
this automates that process.

Instead of looking for jenkins comments in launchpad about open patches,
directly query gerrit for open patches related to the bug on hand. Since
gerrit only supports string matching and not regex for messages, just
look for the bug number in the commit message. Our bug numbers are long
enough that it unlikely the number will come up in other cases.

Change-Id: Ida2144ccc5f0fdf91e2bd70714de80c83f4c1200
This commit is contained in:
Joe Gordon 2014-07-23 16:00:48 -07:00
parent ec087340aa
commit 1981ff7b5f
4 changed files with 93 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import json
import os
from launchpadlib import launchpad
import requests
import elastic_recheck.elasticRecheck as er
from elastic_recheck import results as er_results
@ -40,9 +41,26 @@ def get_launchpad_bug(bug):
(x.bug_target_name, x.status),
lp_bug.bug_tasks))
bugdata['affects'] = projects
bugdata['reviews'] = get_open_reviews(bug)
return bugdata
def get_open_reviews(bug_number):
"return list of open gerrit reviews for a given bug."""
r = requests.get("https://review.openstack.org:443/changes/"
"?q=status:open++message:`%s`" % bug_number)
# strip off first few chars because 'the JSON response body starts with a
# magic prefix line that must be stripped before feeding the rest of the
# response body to a JSON parser'
# https://review.openstack.org/Documentation/rest-api.html
reviews = []
result = None
result = json.loads(r.text[4:])
for review in result:
reviews.append(review['_number'])
return reviews
def main():
parser = argparse.ArgumentParser(description='Generate data for graphs.')
parser.add_argument(dest='queries',

View File

@ -0,0 +1,21 @@
[
{
"kind": "gerritcodereview#change",
"id": "openstack%2Fneutron~master~Iefb30452083747b45496600c81f8d0a6f378bd08",
"project": "openstack/neutron",
"branch": "master",
"topic": "bug/1288393",
"change_id": "Iefb30452083747b45496600c81f8d0a6f378bd08",
"subject": "Change nexus_dict values to be array",
"status": "NEW",
"created": "2014-08-08 20:04:30.000000000",
"updated": "2014-08-08 21:06:08.835000000",
"mergeable": false,
"_sortkey": "002ef9920001b971",
"_number": 113009,
"owner": {
"name": "Britt Houser"
}
}
]

View File

@ -0,0 +1,37 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from elastic_recheck.cmd import graph
from elastic_recheck.tests import unit
class FakeResponse(object):
def __init__(self, response_text):
super(FakeResponse, self).__init__()
# magic gerrit prefix
self.text = ")]}'\n" + response_text
class TestGraphCmd(unit.UnitTestCase):
def test_get_open_reviews_empty(self):
with mock.patch('requests.get') as mock_get:
mock_get.return_value = FakeResponse("[]\n")
self.assertEqual(graph.get_open_reviews('1353131'), [])
def test_get_open_reviews(self):
with mock.patch('requests.get') as mock_get:
with open('elastic_recheck/tests/unit/samples/'
'gerrit-bug-query.json') as f:
mock_get.return_value = FakeResponse(f.read())
self.assertEqual(graph.get_open_reviews('1288393'), [113009])

View File

@ -48,6 +48,23 @@ function update() {
$('<h3/>', {
text: 'Projects: ' + bug['bug_data']['affects']
}).appendTo(div);
var reviews = bug['bug_data']['reviews'];
if (reviews.length>0) {
$('<h3/>', {
text: 'Open reviews: '
}).appendTo($('<span/>', {
'class': 'extlink'
}).appendTo(div));
}
for (var i = 0; i < reviews.length ; i++) {
$('<a/>', {
href: 'https://review.openstack.org/#/c/'+reviews[i],
text: reviews[i]
}).appendTo($('<span/>', {
'class': 'extlink'
}).appendTo(div));
}
$('<div/>', {'class': 'graph'}).appendTo(div);
$('<a/>', {
href: 'http://logstash.openstack.org/#'+bug['logstash_query'],