diff --git a/gm_pr/models.py b/gm_pr/models.py index eea1b02..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="", + 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,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_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 3035208..25cfebe 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_comment_count = get_open_comment_count(json_pr['review_comments_url'], current_user) + else: + my_open_comment_count = 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_comment_count=my_open_comment_count, 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_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_comment_count +=1 + return open_comment_count + 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..ca5e8dd 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-comment-count{ + 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..1456955 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_comment_count > 0 %} + {{pr.my_open_comment_count}} + {% 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'],