Skip to content

Commit

Permalink
Issue #5: if a 'login' parameter is specified, user-specific info is …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
caarmen authored and Carmen Alvarez committed Aug 24, 2015
1 parent 2f59531 commit 5cfbab0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
3 changes: 2 additions & 1 deletion gm_pr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
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):
self.url = url
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
Expand Down
22 changes: 19 additions & 3 deletions gm_pr/prfetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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']),
Expand All @@ -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)
Expand All @@ -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):
"""
Expand All @@ -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]
3 changes: 3 additions & 0 deletions gm_pr/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",)

This comment has been minimized.

Copy link
@mmaret-geny

mmaret-geny Aug 28, 2015

Just for my curiosity, what's the purpose of that ?

This comment has been minimized.

Copy link
@CedricCabessa

CedricCabessa Aug 28, 2015

Contributor

This allow you to write "request.GET" in the template.
see 5cfbab0#diff-4002fb4820d62ee6dc682cb689dc02d0R57

This comment has been minimized.

Copy link
@calvarez-ov

calvarez-ov Aug 28, 2015

Contributor

Thanks Cedric. I actually put a comment in the original hackathon PR to explain that, but didn't copy over all the comments from that PR to this one. At least I see the value now in putting comments in my own PRs :)

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
Expand Down
5 changes: 5 additions & 0 deletions gm_pr/static/gm_pr.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions gm_pr/templates/pr.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<th>Title</th>
<th>User</th>
<th>Reviews</th>
{% if request.GET.login %}
<th>My Open Comments</th>
{% endif %}
<th class="feedback-name">{{feedback_ok|safe}}</th>
<th class="feedback-name">{{feedback_weak|safe}}</th>
<th class="feedback-name">{{feedback_ko|safe}}</th>
Expand All @@ -51,6 +54,13 @@
<td class="title"><a href="{{pr.url}}">{{pr.title}}</a></td>
<td class="user">{{pr.user}}</td>
<td class="nbrev">{{pr.nbreview}}</td>
{% if request.GET.login %}
<td class="my-open-comments">
{% if pr.my_open_comments > 0 %}
{{pr.my_open_comments}}
{% endif %}
</td>
{% endif %}
<td class="feedback_ok">{{pr.feedback_ok}}</td>
<td class="feedback_weak">{{pr.feedback_weak}}</td>
<td class="feedback_ko">{{pr.feedback_ko}}</td>
Expand Down
6 changes: 5 additions & 1 deletion web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 5cfbab0

Please sign in to comment.