diff rhodecode/model/pull_request.py @ 4024:73ef2a5d3042

pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
author Mads Kiilerich <madski@unity3d.com>
date Wed, 05 Jun 2013 01:16:42 +0200
parents 40d50bb7cf2f
children ffd45b185016
line wrap: on
line diff
--- a/rhodecode/model/pull_request.py	Tue Jun 04 14:01:57 2013 +0200
+++ b/rhodecode/model/pull_request.py	Wed Jun 05 01:16:42 2013 +0200
@@ -47,12 +47,19 @@
     def __get_pull_request(self, pull_request):
         return self._get_instance(PullRequest, pull_request)
 
-    def get_all(self, repo):
-        repo = self._get_repo(repo)
-        return PullRequest.query()\
-                .filter(PullRequest.other_repo == repo)\
-                .order_by(PullRequest.created_on.desc())\
-                .all()
+    def get_all(self, repo_name, from_=False, closed=False):
+        """Get all PRs for repo.
+        Default is all PRs to the repo, PRs from the repo if from_.
+        Closed PRs are only included if closed is true."""
+        repo = self._get_repo(repo_name)
+        q = PullRequest.query()
+        if from_:
+            q = q.filter(PullRequest.org_repo == repo)
+        else:
+            q = q.filter(PullRequest.other_repo == repo)
+        if not closed:
+            q = q.filter(PullRequest.status != PullRequest.STATUS_CLOSED)
+        return q.order_by(PullRequest.created_on.desc()).all()
 
     def create(self, created_by, org_repo, org_ref, other_repo, other_ref,
                revisions, reviewers, title, description=None):