annotate rhodecode/model/pull_request.py @ 3714:7e3d89d9d3a2 beta

- Manage User’s Groups: create, delete, rename, add/remove users inside. by user group admin. In this case, a user's group can be owned by several people thru an owner user's group. Some refactoring of naming, permission handling logic. - remove some code duplicity as well as inconsistent naming
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 08 Apr 2013 22:47:35 +0200
parents 2053053e0882
children 5dcfa6304f88
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 """
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
3 rhodecode.model.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
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 pull request model for RhodeCode
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 :created_on: Jun 6, 2012
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 :author: marcink
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 :copyright: (C) 2012-2012 Marcin Kuzminski <marcin@python-works.com>
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 :license: GPLv3, see COPYING for more details.
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 """
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # 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
14 # 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
15 # 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
16 # (at your option) any later version.
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 #
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # 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
19 # 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
20 # 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
21 # 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
22 #
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # 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
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
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
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
28 import re
2597
7b092b919f4f Switch to waitress wsgi server by default in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents: 2584
diff changeset
29
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from pylons.i18n.translation import _
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31
2597
7b092b919f4f Switch to waitress wsgi server by default in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents: 2584
diff changeset
32 from rhodecode.model.meta import Session
3303
ae5ac36cdf83 pull request: use unionrepo instead of outgoing
Mads Kiilerich <madski@unity3d.com>
parents: 3301
diff changeset
33 from rhodecode.lib import helpers as h, unionrepo
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 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
35 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
36 ChangesetStatus
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from rhodecode.model.notification import NotificationModel
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 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
39
3303
ae5ac36cdf83 pull request: use unionrepo instead of outgoing
Mads Kiilerich <madski@unity3d.com>
parents: 3301
diff changeset
40 from rhodecode.lib.vcs.utils.hgcompat import scmutil
3301
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
41 from rhodecode.lib.vcs.utils import safe_str
3387
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
42 from rhodecode.lib.vcs.backends.base import EmptyChangeset
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
43
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 log = logging.getLogger(__name__)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 class PullRequestModel(BaseModel):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48
2522
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
49 cls = PullRequest
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
50
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
51 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
52 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
53
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
54 def get_all(self, repo):
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
55 repo = self._get_repo(repo)
3262
14e9a06c37a7 fix order of pull-requests in show all page
Marcin Kuzminski <marcin@python-works.com>
parents: 3251
diff changeset
56 return PullRequest.query()\
14e9a06c37a7 fix order of pull-requests in show all page
Marcin Kuzminski <marcin@python-works.com>
parents: 3251
diff changeset
57 .filter(PullRequest.other_repo == repo)\
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
58 .order_by(PullRequest.created_on.desc())\
3262
14e9a06c37a7 fix order of pull-requests in show all page
Marcin Kuzminski <marcin@python-works.com>
parents: 3251
diff changeset
59 .all()
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
60
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
61 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
62 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
63 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
64
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
65 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
66 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
67 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
68
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 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
70 new.org_repo = org_repo
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 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
72 new.other_repo = other_repo
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 new.other_ref = other_ref
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 new.revisions = revisions
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 new.title = title
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 new.description = description
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
77 new.author = created_by_user
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
78 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
79 Session().flush()
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 #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
81 for member in set(reviewers):
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 _usr = self._get_user(member)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 reviewer = PullRequestReviewers(_usr, new)
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
84 Session().add(reviewer)
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85
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
86 #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
87 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
88 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
89 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
90 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
91 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
92 )
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
93 revision_data = [(x.raw_id, x.message)
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
94 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
95 #notification to reviewers
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 notif = NotificationModel()
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
97
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
98 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
99 pull_request_id=new.pull_request_id,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
100 qualified=True,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
101 )
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 subject = safe_unicode(
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 h.link_to(
3251
e76859961cbc pull request: mention title of pull request in notifications
Mads Kiilerich <madski@unity3d.com>
parents: 3192
diff changeset
104 _('%(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
105 {'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
106 'pr_title': new.title,
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 'pr_id': new.pull_request_id},
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
108 pr_url
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 )
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 body = description
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
112 kwargs = {
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
113 'pr_title': title,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
114 '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
115 '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
116 qualified=True,),
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
117 'pr_url': pr_url,
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
118 'pr_revisions': revision_data
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
119 }
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
120
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
121 notif.create(created_by=created_by_user, subject=subject, body=body,
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122 recipients=reviewers,
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
123 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
124 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
125
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
126 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
127 reviewers_ids = set(reviewers_ids)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
128 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
129 current_reviewers = PullRequestReviewers.query()\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
130 .filter(PullRequestReviewers.pull_request==
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
131 pull_request)\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
132 .all()
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
133 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
134
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
135 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
136 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
137
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
138 log.debug("Adding %s reviewers" % to_add)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
139 log.debug("Removing %s reviewers" % to_remove)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
140
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
141 for uid in to_add:
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
142 _usr = self._get_user(uid)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
143 reviewer = PullRequestReviewers(_usr, pull_request)
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
144 Session().add(reviewer)
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
145
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
146 for uid in to_remove:
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
147 reviewer = PullRequestReviewers.query()\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
148 .filter(PullRequestReviewers.user_id==uid,
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
149 PullRequestReviewers.pull_request==pull_request)\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
150 .scalar()
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
151 if reviewer:
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
152 Session().delete(reviewer)
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
153
2746
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
154 def delete(self, pull_request):
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
155 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
156 Session().delete(pull_request)
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
157
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
158 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
159 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
160 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
161 pull_request.updated_on = datetime.datetime.now()
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3389
diff changeset
162 Session().add(pull_request)
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
163
3486
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
164 def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref, merge):
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
165 """
3323
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
166 Returns a list of changesets that can be merged from org_repo@org_ref
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
167 to other_repo@other_ref ... and the ancestor that would be used for merge
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
168
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
169 :param org_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
170 :param org_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
171 :param other_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
172 :param other_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
173 :param tmp:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
174 """
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
175
3323
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
176 ancestor = None
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
177
3300
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
178 if alias == 'hg':
3301
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
179 # lookup up the exact node id
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
180 _revset_predicates = {
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
181 'branch': 'branch',
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
182 'book': 'bookmark',
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
183 'tag': 'tag',
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
184 'rev': 'id',
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
185 }
3387
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
186
3301
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
187 org_rev_spec = "%s('%s')" % (_revset_predicates[org_ref[0]],
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
188 safe_str(org_ref[1]))
3387
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
189 if org_ref[1] == EmptyChangeset().raw_id:
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
190 org_rev = org_ref[1]
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
191 else:
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
192 org_rev = org_repo._repo[scmutil.revrange(org_repo._repo,
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
193 [org_rev_spec])[-1]]
3301
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
194 other_rev_spec = "%s('%s')" % (_revset_predicates[other_ref[0]],
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
195 safe_str(other_ref[1]))
3387
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
196 if other_ref[1] == EmptyChangeset().raw_id:
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
197 other_rev = other_ref[1]
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
198 else:
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
199 other_rev = other_repo._repo[scmutil.revrange(other_repo._repo,
bd5420ea396b better handling of EmptyChangeset case in cherry pick pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 3380
diff changeset
200 [other_rev_spec])[-1]]
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
201
3300
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
202 #case two independent repos
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
203 if org_repo != other_repo:
3322
c9b0f1d363c7 compare: swap org and other when they refer to different repos, ie are pull request style
Mads Kiilerich <madski@unity3d.com>
parents: 3315
diff changeset
204 hgrepo = unionrepo.unionrepository(other_repo.baseui,
c9b0f1d363c7 compare: swap org and other when they refer to different repos, ie are pull request style
Mads Kiilerich <madski@unity3d.com>
parents: 3315
diff changeset
205 other_repo.path,
c9b0f1d363c7 compare: swap org and other when they refer to different repos, ie are pull request style
Mads Kiilerich <madski@unity3d.com>
parents: 3315
diff changeset
206 org_repo.path)
c9b0f1d363c7 compare: swap org and other when they refer to different repos, ie are pull request style
Mads Kiilerich <madski@unity3d.com>
parents: 3315
diff changeset
207 # all the changesets we are looking for will be in other_repo,
c9b0f1d363c7 compare: swap org and other when they refer to different repos, ie are pull request style
Mads Kiilerich <madski@unity3d.com>
parents: 3315
diff changeset
208 # so rev numbers from hgrepo can be used in other_repo
3300
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
209
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
210 #no remote compare do it on the same repository
3300
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
211 else:
3322
c9b0f1d363c7 compare: swap org and other when they refer to different repos, ie are pull request style
Mads Kiilerich <madski@unity3d.com>
parents: 3315
diff changeset
212 hgrepo = other_repo._repo
3315
fc08484c5bf3 whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3303
diff changeset
213
3486
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
214 if merge:
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
215 revs = ["ancestors(id('%s')) and not ancestors(id('%s')) and not id('%s')" %
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
216 (other_rev, org_rev, org_rev)]
3323
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
217
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
218 ancestors = scmutil.revrange(hgrepo,
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
219 ["ancestor(id('%s'), id('%s'))" % (org_rev, other_rev)])
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
220 if len(ancestors) == 1:
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
221 ancestor = hgrepo[ancestors[0]].hex()
3486
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
222 else:
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
223 # TODO: have both + and - changesets
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
224 revs = ["id('%s') :: id('%s') - id('%s')" %
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
225 (org_rev, other_rev, org_rev)]
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
226
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
227 changesets = [other_repo.get_changeset(cs)
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
228 for cs in scmutil.revrange(hgrepo, revs)]
3300
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
229
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
230 elif alias == 'git':
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
231 assert org_repo == other_repo, (org_repo, other_repo) # no git support for different repos
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
232 so, se = org_repo.run_git_command(
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
233 'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1],
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
234 other_ref[1])
2c0208bd686b pull request: shuffle different-repo and hg-git conditionals around, no code change
Mads Kiilerich <madski@unity3d.com>
parents: 3262
diff changeset
235 )
3323
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
236 changesets = [org_repo.get_changeset(cs)
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
237 for cs in re.findall(r'[0-9a-fA-F]{40}', so)]
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
238
3323
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
239 return changesets, ancestor
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
240
3486
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
241 def get_compare_data(self, org_repo, org_ref, other_repo, other_ref, merge):
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
242 """
3301
3c91ec4419a6 pull requeset: move stuff around, preparing for next change
Mads Kiilerich <madski@unity3d.com>
parents: 3300
diff changeset
243 Returns incoming changesets for mercurial repositories
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
244
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
245 :param org_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
246 :param org_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
247 :param other_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
248 :param other_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
249 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
250
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
251 if len(org_ref) != 2 or not isinstance(org_ref, (list, tuple)):
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
252 raise Exception('org_ref must be a two element list/tuple')
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
253
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
254 if len(other_ref) != 2 or not isinstance(org_ref, (list, tuple)):
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
255 raise Exception('other_ref must be a two element list/tuple')
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
256
3443
3ac76dfdab8e compare: minor refactoring and comments
Mads Kiilerich <madski@unity3d.com>
parents: 3430
diff changeset
257 cs_ranges, ancestor = self._get_changesets(org_repo.scm_instance.alias,
3ac76dfdab8e compare: minor refactoring and comments
Mads Kiilerich <madski@unity3d.com>
parents: 3430
diff changeset
258 org_repo.scm_instance, org_ref,
3486
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
259 other_repo.scm_instance, other_ref,
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3443
diff changeset
260 merge)
3323
a07296564f6b compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 3322
diff changeset
261 return cs_ranges, ancestor