diff --git a/gm_pr/models.py b/gm_pr/models.py index eea1b02..9bdce79 100644 --- a/gm_pr/models.py +++ b/gm_pr/models.py @@ -16,7 +16,7 @@ class Pr: """ Simple class wrapper for pr properties """ - def __init__(self, url="", title="", updated_at="", user="", + def __init__(self, url="", title="", updated_at="", user="", my_open_comments=0, repo="", nbreview=0, feedback_ok=0, feedback_weak=0, feedback_ko=0, milestone=None, labels=None, is_old=False): @@ -24,6 +24,7 @@ def __init__(self, url="", title="", updated_at="", user="", self.title = title self.updated_at = updated_at self.user = user + self.my_open_comments = my_open_comments self.repo = repo self.nbreview = nbreview self.feedback_ok = feedback_ok diff --git a/gm_pr/prfetcher.py b/gm_pr/prfetcher.py index 3035208..1c1d0be 100644 --- a/gm_pr/prfetcher.py +++ b/gm_pr/prfetcher.py @@ -34,7 +34,7 @@ def is_color_light(rgb_hex_color_string): return y > 128 @app.task -def fetch_data(repo_name, url, org): +def fetch_data(repo_name, url, org, current_user): """ Celery task, call github api repo_name -- github repo name url -- base url for this repo @@ -83,6 +83,10 @@ def fetch_data(repo_name, url, org): break # look for tags only in main conversation and not in "file changed" + if current_user is not None: + my_open_comments = get_open_comment_count(json_pr['review_comments_url'], current_user) + else: + my_open_comments = 0 for jcomment in conversation_json: body = jcomment['body'] if re.search(settings.FEEDBACK_OK['keyword'], body): @@ -98,6 +102,7 @@ def fetch_data(repo_name, url, org): title=json_pr['title'], updated_at=date, user=json_pr['user']['login'], + my_open_comments=my_open_comments, repo=json_pr['base']['repo']['full_name'], nbreview=int(detail_json['comments']) + int(detail_json['review_comments']), @@ -116,11 +121,21 @@ def fetch_data(repo_name, url, org): return repo +# Return the number of non-obsolete review comments posted on the given PR url, by the given user. +def get_open_comment_count(url, user): + open_comments=0 + review_comments = paginablejson.PaginableJson(url) + for review_comment in review_comments: + # In obsolote comments, the commit_id != original_commit_id. + if review_comment['commit_id'] == review_comment['original_commit_id'] and review_comment['user']['login'] == user: + open_comments +=1 + return open_comments + class PrFetcher: """ Pr fetc """ - def __init__(self, url, org, repos): + def __init__(self, url, org, repos, current_user): """ url -- top level url (eg: https://api.github.com) org -- github organisation (eg: Genymobile) @@ -129,6 +144,7 @@ def __init__(self, url, org, repos): self.__url = url self.__org = org self.__repos = repos + self.__current_user = current_user def get_prs(self): """ @@ -137,7 +153,7 @@ def get_prs(self): return a list of { 'name' : repo_name, 'pr_list' : pr_list } pr_list is a list of models.Pr """ - res = group(fetch_data.s(repo_name, self.__url, self.__org) + res = group(fetch_data.s(repo_name, self.__url, self.__org, self.__current_user) for repo_name in self.__repos)() data = res.get() return [repo for repo in data if repo != None] diff --git a/gm_pr/settings.py b/gm_pr/settings.py index 670d42d..5b71dae 100644 --- a/gm_pr/settings.py +++ b/gm_pr/settings.py @@ -123,6 +123,9 @@ ROOT_URLCONF = 'gm_pr.urls' +from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS +TEMPLATE_CONTEXT_PROCESSORS += ("django.core.context_processors.request",) + TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. diff --git a/gm_pr/static/gm_pr.css b/gm_pr/static/gm_pr.css index ed8229d..dc2f613 100644 --- a/gm_pr/static/gm_pr.css +++ b/gm_pr/static/gm_pr.css @@ -108,6 +108,11 @@ td a:hover { text-align: center; width: 1.5em; } +.my-open-comments{ + color: black; + text-align: center; + width: 1.5em; +} .feedback_ok, .feedback_weak, .feedback_ko { diff --git a/gm_pr/templates/pr.html b/gm_pr/templates/pr.html index 0e06570..baff947 100644 --- a/gm_pr/templates/pr.html +++ b/gm_pr/templates/pr.html @@ -31,6 +31,9 @@