Skip to content

Commit

Permalink
[enriched][github] Add code to calculate the first reaction duration …
Browse files Browse the repository at this point in the history
…to an issue

This code adds the functionality to calculate the number of days
before a comment or a reaction was made to an issue/pr by someone
other than the user who created that issue/pr.

closes chaoss/wg-evolution#8
  • Loading branch information
aswanipranjal authored and Alvaro del Castillo committed Jun 27, 2018
1 parent 134b2c7 commit d309144
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions grimoire_elk/enriched/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import re

from datetime import datetime
from dateutil import parser

from .utils import get_time_diff_days

Expand Down Expand Up @@ -249,6 +250,20 @@ def get_project_repository(self, eitem):
repo = eitem['origin']
return repo

def get_time_to_first_attention(self, item):
"""Get the first date at which a comment or reaction was made to the issue by someone
other than the user who created the issue
"""
comment_dates = [parser.parse(comment['created_at']).replace(tzinfo=None) for comment
in item['comments_data'] if item['user']['login'] != comment['user']['login']]
reaction_dates = [parser.parse(reaction['created_at']).replace(tzinfo=None) for reaction
in item['reactions_data'] if item['user']['login'] != reaction['user']['login']]
reaction_dates.extend(comment_dates)
if reaction_dates:
return min(reaction_dates)
else:
return None

@metadata
def get_rich_item(self, item):
rich_issue = {}
Expand Down Expand Up @@ -343,6 +358,11 @@ def get_rich_item(self, item):
if 'project' in item:
rich_issue['project'] = item['project']

rich_issue['time_to_first_attention'] = None
if issue['comments'] + issue['reactions']['total_count'] != 0:
rich_issue['time_to_first_attention'] = \
get_time_diff_days(issue['created_at'], self.get_time_to_first_attention(issue))

rich_issue.update(self.get_grimoire_fields(issue['created_at'], "issue"))

if self.sortinghat:
Expand Down

0 comments on commit d309144

Please sign in to comment.