diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -377,8 +377,8 @@ class ChangesetController(BaseRepoContro comm = ChangesetCommentsModel().create( text=request.POST.get('text'), - repo_id=c.rhodecode_db_repo.repo_id, - user_id=c.rhodecode_user.user_id, + repo=c.rhodecode_db_repo.repo_id, + user=c.rhodecode_user.user_id, revision=revision, f_path=request.POST.get('f_path'), line_no=request.POST.get('line'), diff --git a/rhodecode/controllers/pullrequests.py b/rhodecode/controllers/pullrequests.py --- a/rhodecode/controllers/pullrequests.py +++ b/rhodecode/controllers/pullrequests.py @@ -34,6 +34,7 @@ from pylons.controllers.util import abor from pylons.i18n.translation import _ from pylons.decorators import jsonify +from rhodecode.lib.compat import json from rhodecode.lib.base import BaseRepoController, render from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from rhodecode.lib import helpers as h @@ -86,6 +87,8 @@ class PullrequestsController(BaseRepoCon log.error('Review not available for GIT REPOS') raise HTTPNotFound + other_repos_info = {} + c.org_refs = self._get_repo_refs(c.rhodecode_repo) c.org_repos = [] c.other_repos = [] @@ -95,12 +98,23 @@ class PullrequestsController(BaseRepoCon c.other_refs = c.org_refs c.other_repos.extend(c.org_repos) + + #add orginal repo + other_repos_info[org_repo.repo_name] = { + 'gravatar': h.gravatar_url(org_repo.user.email, 24), + 'description': org_repo.description + } + c.default_pull_request = org_repo.repo_name #gather forks and add to this list for fork in org_repo.forks: c.other_repos.append((fork.repo_name, '%s/%s' % ( fork.user.username, fork.repo_name)) ) + other_repos_info[fork.repo_name] = { + 'gravatar': h.gravatar_url(fork.user.email, 24), + 'description': fork.description + } #add parents of this fork also if org_repo.parent: c.default_pull_request = org_repo.parent.repo_name @@ -108,7 +122,12 @@ class PullrequestsController(BaseRepoCon org_repo.parent.user.username, org_repo.parent.repo_name)) ) + other_repos_info[org_repo.parent.repo_name] = { + 'gravatar': h.gravatar_url(org_repo.parent.user.email, 24), + 'description': org_repo.parent.description + } + c.other_repos_info = json.dumps(other_repos_info) c.review_members = [] c.available_members = [] for u in User.query().filter(User.username != 'default').all(): @@ -134,17 +153,18 @@ class PullrequestsController(BaseRepoCon description = req_p['pullrequest_desc'] try: - model = PullRequestModel() - pull_request = model.create(self.rhodecode_user.user_id, org_repo, - org_ref, other_repo, other_ref, revisions, - reviewers, title, description) - Session.commit() + pull_request = PullRequestModel().create( + self.rhodecode_user.user_id, org_repo, org_ref, other_repo, + other_ref, revisions, reviewers, title, description + ) + Session().commit() h.flash(_('Successfully opened new pull request'), category='success') except Exception: h.flash(_('Error occurred during sending pull request'), category='error') log.error(traceback.format_exc()) + return redirect(url('changelog_home', repo_name=org_repo,)) return redirect(url('pullrequest_show', repo_name=other_repo, pull_request_id=pull_request.pull_request_id)) @@ -257,8 +277,8 @@ class PullrequestsController(BaseRepoCon comm = ChangesetCommentsModel().create( text=request.POST.get('text'), - repo_id=c.rhodecode_db_repo.repo_id, - user_id=c.rhodecode_user.user_id, + repo=c.rhodecode_db_repo.repo_id, + user=c.rhodecode_user.user_id, pull_request=pull_request_id, f_path=request.POST.get('f_path'), line_no=request.POST.get('line'), @@ -279,7 +299,7 @@ class PullrequestsController(BaseRepoCon 'user_commented_pull_request:%s' % pull_request_id, c.rhodecode_db_repo, self.ip_addr, self.sa) - Session.commit() + Session().commit() if not request.environ.get('HTTP_X_PARTIAL_XHR'): return redirect(h.url('pullrequest_show', repo_name=repo_name, @@ -302,7 +322,7 @@ class PullrequestsController(BaseRepoCon owner = lambda: co.author.user_id == c.rhodecode_user.user_id if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner: ChangesetCommentsModel().delete(comment=co) - Session.commit() + Session().commit() return True else: raise HTTPForbidden() \ No newline at end of file diff --git a/rhodecode/model/comment.py b/rhodecode/model/comment.py --- a/rhodecode/model/comment.py +++ b/rhodecode/model/comment.py @@ -57,7 +57,7 @@ class ChangesetCommentsModel(BaseModel): user_objects.append(user_obj) return user_objects - def create(self, text, repo_id, user_id, revision=None, pull_request=None, + def create(self, text, repo, user, revision=None, pull_request=None, f_path=None, line_no=None, status_change=None): """ Creates new comment for changeset or pull request. @@ -65,8 +65,8 @@ class ChangesetCommentsModel(BaseModel): status change of changeset or changesets associated with pull request :param text: - :param repo_id: - :param user_id: + :param repo: + :param user: :param revision: :param pull_request: :param f_path: @@ -76,10 +76,11 @@ class ChangesetCommentsModel(BaseModel): if not text: return - repo = Repository.get(repo_id) + repo = self._get_repo(repo) + user = self._get_user(user) comment = ChangesetComment() comment.repo = repo - comment.user_id = user_id + comment.author = user comment.text = text comment.f_path = f_path comment.line_no = line_no @@ -92,7 +93,7 @@ class ChangesetCommentsModel(BaseModel): elif pull_request: pull_request = self.__get_pull_request(pull_request) comment.pull_request = pull_request - desc = '' + desc = pull_request.pull_request_id else: raise Exception('Please specify revision or pull_request_id') @@ -108,8 +109,8 @@ class ChangesetCommentsModel(BaseModel): if line_no: line = _('on line %s') % line_no subj = safe_unicode( - h.link_to('Re commit: %(commit_desc)s %(line)s' % \ - {'commit_desc': desc, 'line': line}, + h.link_to('Re commit: %(desc)s %(line)s' % \ + {'desc': desc, 'line': line}, h.url('changeset_home', repo_name=repo.repo_name, revision=revision, anchor='comment-%s' % comment.comment_id, @@ -124,8 +125,18 @@ class ChangesetCommentsModel(BaseModel): recipients += [User.get_by_email(author_email)] #pull request elif pull_request: - #TODO: make this something usefull - subj = 'commented on pull request something...' + subj = safe_unicode( + h.link_to('Re pull request: %(desc)s %(line)s' % \ + {'desc': desc, 'line': line}, + h.url('pullrequest_show', + repo_name=pull_request.other_repo.repo_name, + pull_request_id=pull_request.pull_request_id, + anchor='comment-%s' % comment.comment_id, + qualified=True, + ) + ) + ) + notification_type = Notification.TYPE_PULL_REQUEST_COMMENT # get the current participants of this pull request recipients = ChangesetComment.get_users(pull_request_id= @@ -135,7 +146,7 @@ class ChangesetCommentsModel(BaseModel): # create notification objects, and emails NotificationModel().create( - created_by=user_id, subject=subj, body=body, + created_by=user, subject=subj, body=body, recipients=recipients, type_=notification_type, email_kwargs={'status_change': status_change} ) @@ -145,7 +156,7 @@ class ChangesetCommentsModel(BaseModel): if mention_recipients: subj = _('[Mention]') + ' ' + subj NotificationModel().create( - created_by=user_id, subject=subj, body=body, + created_by=user, subject=subj, body=body, recipients=mention_recipients, type_=notification_type, email_kwargs={'status_change': status_change} diff --git a/rhodecode/model/pull_request.py b/rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py +++ b/rhodecode/model/pull_request.py @@ -29,11 +29,15 @@ from pylons.i18n.translation import _ from rhodecode.lib import helpers as h from rhodecode.model import BaseModel -from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification +from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification,\ + ChangesetStatus from rhodecode.model.notification import NotificationModel from rhodecode.lib.utils2 import safe_unicode from rhodecode.lib.vcs.utils.hgcompat import discovery +from rhodecode.model.changeset_status import ChangesetStatusModel +from rhodecode.model.comment import ChangesetCommentsModel +from rhodecode.model.meta import Session log = logging.getLogger(__name__) @@ -48,19 +52,22 @@ class PullRequestModel(BaseModel): def create(self, created_by, org_repo, org_ref, other_repo, other_ref, revisions, reviewers, title, description=None): + 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 = self._get_repo(org_repo) + new.org_repo = org_repo new.org_ref = org_ref - new.other_repo = self._get_repo(other_repo) + new.other_repo = other_repo new.other_ref = other_ref new.revisions = revisions new.title = title new.description = description new.author = created_by_user self.sa.add(new) - + Session().flush() #members for member in reviewers: _usr = self._get_user(member) @@ -82,7 +89,7 @@ class PullRequestModel(BaseModel): ) ) body = description - notif.create(created_by=created_by, subject=subject, body=body, + notif.create(created_by=created_by_user, subject=subject, body=body, recipients=reviewers, type_=Notification.TYPE_PULL_REQUEST,) diff --git a/rhodecode/templates/pullrequests/pullrequest.html b/rhodecode/templates/pullrequests/pullrequest.html --- a/rhodecode/templates/pullrequests/pullrequest.html +++ b/rhodecode/templates/pullrequests/pullrequest.html @@ -50,12 +50,12 @@
- gravatar + gravatar
${h.select('other_repo',c.default_pull_request ,c.other_repos,class_='refs')}:${h.select('other_ref','',c.other_refs,class_='refs')} -
${c.rhodecode_db_repo.description}
+
@@ -142,7 +142,7 @@