From 5cfbab0143d58fb760e6438c4115c24ae140d800 Mon Sep 17 00:00:00 2001 From: Carmen Alvarez Date: Sat, 22 Aug 2015 05:37:15 +0200 Subject: [PATCH 1/3] Issue #5: if a 'login' parameter is specified, user-specific info is displayed. For now, just "My Open Comments" is displayed. If no 'login' url parameter is specified, then the "My Open Comments" column is not displayed. --- gm_pr/models.py | 3 ++- gm_pr/prfetcher.py | 22 +++++++++++++++++++--- gm_pr/settings.py | 3 +++ gm_pr/static/gm_pr.css | 5 +++++ gm_pr/templates/pr.html | 10 ++++++++++ web/views.py | 6 +++++- 6 files changed, 44 insertions(+), 5 deletions(-) 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 @@ Title User Reviews + {% if request.GET.login %} + My Open Comments + {% endif %} {{feedback_ok|safe}} {{feedback_weak|safe}} {{feedback_ko|safe}} @@ -51,6 +54,13 @@ {{pr.title}} {{pr.user}} {{pr.nbreview}} + {% if request.GET.login %} + + {% if pr.my_open_comments > 0 %} + {{pr.my_open_comments}} + {% endif %} + + {% endif %} {{pr.feedback_ok}} {{pr.feedback_weak}} {{pr.feedback_ko}} diff --git a/web/views.py b/web/views.py index d55ebc1..d4436da 100644 --- a/web/views.py +++ b/web/views.py @@ -33,7 +33,11 @@ def index(request): if repos != None: before = time.time() - prf = PrFetcher(settings.TOP_LEVEL_URL, settings.ORG, repos) + current_user = None + if 'login' in request.GET: + current_user = request.GET['login'] + + prf = PrFetcher(settings.TOP_LEVEL_URL, settings.ORG, repos, current_user) context = {"title" : "%s PR list" % project, "project_list" : prf.get_prs(), "feedback_ok" : settings.FEEDBACK_OK['name'], From 134c1d8b1ee959999af9ed198ec3b19905c502c1 Mon Sep 17 00:00:00 2001 From: Carmen Alvarez Date: Sat, 22 Aug 2015 05:56:08 +0200 Subject: [PATCH 2/3] Issue #5: correction for determining which review comments are obsolete. --- gm_pr/prfetcher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gm_pr/prfetcher.py b/gm_pr/prfetcher.py index 1c1d0be..b944ecf 100644 --- a/gm_pr/prfetcher.py +++ b/gm_pr/prfetcher.py @@ -126,8 +126,8 @@ 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: + # In obsolote comments, the position is None + if review_comment['position'] is not None and review_comment['user']['login'] == user: open_comments +=1 return open_comments From b148e736e1d3eb5075c265048d6887690615e17e Mon Sep 17 00:00:00 2001 From: Carmen Alvarez Date: Sat, 22 Aug 2015 06:00:46 +0200 Subject: [PATCH 3/3] Issue #5: rename "my_open_comments" to "my_open_comment_count" everywhere. --- gm_pr/models.py | 4 ++-- gm_pr/prfetcher.py | 12 ++++++------ gm_pr/static/gm_pr.css | 2 +- gm_pr/templates/pr.html | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gm_pr/models.py b/gm_pr/models.py index 9bdce79..158e5fb 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="", my_open_comments=0, + def __init__(self, url="", title="", updated_at="", user="", my_open_comment_count=0, repo="", nbreview=0, feedback_ok=0, feedback_weak=0, feedback_ko=0, milestone=None, labels=None, is_old=False): @@ -24,7 +24,7 @@ def __init__(self, url="", title="", updated_at="", user="", my_open_comments=0, self.title = title self.updated_at = updated_at self.user = user - self.my_open_comments = my_open_comments + self.my_open_comment_count = my_open_comment_count self.repo = repo self.nbreview = nbreview self.feedback_ok = feedback_ok diff --git a/gm_pr/prfetcher.py b/gm_pr/prfetcher.py index b944ecf..25cfebe 100644 --- a/gm_pr/prfetcher.py +++ b/gm_pr/prfetcher.py @@ -84,9 +84,9 @@ def fetch_data(repo_name, url, org, current_user): # 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) + my_open_comment_count = get_open_comment_count(json_pr['review_comments_url'], current_user) else: - my_open_comments = 0 + my_open_comment_count = 0 for jcomment in conversation_json: body = jcomment['body'] if re.search(settings.FEEDBACK_OK['keyword'], body): @@ -102,7 +102,7 @@ def fetch_data(repo_name, url, org, current_user): title=json_pr['title'], updated_at=date, user=json_pr['user']['login'], - my_open_comments=my_open_comments, + my_open_comment_count=my_open_comment_count, repo=json_pr['base']['repo']['full_name'], nbreview=int(detail_json['comments']) + int(detail_json['review_comments']), @@ -123,13 +123,13 @@ def fetch_data(repo_name, url, org, current_user): # 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 + open_comment_count=0 review_comments = paginablejson.PaginableJson(url) for review_comment in review_comments: # In obsolote comments, the position is None if review_comment['position'] is not None and review_comment['user']['login'] == user: - open_comments +=1 - return open_comments + open_comment_count +=1 + return open_comment_count class PrFetcher: diff --git a/gm_pr/static/gm_pr.css b/gm_pr/static/gm_pr.css index dc2f613..ca5e8dd 100644 --- a/gm_pr/static/gm_pr.css +++ b/gm_pr/static/gm_pr.css @@ -108,7 +108,7 @@ td a:hover { text-align: center; width: 1.5em; } -.my-open-comments{ +.my-open-comment-count{ color: black; text-align: center; width: 1.5em; diff --git a/gm_pr/templates/pr.html b/gm_pr/templates/pr.html index baff947..1456955 100644 --- a/gm_pr/templates/pr.html +++ b/gm_pr/templates/pr.html @@ -55,9 +55,9 @@ {{pr.user}} {{pr.nbreview}} {% if request.GET.login %} - - {% if pr.my_open_comments > 0 %} - {{pr.my_open_comments}} + + {% if pr.my_open_comment_count > 0 %} + {{pr.my_open_comment_count}} {% endif %} {% endif %}