annotate rhodecode/model/pull_request.py @ 4147:1c8f818787b3 rhodecode-2.2.5-gpl

old style: show the full link box on summary page - no overlap or truncation
author Mads Kiilerich <madski@unity3d.com>
date Wed, 02 Jul 2014 19:03:23 -0400
parents ffd45b185016
children 7e5f8c12a3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 # This program is free software: you can redistribute it and/or modify
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 # it under the terms of the GNU General Public License as published by
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 # (at your option) any later version.
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 #
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 # This program is distributed in the hope that it will be useful,
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 # GNU General Public License for more details.
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 #
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 # You should have received a copy of the GNU General Public License
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
14 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
15 rhodecode.model.pull_request
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
18 pull request model for RhodeCode
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
19
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
20 :created_on: Jun 6, 2012
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
21 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
22 :copyright: (c) 2013 RhodeCode GmbH.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
23 :license: GPLv3, see LICENSE for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4024
diff changeset
24 """
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import logging
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
27 import datetime
2597
7b092b919f4f Switch to waitress wsgi server by default in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents: 2584
diff changeset
28
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 from pylons.i18n.translation import _
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30
2597
7b092b919f4f Switch to waitress wsgi server by default in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents: 2584
diff changeset
31 from rhodecode.model.meta import Session
3754
8beaaea70a89 compare: move get_changesets to compare controller where it is used - 2nd half that was lost in 6c79bfcd3b54
Mads Kiilerich <madski@unity3d.com>
parents: 3726
diff changeset
32 from rhodecode.lib import helpers as h
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from rhodecode.model import BaseModel
3175
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
34 from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification,\
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
35 ChangesetStatus
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 from rhodecode.model.notification import NotificationModel
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from rhodecode.lib.utils2 import safe_unicode
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
39
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 log = logging.getLogger(__name__)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 class PullRequestModel(BaseModel):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
2522
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
45 cls = PullRequest
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
46
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
47 def __get_pull_request(self, pull_request):
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
48 return self._get_instance(PullRequest, pull_request)
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
49
4024
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
50 def get_all(self, repo_name, from_=False, closed=False):
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
51 """Get all PRs for repo.
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
52 Default is all PRs to the repo, PRs from the repo if from_.
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
53 Closed PRs are only included if closed is true."""
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
54 repo = self._get_repo(repo_name)
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
55 q = PullRequest.query()
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
56 if from_:
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
57 q = q.filter(PullRequest.org_repo == repo)
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
58 else:
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
59 q = q.filter(PullRequest.other_repo == repo)
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
60 if not closed:
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
61 q = q.filter(PullRequest.status != PullRequest.STATUS_CLOSED)
73ef2a5d3042 pull requests: make it possible control display of closed PRs and whether it is PRs to or from repo
Mads Kiilerich <madski@unity3d.com>
parents: 3781
diff changeset
62 return q.order_by(PullRequest.created_on.desc()).all()
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
63
3175
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
64 def create(self, created_by, org_repo, org_ref, other_repo, other_ref,
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
65 revisions, reviewers, title, description=None):
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
66 from rhodecode.model.changeset_status import ChangesetStatusModel
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
67
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
68 created_by_user = self._get_user(created_by)
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
69 org_repo = self._get_repo(org_repo)
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
70 other_repo = self._get_repo(other_repo)
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 new = PullRequest()
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
73 new.org_repo = org_repo
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 new.org_ref = org_ref
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
75 new.other_repo = other_repo
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 new.other_ref = other_ref
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 new.revisions = revisions
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 new.title = title
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 new.description = description
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
80 new.author = created_by_user
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
81 Session().add(new)
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
82 Session().flush()
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 #members
3389
1c4505e3be5b show flags, and desc sort pull request based on created_date ref #765
Marcin Kuzminski <marcin@python-works.com>
parents: 3387
diff changeset
84 for member in set(reviewers):
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 _usr = self._get_user(member)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 reviewer = PullRequestReviewers(_usr, new)
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
87 Session().add(reviewer)
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88
3175
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
89 #reset state to under-review
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
90 ChangesetStatusModel().set_status(
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
91 repo=org_repo,
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
92 status=ChangesetStatus.STATUS_UNDER_REVIEW,
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
93 user=created_by_user,
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
94 pull_request=new
5d1d25c1c700 set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents: 3076
diff changeset
95 )
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
96 revision_data = [(x.raw_id, x.message)
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
97 for x in map(org_repo.get_changeset, revisions)]
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 #notification to reviewers
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
99 pr_url = h.url('pullrequest_show', repo_name=other_repo.repo_name,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
100 pull_request_id=new.pull_request_id,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
101 qualified=True,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
102 )
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 subject = safe_unicode(
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 h.link_to(
3251
e76859961cbc pull request: mention title of pull request in notifications
Mads Kiilerich <madski@unity3d.com>
parents: 3192
diff changeset
105 _('%(user)s wants you to review pull request #%(pr_id)s: %(pr_title)s') % \
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 {'user': created_by_user.username,
3251
e76859961cbc pull request: mention title of pull request in notifications
Mads Kiilerich <madski@unity3d.com>
parents: 3192
diff changeset
107 'pr_title': new.title,
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 'pr_id': new.pull_request_id},
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
109 pr_url
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 body = description
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
113 kwargs = {
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
114 'pr_title': title,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
115 'pr_user_created': h.person(created_by_user.email),
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
116 'pr_repo_url': h.url('summary_home', repo_name=other_repo.repo_name,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
117 qualified=True,),
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
118 'pr_url': pr_url,
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
119 'pr_revisions': revision_data
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
120 }
3389
1c4505e3be5b show flags, and desc sort pull request based on created_date ref #765
Marcin Kuzminski <marcin@python-works.com>
parents: 3387
diff changeset
121
3781
40d50bb7cf2f emailing: log failing emailing as an error
Mads Kiilerich <madski@unity3d.com>
parents: 3754
diff changeset
122 NotificationModel().create(created_by=created_by_user, subject=subject, body=body,
40d50bb7cf2f emailing: log failing emailing as an error
Mads Kiilerich <madski@unity3d.com>
parents: 3754
diff changeset
123 recipients=reviewers,
40d50bb7cf2f emailing: log failing emailing as an error
Mads Kiilerich <madski@unity3d.com>
parents: 3754
diff changeset
124 type_=Notification.TYPE_PULL_REQUEST, email_kwargs=kwargs)
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 return new
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
126
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
127 def update_reviewers(self, pull_request, reviewers_ids):
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
128 reviewers_ids = set(reviewers_ids)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
129 pull_request = self.__get_pull_request(pull_request)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
130 current_reviewers = PullRequestReviewers.query()\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
131 .filter(PullRequestReviewers.pull_request==
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
132 pull_request)\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
133 .all()
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
134 current_reviewers_ids = set([x.user.user_id for x in current_reviewers])
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
135
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
136 to_add = reviewers_ids.difference(current_reviewers_ids)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
137 to_remove = current_reviewers_ids.difference(reviewers_ids)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
138
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
139 log.debug("Adding %s reviewers" % to_add)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
140 log.debug("Removing %s reviewers" % to_remove)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
141
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
142 for uid in to_add:
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
143 _usr = self._get_user(uid)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
144 reviewer = PullRequestReviewers(_usr, pull_request)
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
145 Session().add(reviewer)
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
146
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
147 for uid in to_remove:
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
148 reviewer = PullRequestReviewers.query()\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
149 .filter(PullRequestReviewers.user_id==uid,
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
150 PullRequestReviewers.pull_request==pull_request)\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
151 .scalar()
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
152 if reviewer:
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
153 Session().delete(reviewer)
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
154
2746
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
155 def delete(self, pull_request):
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
156 pull_request = self.__get_pull_request(pull_request)
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
157 Session().delete(pull_request)
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
158
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
159 def close_pull_request(self, pull_request):
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
160 pull_request = self.__get_pull_request(pull_request)
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
161 pull_request.status = PullRequest.STATUS_CLOSED
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
162 pull_request.updated_on = datetime.datetime.now()
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
163 Session().add(pull_request)