Merge "Add open reviews to elastic-recheck status page"
This commit is contained in:
commit
24c460ee03
@ -21,6 +21,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from launchpadlib import launchpad
|
from launchpadlib import launchpad
|
||||||
|
import requests
|
||||||
|
|
||||||
import elastic_recheck.elasticRecheck as er
|
import elastic_recheck.elasticRecheck as er
|
||||||
from elastic_recheck import results as er_results
|
from elastic_recheck import results as er_results
|
||||||
@ -40,9 +41,26 @@ def get_launchpad_bug(bug):
|
|||||||
(x.bug_target_name, x.status),
|
(x.bug_target_name, x.status),
|
||||||
lp_bug.bug_tasks))
|
lp_bug.bug_tasks))
|
||||||
bugdata['affects'] = projects
|
bugdata['affects'] = projects
|
||||||
|
bugdata['reviews'] = get_open_reviews(bug)
|
||||||
return bugdata
|
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():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='Generate data for graphs.')
|
parser = argparse.ArgumentParser(description='Generate data for graphs.')
|
||||||
parser.add_argument(dest='queries',
|
parser.add_argument(dest='queries',
|
||||||
|
21
elastic_recheck/tests/unit/samples/gerrit-bug-query.json
Normal file
21
elastic_recheck/tests/unit/samples/gerrit-bug-query.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
37
elastic_recheck/tests/unit/test_graph.py
Normal file
37
elastic_recheck/tests/unit/test_graph.py
Normal 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])
|
@ -48,6 +48,23 @@ function update() {
|
|||||||
$('<h3/>', {
|
$('<h3/>', {
|
||||||
text: 'Projects: ' + bug['bug_data']['affects']
|
text: 'Projects: ' + bug['bug_data']['affects']
|
||||||
}).appendTo(div);
|
}).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);
|
$('<div/>', {'class': 'graph'}).appendTo(div);
|
||||||
$('<a/>', {
|
$('<a/>', {
|
||||||
href: 'http://logstash.openstack.org/#'+bug['logstash_query'],
|
href: 'http://logstash.openstack.org/#'+bug['logstash_query'],
|
||||||
|
Loading…
Reference in New Issue
Block a user