From e7207c6f77f8db035bfad394b5e983f23ce4b467 Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Sat, 19 Jan 2013 20:57:19 +0100 Subject: show comments from pull requests into associated changesets --HG-- branch : beta --- rhodecode/controllers/changeset.py | 23 ++++++++++++++++++---- rhodecode/controllers/pullrequests.py | 1 - rhodecode/model/changeset_status.py | 14 ++++++------- .../changeset/changeset_file_comment.html | 5 +++++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py index 32076a00..f982f04f 100644 --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -221,13 +221,25 @@ class ChangesetController(BaseRepoController): for changeset in c.cs_ranges: inlines = [] if method == 'show': - c.statuses.extend([ChangesetStatusModel()\ - .get_status(c.rhodecode_db_repo.repo_id, - changeset.raw_id)]) + c.statuses.extend([ChangesetStatusModel().get_status( + c.rhodecode_db_repo.repo_id, changeset.raw_id)]) c.comments.extend(ChangesetCommentsModel()\ .get_comments(c.rhodecode_db_repo.repo_id, revision=changeset.raw_id)) + + #comments from PR + st = ChangesetStatusModel().get_statuses( + c.rhodecode_db_repo.repo_id, changeset.raw_id, + with_revisions=True) + # from associated statuses, check the pull requests, and + # show comments from them + + prs = set([x.pull_request for x in + filter(lambda x: x.pull_request != None, st)]) + + for pr in prs: + c.comments.extend(pr.comments) inlines = ChangesetCommentsModel()\ .get_inline_comments(c.rhodecode_db_repo.repo_id, revision=changeset.raw_id) @@ -269,6 +281,9 @@ class ChangesetController(BaseRepoController): cs_changes[''] = [None, None, None, None, diff, None] c.changes[changeset.raw_id] = cs_changes + #sort comments by how they were generated + c.comments = sorted(c.comments, key=lambda x: x.comment_id) + # count inline comments for __, lines in c.inline_comments: for comments in lines.values(): @@ -342,7 +357,7 @@ class ChangesetController(BaseRepoController): ) except StatusChangeOnClosedPullRequestError: log.error(traceback.format_exc()) - msg = _('Changing status on a changeset associated with' + msg = _('Changing status on a changeset associated with ' 'a closed pull request is not allowed') h.flash(msg, category='warning') return redirect(h.url('changeset_home', repo_name=repo_name, diff --git a/rhodecode/controllers/pullrequests.py b/rhodecode/controllers/pullrequests.py index 368d06a6..fa08b632 100644 --- a/rhodecode/controllers/pullrequests.py +++ b/rhodecode/controllers/pullrequests.py @@ -224,7 +224,6 @@ class PullrequestsController(BaseRepoController): h.flash(_('Successfully opened new pull request'), category='success') except Exception: - raise h.flash(_('Error occurred during sending pull request'), category='error') log.error(traceback.format_exc()) diff --git a/rhodecode/model/changeset_status.py b/rhodecode/model/changeset_status.py index 3e8d0efd..a7e0efcf 100644 --- a/rhodecode/model/changeset_status.py +++ b/rhodecode/model/changeset_status.py @@ -89,27 +89,27 @@ class ChangesetStatusModel(BaseModel): with_revisions) return q.all() - def get_status(self, repo, revision=None, pull_request=None): + def get_status(self, repo, revision=None, pull_request=None, as_str=True): """ Returns latest status of changeset for given revision or for given pull request. Statuses are versioned inside a table itself and version == 0 is always the current one :param repo: - :type repo: :param revision: 40char hash or None - :type revision: str :param pull_request: pull_request reference - :type: + :param as_str: return status as string not object """ q = self._get_status_query(repo, revision, pull_request) # need to use first here since there can be multiple statuses # returned from pull_request status = q.first() - status = status.status if status else status - st = status or ChangesetStatus.DEFAULT - return str(st) + if as_str: + status = status.status if status else status + st = status or ChangesetStatus.DEFAULT + return str(st) + return status def set_status(self, repo, status, user, comment=None, revision=None, pull_request=None, dont_allow_on_closed_pull_request=False): diff --git a/rhodecode/templates/changeset/changeset_file_comment.html b/rhodecode/templates/changeset/changeset_file_comment.html index c9aa552f..edbce729 100644 --- a/rhodecode/templates/changeset/changeset_file_comment.html +++ b/rhodecode/templates/changeset/changeset_file_comment.html @@ -19,6 +19,11 @@
${co.status_change[0].status_lbl}
+
+ %if co.pull_request: + ${_('Status from pull request %s') % co.pull_request.pull_request_id} + %endif +
%endif %if h.HasPermissionAny('hg.admin', 'repository.admin')() or co.author.user_id == c.rhodecode_user.user_id: -- cgit v1.2.3