annotate rhodecode/model/pull_request.py @ 3262:14e9a06c37a7 beta

fix order of pull-requests in show all page
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 30 Jan 2013 00:11:35 +0100
parents e76859961cbc
children 2c0208bd686b
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
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
27 import binascii
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
28 import datetime
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
29 import re
2597
7b092b919f4f Switch to waitress wsgi server by default in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents: 2584
diff changeset
30
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 from pylons.i18n.translation import _
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32
2597
7b092b919f4f Switch to waitress wsgi server by default in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents: 2584
diff changeset
33 from rhodecode.model.meta import Session
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 from rhodecode.lib import helpers as h
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 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
36 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
37 ChangesetStatus
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 from rhodecode.model.notification import NotificationModel
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 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
40
2801
69420c48a0e6 fixes #550 mercurial repositories comparision failed when origin repo had
Marcin Kuzminski <marcin@python-works.com>
parents: 2799
diff changeset
41 from rhodecode.lib.vcs.utils.hgcompat import discovery, localrepo, scmutil, \
69420c48a0e6 fixes #550 mercurial repositories comparision failed when origin repo had
Marcin Kuzminski <marcin@python-works.com>
parents: 2799
diff changeset
42 findcommonoutgoing
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)\
14e9a06c37a7 fix order of pull-requests in show all page
Marcin Kuzminski <marcin@python-works.com>
parents: 3251
diff changeset
58 .order_by(PullRequest.created_on)\
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
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 self.sa.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
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 for member in reviewers:
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)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 self.sa.add(reviewer)
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 )
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
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 #notification to reviewers
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 notif = NotificationModel()
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
96
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
97 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
98 pull_request_id=new.pull_request_id,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
99 qualified=True,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
100 )
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 subject = safe_unicode(
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 h.link_to(
3251
e76859961cbc pull request: mention title of pull request in notifications
Mads Kiilerich <madski@unity3d.com>
parents: 3192
diff changeset
103 _('%(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
104 {'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
105 'pr_title': new.title,
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 'pr_id': new.pull_request_id},
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
107 pr_url
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 )
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 body = description
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
111 kwargs = {
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
112 'pr_title': title,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
113 '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
114 '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
115 qualified=True,),
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
116 'pr_url': pr_url,
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
117 'pr_revisions': revisions
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
118 }
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
119 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
120 recipients=reviewers,
2799
493646d3146f Nicer email notifications about pull-request
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
121 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
122 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
123
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
124 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
125 reviewers_ids = set(reviewers_ids)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
126 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
127 current_reviewers = PullRequestReviewers.query()\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
128 .filter(PullRequestReviewers.pull_request==
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
129 pull_request)\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
130 .all()
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
131 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
132
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
133 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
134 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
135
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
136 log.debug("Adding %s reviewers" % to_add)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
137 log.debug("Removing %s reviewers" % to_remove)
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 for uid in to_add:
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
140 _usr = self._get_user(uid)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
141 reviewer = PullRequestReviewers(_usr, pull_request)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
142 self.sa.add(reviewer)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
143
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
144 for uid in to_remove:
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
145 reviewer = PullRequestReviewers.query()\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
146 .filter(PullRequestReviewers.user_id==uid,
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
147 PullRequestReviewers.pull_request==pull_request)\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
148 .scalar()
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
149 if reviewer:
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
150 self.sa.delete(reviewer)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
151
2746
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
152 def delete(self, pull_request):
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
153 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
154 Session().delete(pull_request)
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
155
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
156 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
157 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
158 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
159 pull_request.updated_on = datetime.datetime.now()
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 self.sa.add(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
3192
b9105d31e582 refactoring: drop unused 'discovery data' in pull request and compare diffs
Mads Kiilerich <madski@unity3d.com>
parents: 3175
diff changeset
162 def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref):
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
163 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
164 Returns a list of changesets that are incoming from org_repo@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
165 to other_repo@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
166
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
167 :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
168 :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
169 :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
170 :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
171 :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
172 """
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
173
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
174 changesets = []
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
175 #case two independent repos
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
176 if org_repo != other_repo:
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
177 revs = [
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
178 org_repo._repo.lookup(org_ref[1]),
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
179 org_repo._repo.lookup(other_ref[1]),
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
180 ]
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
181
2801
69420c48a0e6 fixes #550 mercurial repositories comparision failed when origin repo had
Marcin Kuzminski <marcin@python-works.com>
parents: 2799
diff changeset
182 obj = findcommonoutgoing(org_repo._repo,
2810
4a5c56da2603 fixes #555 issues when comparing non-related repositories on pull requests or compare view
Marcin Kuzminski <marcin@python-works.com>
parents: 2801
diff changeset
183 localrepo.locallegacypeer(other_repo._repo.local()),
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
184 revs,
2810
4a5c56da2603 fixes #555 issues when comparing non-related repositories on pull requests or compare view
Marcin Kuzminski <marcin@python-works.com>
parents: 2801
diff changeset
185 force=True)
2801
69420c48a0e6 fixes #550 mercurial repositories comparision failed when origin repo had
Marcin Kuzminski <marcin@python-works.com>
parents: 2799
diff changeset
186 revs = obj.missing
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
187
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
188 for cs in map(binascii.hexlify, revs):
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
189 _cs = org_repo.get_changeset(cs)
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
190 changesets.append(_cs)
3076
5deb16cd2802 fixes #668 cherry picking of changeset should also work now on picking single changesets, and the ones from top
Marcin Kuzminski <marcin@python-works.com>
parents: 3023
diff changeset
191 # in case we have revisions filter out the ones not in given range
5deb16cd2802 fixes #668 cherry picking of changeset should also work now on picking single changesets, and the ones from top
Marcin Kuzminski <marcin@python-works.com>
parents: 3023
diff changeset
192 if org_ref[0] == 'rev' and other_ref[0] == 'rev':
5deb16cd2802 fixes #668 cherry picking of changeset should also work now on picking single changesets, and the ones from top
Marcin Kuzminski <marcin@python-works.com>
parents: 3023
diff changeset
193 revs = [x.raw_id for x in changesets]
5deb16cd2802 fixes #668 cherry picking of changeset should also work now on picking single changesets, and the ones from top
Marcin Kuzminski <marcin@python-works.com>
parents: 3023
diff changeset
194 start = org_ref[1]
5deb16cd2802 fixes #668 cherry picking of changeset should also work now on picking single changesets, and the ones from top
Marcin Kuzminski <marcin@python-works.com>
parents: 3023
diff changeset
195 stop = other_ref[1]
5deb16cd2802 fixes #668 cherry picking of changeset should also work now on picking single changesets, and the ones from top
Marcin Kuzminski <marcin@python-works.com>
parents: 3023
diff changeset
196 changesets = changesets[revs.index(start):revs.index(stop) + 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
197 else:
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
198 #no remote compare do it on the same repository
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
199 if alias == 'hg':
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
200 _revset_predicates = {
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
201 'branch': 'branch',
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
202 'book': 'bookmark',
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
203 'tag': 'tag',
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
204 'rev': 'id',
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
205 }
2630
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
206
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
207 revs = [
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
208 "ancestors(%s('%s')) and not ancestors(%s('%s'))" % (
3015
16af24982e30 Multiple changes for compare system
Marcin Kuzminski <marcin@python-works.com>
parents: 3010
diff changeset
209 _revset_predicates[other_ref[0]], other_ref[1],
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
210 _revset_predicates[org_ref[0]], org_ref[1],
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
211 )
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
212 ]
2630
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
213
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
214 out = scmutil.revrange(org_repo._repo, revs)
3015
16af24982e30 Multiple changes for compare system
Marcin Kuzminski <marcin@python-works.com>
parents: 3010
diff changeset
215 for cs in (out):
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
216 changesets.append(org_repo.get_changeset(cs))
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
217 elif alias == 'git':
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
218 so, se = org_repo.run_git_command(
3015
16af24982e30 Multiple changes for compare system
Marcin Kuzminski <marcin@python-works.com>
parents: 3010
diff changeset
219 'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1],
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
220 other_ref[1])
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
221 )
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
222 ids = re.findall(r'[0-9a-fA-F]{40}', so)
3015
16af24982e30 Multiple changes for compare system
Marcin Kuzminski <marcin@python-works.com>
parents: 3010
diff changeset
223 for cs in (ids):
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
224 changesets.append(org_repo.get_changeset(cs))
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
225
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
226 return changesets
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
227
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
228 def get_compare_data(self, org_repo, org_ref, other_repo, 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
229 """
3192
b9105d31e582 refactoring: drop unused 'discovery data' in pull request and compare diffs
Mads Kiilerich <madski@unity3d.com>
parents: 3175
diff changeset
230 Returns incomming 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
231
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
232 :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
233 :type 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
234 :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
235 :type 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
236 :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
237 :type 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
238 :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
239 :type 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
240 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
241
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 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
243 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
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 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
246 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
247
3010
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
248 org_repo_scm = org_repo.scm_instance
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
249 other_repo_scm = other_repo.scm_instance
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
250
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
251 alias = org_repo.scm_instance.alias
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
252 cs_ranges = self._get_changesets(alias,
bf96fd1920c1 Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents: 2810
diff changeset
253 org_repo_scm, org_ref,
3192
b9105d31e582 refactoring: drop unused 'discovery data' in pull request and compare diffs
Mads Kiilerich <madski@unity3d.com>
parents: 3175
diff changeset
254 other_repo_scm, other_ref)
b9105d31e582 refactoring: drop unused 'discovery data' in pull request and compare diffs
Mads Kiilerich <madski@unity3d.com>
parents: 3175
diff changeset
255 return cs_ranges