diff --git a/grimoire_elk/enriched/bugzillarest.py b/grimoire_elk/enriched/bugzillarest.py index c929df21d..5859976a5 100644 --- a/grimoire_elk/enriched/bugzillarest.py +++ b/grimoire_elk/enriched/bugzillarest.py @@ -138,6 +138,7 @@ def get_rich_item(self, item): eitem['comments'] = 0 eitem['number_of_comments'] = 0 eitem['time_to_last_update_days'] = None + eitem['time_to_first_attention'] = None eitem['url'] = None # Add the field to know if the ticket is open @@ -155,6 +156,9 @@ def get_rich_item(self, item): if 'is_open' in issue and not issue['is_open']: eitem['timeopen_days'] = eitem['time_to_last_update_days'] + eitem['time_to_first_attention'] = \ + get_time_diff_days(eitem['creation_ts'], self.get_time_to_first_attention(issue)) + eitem['changes'] = 0 for history in issue['history']: if 'changes' in history: @@ -177,3 +181,28 @@ def get_rich_item(self, item): self.add_repository_labels(eitem) self.add_metadata_filter_raw(eitem) return eitem + + def get_time_to_first_attention(self, item): + """Set the time to first attention. + + This date is defined as the first date at which a comment by someone + other than the user who created the issue. + """ + if 'comments' not in item: + return None + + comment_dates = [] + creator = item['creator'] + + # First comment is the description of the issue + # Real comments start at the second position (index 1) + for comment in item['comments'][1:]: + user = comment['creator'] + if user == creator: + continue + comment_dates.append(str_to_datetime(comment['time']).replace(tzinfo=None)) + + if comment_dates: + return min(comment_dates) + else: + return None diff --git a/tests/test_bugzillarest.py b/tests/test_bugzillarest.py index d996575da..79f864c4e 100644 --- a/tests/test_bugzillarest.py +++ b/tests/test_bugzillarest.py @@ -91,6 +91,18 @@ def test_enrich_keywords(self): eitem = enrich_backend.get_rich_item(item) self.assertEqual(eitem['keywords'], ['crash', 'regression']) + def test_time_to_first_attention(self): + """Test whether time_to_first_attention is calculated""" + + self._test_raw_to_enrich() + enrich_backend = self.connectors[self.connector][2]() + + expected = [7.23, 0.03, 0.2, 2.31, 9.88, None, None] + + for index in range(0, len(self.items)): + eitem = enrich_backend.get_rich_item(self.items[index]) + self.assertEqual(eitem['time_to_first_attention'], expected[index]) + def test_raw_to_enrich_sorting_hat(self): """Test enrich with SortingHat"""