changeset 3176:7ec5f9c1df45 beta

show comments from pull requests into associated changesets
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 19 Jan 2013 20:57:19 +0100
parents 5d1d25c1c700
children 48a18391f6da
files rhodecode/controllers/changeset.py rhodecode/controllers/pullrequests.py rhodecode/model/changeset_status.py rhodecode/templates/changeset/changeset_file_comment.html
diffstat 4 files changed, 31 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/changeset.py	Sat Jan 19 19:42:37 2013 +0100
+++ b/rhodecode/controllers/changeset.py	Sat Jan 19 20:57:19 2013 +0100
@@ -221,13 +221,25 @@
         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 @@
                 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 @@
                 )
             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,
--- a/rhodecode/controllers/pullrequests.py	Sat Jan 19 19:42:37 2013 +0100
+++ b/rhodecode/controllers/pullrequests.py	Sat Jan 19 20:57:19 2013 +0100
@@ -224,7 +224,6 @@
             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())
--- a/rhodecode/model/changeset_status.py	Sat Jan 19 19:42:37 2013 +0100
+++ b/rhodecode/model/changeset_status.py	Sat Jan 19 20:57:19 2013 +0100
@@ -89,27 +89,27 @@
                                    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):
--- a/rhodecode/templates/changeset/changeset_file_comment.html	Sat Jan 19 19:42:37 2013 +0100
+++ b/rhodecode/templates/changeset/changeset_file_comment.html	Sat Jan 19 20:57:19 2013 +0100
@@ -19,6 +19,11 @@
              <div style="float:left;padding:0px 2px 0px 2px"><span style="font-size: 18px;">&rsaquo;</span></div>
              <div title="${_('Changeset status')}" class="changeset-status-lbl"> ${co.status_change[0].status_lbl}</div>
              <div class="changeset-status-ico"><img src="${h.url(str('/images/icons/flag_status_%s.png' % co.status_change[0].status))}" /></div>
+             <div style="float:left;padding:3px 0px 0px 5px"> <span class="">
+             %if co.pull_request:
+                <a href="${h.url('pullrequest_show',repo_name=co.pull_request.other_repo.repo_name,pull_request_id=co.pull_request.pull_request_id)}">${_('Status from pull request %s') % co.pull_request.pull_request_id}</a>   
+             %endif
+             </span> </div>
            </div>
         %endif
       %if h.HasPermissionAny('hg.admin', 'repository.admin')() or co.author.user_id == c.rhodecode_user.user_id: