diff --git a/grimoire_elk/enriched/bugzilla.py b/grimoire_elk/enriched/bugzilla.py index 30aaa4b1f..a8c18e8a4 100644 --- a/grimoire_elk/enriched/bugzilla.py +++ b/grimoire_elk/enriched/bugzilla.py @@ -195,10 +195,21 @@ def get_rich_item(self, item): # Add extra JSON fields used in Kibana (enriched fields) eitem['comments'] = 0 + eitem['last_comment_date'] = None eitem['url'] = None if 'long_desc' in issue: eitem['comments'] = len(issue['long_desc']) + + last_comment_date = None + + if eitem['comments'] > 1: + last_comment = issue['long_desc'][-1] + last_comment_date = str_to_datetime(last_comment['bug_when'][0]['__text__']) + last_comment_date = last_comment_date.isoformat() + + eitem['last_comment_date'] = last_comment_date + eitem['url'] = item['origin'] + "/show_bug.cgi?id=" + issue['bug_id'][0]['__text__'] eitem['resolution_days'] = \ get_time_diff_days(eitem['creation_date'], eitem['delta_ts']) diff --git a/schema/bugzilla.csv b/schema/bugzilla.csv index e9a8a52ad..1177a1480 100644 --- a/schema/bugzilla.csv +++ b/schema/bugzilla.csv @@ -58,6 +58,7 @@ is_bugzillarest_bugrest,long is_open,boolean keywords,keyword labels,list +last_comment_date,date main_description,keyword main_description_analyzed,string,false metadata__enriched_on,date diff --git a/tests/test_bugzilla.py b/tests/test_bugzilla.py index ef5e3b345..394c9313b 100644 --- a/tests/test_bugzilla.py +++ b/tests/test_bugzilla.py @@ -19,6 +19,7 @@ # Alvaro del Castillo # Valerio Cosentino # + import logging import unittest @@ -105,6 +106,26 @@ def test_time_to_first_attention(self): eitem = enrich_backend.get_rich_item(self.items[index]) self.assertEqual(eitem['time_to_first_attention'], expected[index]) + def test_last_comment_date(self): + """Test whether last_comment_date is added to the enriched item""" + + self._test_raw_to_enrich() + enrich_backend = self.connectors[self.connector][2]() + + expected = [ + "2013-06-25T11:55:46+02:00", + "2013-06-25T11:55:46+02:00", + None, + "2013-06-25T11:55:46+02:00", + "2013-06-25T11:55:46+02:00", + None, + "2014-08-01T11:55:46+02:00" + ] + + for index in range(0, len(self.items)): + eitem = enrich_backend.get_rich_item(self.items[index]) + self.assertEqual(eitem['last_comment_date'], expected[index]) + def test_raw_to_enrich_sorting_hat(self): """Test enrich with SortingHat"""