Files
@ aa3b55946089
Branch filter:
Location: kallithea/rhodecode/model/pull_request.py - annotation
aa3b55946089
6.0 KiB
text/x-python
Migrate to Mergely 3.3.4.
RhodeCode 2.2.5 distributed Mergely 3.3.4 with some of the changes that
Mergely 3.3.3 in RhodeCode 1.7.2 also had. That do however not seem to be
changes we want for Kallithea this way and we take the 3.3.4 files as they are.
I've also included the Mergely license file, as downloaded from:
http://www.mergely.com/license.php
That LICENSE file is kept in HTML just as it was downloaded from their
website. While it's a bit annoying to keep the license file in HTML, this is
the way it came from upstream so we'll leave it that way.
Since the Javascript code is used with other GPLv3 Javascript, we are using the
GPL option of Mergely's tri-license.
Finally, note that previously, this was incorrectly called "mergerly", so the
opportunity is taken here to correct the name. That required changes to
diff_2way.html.
As commands::
$ wget -N --output-document LICENSE-MERGELY.html http://www.mergely.com/license.php
$ hg add LICENSE-MERGELY.html
$ hg mv rhodecode/public/css/mergerly.css rhodecode/public/css/mergely.css
$ hg mv rhodecode/public/js/mergerly.js rhodecode/public/js/mergely.js
$ sed -i 's,mergerly\.,mergely,g' rhodecode/templates/files/diff_2way.html
$ ( cd /tmp; \
wget -N http://www.mergely.com/releases/mergely-3.3.4.zip; \
unzip mergely-3.3.4.zip )
$ sha256sum /tmp/mergely-3.3.4.zip
87415d30494bbe829c248881aa7cdc0303f7e70b458a5f687615564d4498cc82 mergely-3.3.4.zip
$ cp /tmp/mergely-3.3.4/lib/mergely.js rhodecode/public/js/mergely.js
$ cp /tmp/mergely-3.3.4/lib/mergely.css rhodecode/public/css/mergely.css
$ sed -i -e '/^ \* Version/a\ *\n * NOTE by bkuhn@sfconservancy.org for Kallithea:\n * Mergely license appears at http://www.mergely.com/license.php and in LICENSE-MERGELY.html' rhodecode/public/js/mergely.js rhodecode/public/css/mergely.css
RhodeCode 2.2.5 distributed Mergely 3.3.4 with some of the changes that
Mergely 3.3.3 in RhodeCode 1.7.2 also had. That do however not seem to be
changes we want for Kallithea this way and we take the 3.3.4 files as they are.
I've also included the Mergely license file, as downloaded from:
http://www.mergely.com/license.php
That LICENSE file is kept in HTML just as it was downloaded from their
website. While it's a bit annoying to keep the license file in HTML, this is
the way it came from upstream so we'll leave it that way.
Since the Javascript code is used with other GPLv3 Javascript, we are using the
GPL option of Mergely's tri-license.
Finally, note that previously, this was incorrectly called "mergerly", so the
opportunity is taken here to correct the name. That required changes to
diff_2way.html.
As commands::
$ wget -N --output-document LICENSE-MERGELY.html http://www.mergely.com/license.php
$ hg add LICENSE-MERGELY.html
$ hg mv rhodecode/public/css/mergerly.css rhodecode/public/css/mergely.css
$ hg mv rhodecode/public/js/mergerly.js rhodecode/public/js/mergely.js
$ sed -i 's,mergerly\.,mergely,g' rhodecode/templates/files/diff_2way.html
$ ( cd /tmp; \
wget -N http://www.mergely.com/releases/mergely-3.3.4.zip; \
unzip mergely-3.3.4.zip )
$ sha256sum /tmp/mergely-3.3.4.zip
87415d30494bbe829c248881aa7cdc0303f7e70b458a5f687615564d4498cc82 mergely-3.3.4.zip
$ cp /tmp/mergely-3.3.4/lib/mergely.js rhodecode/public/js/mergely.js
$ cp /tmp/mergely-3.3.4/lib/mergely.css rhodecode/public/css/mergely.css
$ sed -i -e '/^ \* Version/a\ *\n * NOTE by bkuhn@sfconservancy.org for Kallithea:\n * Mergely license appears at http://www.mergely.com/license.php and in LICENSE-MERGELY.html' rhodecode/public/js/mergely.js rhodecode/public/css/mergely.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | f29469677319 f29469677319 f29469677319 f29469677319 f29469677319 f29469677319 f29469677319 f29469677319 f29469677319 f29469677319 f29469677319 f29469677319 f29469677319 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 f29469677319 f29469677319 58c529332e7e 7b092b919f4f f29469677319 f29469677319 7b092b919f4f 8beaaea70a89 f29469677319 5d1d25c1c700 5d1d25c1c700 f29469677319 f29469677319 f29469677319 3bf057a7f7e8 f29469677319 f29469677319 f29469677319 f29469677319 f29469677319 17893d61792a 17893d61792a 58c529332e7e 58c529332e7e 58c529332e7e 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 73ef2a5d3042 1bc579bcd67a 5d1d25c1c700 5d1d25c1c700 5d1d25c1c700 1c2ba03c42b4 1bc579bcd67a 1c2ba03c42b4 1c2ba03c42b4 f29469677319 f29469677319 1c2ba03c42b4 f29469677319 1c2ba03c42b4 f29469677319 f29469677319 f29469677319 f29469677319 1bc579bcd67a bbe21df7ad48 1c2ba03c42b4 f29469677319 1c4505e3be5b f29469677319 f29469677319 bbe21df7ad48 f29469677319 5d1d25c1c700 5d1d25c1c700 5d1d25c1c700 5d1d25c1c700 5d1d25c1c700 5d1d25c1c700 5d1d25c1c700 bbe21df7ad48 bbe21df7ad48 f29469677319 493646d3146f 493646d3146f 493646d3146f 493646d3146f f29469677319 f29469677319 e76859961cbc f29469677319 e76859961cbc f29469677319 493646d3146f f29469677319 f29469677319 f29469677319 493646d3146f 493646d3146f 493646d3146f 493646d3146f 493646d3146f 493646d3146f bbe21df7ad48 493646d3146f 1c4505e3be5b 40d50bb7cf2f 40d50bb7cf2f 40d50bb7cf2f f29469677319 3bf057a7f7e8 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d bbe21df7ad48 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d 3f50a5e8fc4d bbe21df7ad48 3f50a5e8fc4d 49a4864b11c1 49a4864b11c1 49a4864b11c1 49a4864b11c1 58c529332e7e 58c529332e7e 58c529332e7e 58c529332e7e bbe21df7ad48 | # -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
rhodecode.model.pull_request
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pull request model for RhodeCode
:created_on: Jun 6, 2012
:author: marcink
:copyright: (c) 2013 RhodeCode GmbH.
:license: GPLv3, see LICENSE for more details.
"""
import logging
import datetime
from pylons.i18n.translation import _
from rhodecode.model.meta import Session
from rhodecode.lib import helpers as h
from rhodecode.model import BaseModel
from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification,\
ChangesetStatus
from rhodecode.model.notification import NotificationModel
from rhodecode.lib.utils2 import safe_unicode
log = logging.getLogger(__name__)
class PullRequestModel(BaseModel):
cls = PullRequest
def __get_pull_request(self, pull_request):
return self._get_instance(PullRequest, pull_request)
def get_all(self, repo_name, from_=False, closed=False):
"""Get all PRs for repo.
Default is all PRs to the repo, PRs from the repo if from_.
Closed PRs are only included if closed is true."""
repo = self._get_repo(repo_name)
q = PullRequest.query()
if from_:
q = q.filter(PullRequest.org_repo == repo)
else:
q = q.filter(PullRequest.other_repo == repo)
if not closed:
q = q.filter(PullRequest.status != PullRequest.STATUS_CLOSED)
return q.order_by(PullRequest.created_on.desc()).all()
def create(self, created_by, org_repo, org_ref, other_repo, other_ref,
revisions, reviewers, title, description=None):
from rhodecode.model.changeset_status import ChangesetStatusModel
created_by_user = self._get_user(created_by)
org_repo = self._get_repo(org_repo)
other_repo = self._get_repo(other_repo)
new = PullRequest()
new.org_repo = org_repo
new.org_ref = org_ref
new.other_repo = other_repo
new.other_ref = other_ref
new.revisions = revisions
new.title = title
new.description = description
new.author = created_by_user
Session().add(new)
Session().flush()
#members
for member in set(reviewers):
_usr = self._get_user(member)
reviewer = PullRequestReviewers(_usr, new)
Session().add(reviewer)
#reset state to under-review
ChangesetStatusModel().set_status(
repo=org_repo,
status=ChangesetStatus.STATUS_UNDER_REVIEW,
user=created_by_user,
pull_request=new
)
revision_data = [(x.raw_id, x.message)
for x in map(org_repo.get_changeset, revisions)]
#notification to reviewers
pr_url = h.url('pullrequest_show', repo_name=other_repo.repo_name,
pull_request_id=new.pull_request_id,
qualified=True,
)
subject = safe_unicode(
h.link_to(
_('%(user)s wants you to review pull request #%(pr_id)s: %(pr_title)s') % \
{'user': created_by_user.username,
'pr_title': new.title,
'pr_id': new.pull_request_id},
pr_url
)
)
body = description
kwargs = {
'pr_title': title,
'pr_user_created': h.person(created_by_user.email),
'pr_repo_url': h.url('summary_home', repo_name=other_repo.repo_name,
qualified=True,),
'pr_url': pr_url,
'pr_revisions': revision_data
}
NotificationModel().create(created_by=created_by_user, subject=subject, body=body,
recipients=reviewers,
type_=Notification.TYPE_PULL_REQUEST, email_kwargs=kwargs)
return new
def update_reviewers(self, pull_request, reviewers_ids):
reviewers_ids = set(reviewers_ids)
pull_request = self.__get_pull_request(pull_request)
current_reviewers = PullRequestReviewers.query()\
.filter(PullRequestReviewers.pull_request==
pull_request)\
.all()
current_reviewers_ids = set([x.user.user_id for x in current_reviewers])
to_add = reviewers_ids.difference(current_reviewers_ids)
to_remove = current_reviewers_ids.difference(reviewers_ids)
log.debug("Adding %s reviewers" % to_add)
log.debug("Removing %s reviewers" % to_remove)
for uid in to_add:
_usr = self._get_user(uid)
reviewer = PullRequestReviewers(_usr, pull_request)
Session().add(reviewer)
for uid in to_remove:
reviewer = PullRequestReviewers.query()\
.filter(PullRequestReviewers.user_id==uid,
PullRequestReviewers.pull_request==pull_request)\
.scalar()
if reviewer:
Session().delete(reviewer)
def delete(self, pull_request):
pull_request = self.__get_pull_request(pull_request)
Session().delete(pull_request)
def close_pull_request(self, pull_request):
pull_request = self.__get_pull_request(pull_request)
pull_request.status = PullRequest.STATUS_CLOSED
pull_request.updated_on = datetime.datetime.now()
Session().add(pull_request)
|