# HG changeset patch # User Marcin Kuzminski # Date 2018-07-17 12:45:29 # Node ID 6d16d1cd1e9de69d7ca9df90e3cbf6ae15eec7c5 # Parent d308132f7fc406ba36e6d4d76c2790ce03d10364 pull-requests: make the renderer stored and saved for each pull requests. - gives backward compatability with previous versions which didn't set renderer - allows versioning of renderer changes diff --git a/rhodecode/__init__.py b/rhodecode/__init__.py --- a/rhodecode/__init__.py +++ b/rhodecode/__init__.py @@ -51,7 +51,7 @@ PYRAMID_SETTINGS = {} EXTENSIONS = {} __version__ = ('.'.join((str(each) for each in VERSION[:3]))) -__dbversion__ = 86 # defines current db version for migrations +__dbversion__ = 87 # defines current db version for migrations __platform__ = platform.system() __license__ = 'AGPLv3, and Commercial License' __author__ = 'RhodeCode GmbH' diff --git a/rhodecode/apps/repository/tests/test_repo_pullrequests.py b/rhodecode/apps/repository/tests/test_repo_pullrequests.py --- a/rhodecode/apps/repository/tests/test_repo_pullrequests.py +++ b/rhodecode/apps/repository/tests/test_repo_pullrequests.py @@ -368,8 +368,9 @@ class TestPullrequestsView(object): ('target_repo', target.repo_name), ('target_ref', 'branch:default:' + commit_ids['ancestor']), ('common_ancestor', commit_ids['ancestor']), + ('pullrequest_title', 'Title'), ('pullrequest_desc', 'Description'), - ('pullrequest_title', 'Title'), + ('description_renderer', 'markdown'), ('__start__', 'review_members:sequence'), ('__start__', 'reviewer:mapping'), ('user_id', '1'), @@ -427,8 +428,9 @@ class TestPullrequestsView(object): ('target_repo', target.repo_name), ('target_ref', 'branch:default:' + commit_ids['ancestor-child']), ('common_ancestor', commit_ids['ancestor']), + ('pullrequest_title', 'Title'), ('pullrequest_desc', 'Description'), - ('pullrequest_title', 'Title'), + ('description_renderer', 'markdown'), ('__start__', 'review_members:sequence'), ('__start__', 'reviewer:mapping'), ('user_id', '2'), @@ -493,8 +495,9 @@ class TestPullrequestsView(object): ('target_repo', target.repo_name), ('target_ref', 'branch:default:' + commit_ids['ancestor-child']), ('common_ancestor', commit_ids['ancestor']), + ('pullrequest_title', 'Title'), ('pullrequest_desc', 'Description'), - ('pullrequest_title', 'Title'), + ('description_renderer', 'markdown'), ('__start__', 'review_members:sequence'), ('__start__', 'reviewer:mapping'), ('user_id', '1'), diff --git a/rhodecode/apps/repository/views/repo_pull_requests.py b/rhodecode/apps/repository/views/repo_pull_requests.py --- a/rhodecode/apps/repository/views/repo_pull_requests.py +++ b/rhodecode/apps/repository/views/repo_pull_requests.py @@ -61,7 +61,8 @@ class RepoPullRequestsView(RepoAppView, c = self._get_local_tmpl_context(include_app_defaults=True) c.REVIEW_STATUS_APPROVED = ChangesetStatus.STATUS_APPROVED c.REVIEW_STATUS_REJECTED = ChangesetStatus.STATUS_REJECTED - + # backward compat., we use for OLD PRs a plain renderer + c.renderer = 'plain' return c def _get_pull_requests_list( @@ -297,6 +298,7 @@ class RepoPullRequestsView(RepoAppView, pull_request_at_ver) c.pull_request = pull_request_display_obj + c.renderer = pull_request_at_ver.description_renderer or c.renderer c.pull_request_latest = pull_request_latest if compare or (at_version and not at_version == 'latest'): @@ -894,6 +896,7 @@ class RepoPullRequestsView(RepoAppView, ) description = _form['pullrequest_desc'] + description_renderer = _form['description_renderer'] try: pull_request = PullRequestModel().create( @@ -906,6 +909,7 @@ class RepoPullRequestsView(RepoAppView, reviewers=reviewers, title=pullrequest_title, description=description, + description_renderer=description_renderer, reviewer_data=reviewer_rules, auth_user=self._rhodecode_user ) @@ -970,10 +974,14 @@ class RepoPullRequestsView(RepoAppView, def _edit_pull_request(self, pull_request): _ = self.request.translate + try: PullRequestModel().edit( - pull_request, self.request.POST.get('title'), - self.request.POST.get('description'), self._rhodecode_user) + pull_request, + self.request.POST.get('title'), + self.request.POST.get('description'), + self.request.POST.get('description_renderer'), + self._rhodecode_user) except ValueError: msg = _(u'Cannot update closed pull requests.') h.flash(msg, category='error') diff --git a/rhodecode/lib/dbmigrate/versions/087_version_4_13_0.py b/rhodecode/lib/dbmigrate/versions/087_version_4_13_0.py new file mode 100644 --- /dev/null +++ b/rhodecode/lib/dbmigrate/versions/087_version_4_13_0.py @@ -0,0 +1,40 @@ +import logging + +from sqlalchemy import * + +from rhodecode.model import meta +from rhodecode.lib.dbmigrate.versions import _reset_base, notify + +log = logging.getLogger(__name__) + + +def upgrade(migrate_engine): + """ + Upgrade operations go here. + Don't create your own engine; bind migrate_engine to your metadata + """ + _reset_base(migrate_engine) + from rhodecode.lib.dbmigrate.schema import db_4_11_0_0 as db + + pull_request_table = db.PullRequest.__table__ + pull_request_version_table = db.PullRequestVersion.__table__ + + renderer = Column('description_renderer', Unicode(64), nullable=True) + renderer.create(table=pull_request_table) + + renderer_ver = Column('description_renderer', Unicode(64), nullable=True) + renderer_ver.create(table=pull_request_version_table) + + # issue fixups + fixups(db, meta.Session) + + +def downgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + +def fixups(models, _SESSION): + pass + + diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -1814,7 +1814,11 @@ def render(source, renderer='rst', menti return relative_links(html_source, relative_urls) return html_source - if renderer == 'rst': + if renderer == 'plain': + return literal( + MarkupRenderer.plain(source, leading_newline=False)) + + elif renderer == 'rst': if repo_name: # process patterns on comments if we pass in repo name source, issues = process_patterns( @@ -1824,6 +1828,7 @@ def render(source, renderer='rst', menti '
%s
' % maybe_convert_relative_links( MarkupRenderer.rst(source, mentions=mentions))) + elif renderer == 'markdown': if repo_name: # process patterns on comments if we pass in repo name @@ -1835,6 +1840,7 @@ def render(source, renderer='rst', menti maybe_convert_relative_links( MarkupRenderer.markdown(source, flavored=True, mentions=mentions))) + elif renderer == 'jupyter': return literal( '
%s
' % diff --git a/rhodecode/lib/markup_renderer.py b/rhodecode/lib/markup_renderer.py --- a/rhodecode/lib/markup_renderer.py +++ b/rhodecode/lib/markup_renderer.py @@ -319,14 +319,18 @@ class MarkupRenderer(object): return cls.URL_PAT.sub(url_func, text) @classmethod - def plain(cls, source, universal_newline=True): + def plain(cls, source, universal_newline=True, leading_newline=True): source = safe_unicode(source) if universal_newline: newline = '\n' source = newline.join(source.splitlines()) - source = cls.urlify_text(source) - return '
' + source.replace("\n", '
') + rendered_source = cls.urlify_text(source) + source = '' + if leading_newline: + source += '
' + source += rendered_source.replace("\n", '
') + return source @classmethod def markdown(cls, source, safe=True, flavored=True, mentions=False, diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -3454,6 +3454,8 @@ class _PullRequestBase(BaseModel): description = Column( 'description', UnicodeText().with_variant(UnicodeText(10240), 'mysql'), nullable=True) + description_renderer = Column('description_renderer', Unicode(64), nullable=True) + # new/open/closed status of pull request (not approve/reject/etc) status = Column('status', Unicode(255), nullable=False, default=STATUS_NEW) created_on = Column( diff --git a/rhodecode/model/forms.py b/rhodecode/model/forms.py --- a/rhodecode/model/forms.py +++ b/rhodecode/model/forms.py @@ -606,6 +606,7 @@ def PullRequestForm(localizer, repo_id): review_members = formencode.ForEach(ReviewerForm()) pullrequest_title = v.UnicodeString(strip=True, required=True, min=3, max=255) pullrequest_desc = v.UnicodeString(strip=True, required=False) + description_renderer = v.UnicodeString(strip=True, required=False) return _PullRequestForm 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 @@ -444,6 +444,7 @@ class PullRequestModel(BaseModel): def create(self, created_by, source_repo, source_ref, target_repo, target_ref, revisions, reviewers, title, description=None, + description_renderer=None, reviewer_data=None, translator=None, auth_user=None): translator = translator or get_current_request().translate @@ -460,6 +461,7 @@ class PullRequestModel(BaseModel): pull_request.revisions = revisions pull_request.title = title pull_request.description = description + pull_request.description_renderer = description_renderer pull_request.author = created_by_user pull_request.reviewer_data = reviewer_data @@ -980,7 +982,7 @@ class PullRequestModel(BaseModel): renderer = RstTemplateRenderer() return renderer.render('pull_request_update.mako', **params) - def edit(self, pull_request, title, description, user): + def edit(self, pull_request, title, description, description_renderer, user): pull_request = self.__get_pull_request(pull_request) old_data = pull_request.get_api_data(with_merge_state=False) if pull_request.is_closed(): @@ -989,6 +991,7 @@ class PullRequestModel(BaseModel): pull_request.title = title pull_request.description = description pull_request.updated_on = datetime.datetime.now() + pull_request.description_renderer = description_renderer Session().add(pull_request) self._log_audit_action( 'repo.pull_request.edit', {'old_data': old_data}, diff --git a/rhodecode/public/js/src/rhodecode/pullrequests.js b/rhodecode/public/js/src/rhodecode/pullrequests.js --- a/rhodecode/public/js/src/rhodecode/pullrequests.js +++ b/rhodecode/public/js/src/rhodecode/pullrequests.js @@ -361,7 +361,7 @@ var updateCommits = function(repo_name, /** * PULL REQUEST edit info */ -var editPullRequest = function(repo_name, pull_request_id, title, description) { +var editPullRequest = function(repo_name, pull_request_id, title, description, renderer) { var url = pyroutes.url( 'pullrequest_update', {"repo_name": repo_name, "pull_request_id": pull_request_id}); @@ -369,6 +369,7 @@ var editPullRequest = function(repo_name var postData = { 'title': title, 'description': description, + 'description_renderer': renderer, 'edit_pull_request': true, 'csrf_token': CSRF_TOKEN }; diff --git a/rhodecode/templates/pullrequests/pullrequest.mako b/rhodecode/templates/pullrequests/pullrequest.mako --- a/rhodecode/templates/pullrequests/pullrequest.mako +++ b/rhodecode/templates/pullrequests/pullrequest.mako @@ -55,6 +55,7 @@
+ ${dt.markup_form('pullrequest_desc')}
diff --git a/rhodecode/templates/pullrequests/pullrequest_show.mako b/rhodecode/templates/pullrequests/pullrequest_show.mako --- a/rhodecode/templates/pullrequests/pullrequest_show.mako +++ b/rhodecode/templates/pullrequests/pullrequest_show.mako @@ -166,13 +166,14 @@
-
+
-
${h.render(c.pull_request.description, renderer=c.visual.default_renderer)}
+
${h.render(c.pull_request.description, renderer=c.renderer)}
@@ -795,9 +796,10 @@ $('#edit_pull_request').on('click', function(e){ var title = $('#pr-title-input').val(); var description = codeMirrorInstance.getValue(); + var renderer = $('#pr-renderer-input').val(); editPullRequest( "${c.repo_name}", "${c.pull_request.pull_request_id}", - title, description); + title, description, renderer); }); $('#update_pull_request').on('click', function(e){