From 2df018763e14da120840e629f93ae3f39a434279 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 19 2016 08:19:22 +0000 Subject: [PATCH 1/2] Allow filter the list of commits for a certain user By specifying an `?author=` one can now retrieve the list of commits made by that user (if the emails set in pagure corresponds to the ones in the commits). Fixes https://pagure.io/pagure/issue/1401 --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 2d6c4d1..d7ec283 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -301,6 +301,17 @@ def view_commits(repo, branchname=None, username=None, namespace=None): except ValueError: page = 1 + author = flask.request.args.get('author', None) + author_obj = None + if author: + try: + author_obj = pagure.lib.get_user(SESSION, author) + except: + pass + if not author_obj: + flask.flash( + 'No user found for the author: %s' % author, 'error') + limit = APP.config['ITEM_PER_PAGE'] start = limit * (page - 1) end = limit * page @@ -310,6 +321,19 @@ def view_commits(repo, branchname=None, username=None, namespace=None): if branch: for commit in repo_obj.walk( branch.get_object().hex, pygit2.GIT_SORT_TIME): + + # Filters the commits for an user + filters = None + if author_obj: + filters = True + tmp = False + for email in author_obj.emails: + if email.email == commit.author.email: + tmp = True + break + if not tmp: + continue + if n_commits >= start and n_commits <= end: last_commits.append(commit) n_commits += 1 From f4af77b6db77d0c488898b689f03ccc8874c12c2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 19 2016 08:19:22 +0000 Subject: [PATCH 2/2] Make the pagination use our macro on the commit list page --- diff --git a/pagure/templates/commits.html b/pagure/templates/commits.html index 4897362..afab59a 100644 --- a/pagure/templates/commits.html +++ b/pagure/templates/commits.html @@ -1,5 +1,7 @@ {% extends "repo_master.html" %} +{% from "_render_repo.html" import pagination_link %} + {% block title %}{{ select.capitalize() }} - {{ repo.namespace + '/' if repo.namespace }}{{ repo.name }}{% endblock %} {% set tag = "home" %} @@ -152,37 +154,8 @@ {% endfor %} - {% if total_page %} - - {% endif %} + {{ pagination_link('page', g.page, total_page) }} + {% endif %} {% endblock %}