From b70bb2ee09e6191ffe385031bb446af82c52a29c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 17 2018 08:12:45 +0000 Subject: Adjust get_pull_request_of_user to be more flexible for the API use-case This basically allows the API to directly return the PRs filed or actionable by the user (actionable being all the user's PRs minus the ones they filed). Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index f18bd8b..fbe4fbf 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -4247,10 +4247,16 @@ def could_be_text(text): def get_pull_request_of_user( - session, username, status=None, offset=None, limit=None): + session, username, status=None, filed=None, actionable=None, + offset=None, limit=None, count=False): '''List the opened pull-requests of an user. These pull-requests have either been opened by that user or against projects that user has commit on. + + If filed: only the PRs opened/filed by the specified username will be + returned. + If actionable: only the PRs not opened/filed by the specified username + will be returned. ''' projects = session.query( sqlalchemy.distinct(model.Project.id) @@ -4344,12 +4350,26 @@ def get_pull_request_of_user( model.PullRequest.status == status ) + if filed: + query = query.filter( + model.PullRequest.user_id == model.User.id, + model.User.user == filed + ) + elif actionable: + query = query.filter( + model.PullRequest.user_id == model.User.id, + model.User.user != actionable + ) + if offset: query = query.offset(offset) if limit: query = query.limit(limit) - return query.all() + if count: + return query.count() + else: + return query.all() def update_watch_status(session, project, user, watch):