##// END OF EJS Templates
pull-requests: make the renderer stored and saved for each pull requests....
marcink -
r2903:6d16d1cd default
parent child Browse files
Show More
@@ -0,0 +1,40 b''
1 import logging
2
3 from sqlalchemy import *
4
5 from rhodecode.model import meta
6 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
7
8 log = logging.getLogger(__name__)
9
10
11 def upgrade(migrate_engine):
12 """
13 Upgrade operations go here.
14 Don't create your own engine; bind migrate_engine to your metadata
15 """
16 _reset_base(migrate_engine)
17 from rhodecode.lib.dbmigrate.schema import db_4_11_0_0 as db
18
19 pull_request_table = db.PullRequest.__table__
20 pull_request_version_table = db.PullRequestVersion.__table__
21
22 renderer = Column('description_renderer', Unicode(64), nullable=True)
23 renderer.create(table=pull_request_table)
24
25 renderer_ver = Column('description_renderer', Unicode(64), nullable=True)
26 renderer_ver.create(table=pull_request_version_table)
27
28 # issue fixups
29 fixups(db, meta.Session)
30
31
32 def downgrade(migrate_engine):
33 meta = MetaData()
34 meta.bind = migrate_engine
35
36
37 def fixups(models, _SESSION):
38 pass
39
40
@@ -51,7 +51,7 b' PYRAMID_SETTINGS = {}'
51 EXTENSIONS = {}
51 EXTENSIONS = {}
52
52
53 __version__ = ('.'.join((str(each) for each in VERSION[:3])))
53 __version__ = ('.'.join((str(each) for each in VERSION[:3])))
54 __dbversion__ = 86 # defines current db version for migrations
54 __dbversion__ = 87 # defines current db version for migrations
55 __platform__ = platform.system()
55 __platform__ = platform.system()
56 __license__ = 'AGPLv3, and Commercial License'
56 __license__ = 'AGPLv3, and Commercial License'
57 __author__ = 'RhodeCode GmbH'
57 __author__ = 'RhodeCode GmbH'
@@ -368,8 +368,9 b' class TestPullrequestsView(object):'
368 ('target_repo', target.repo_name),
368 ('target_repo', target.repo_name),
369 ('target_ref', 'branch:default:' + commit_ids['ancestor']),
369 ('target_ref', 'branch:default:' + commit_ids['ancestor']),
370 ('common_ancestor', commit_ids['ancestor']),
370 ('common_ancestor', commit_ids['ancestor']),
371 ('pullrequest_title', 'Title'),
371 ('pullrequest_desc', 'Description'),
372 ('pullrequest_desc', 'Description'),
372 ('pullrequest_title', 'Title'),
373 ('description_renderer', 'markdown'),
373 ('__start__', 'review_members:sequence'),
374 ('__start__', 'review_members:sequence'),
374 ('__start__', 'reviewer:mapping'),
375 ('__start__', 'reviewer:mapping'),
375 ('user_id', '1'),
376 ('user_id', '1'),
@@ -427,8 +428,9 b' class TestPullrequestsView(object):'
427 ('target_repo', target.repo_name),
428 ('target_repo', target.repo_name),
428 ('target_ref', 'branch:default:' + commit_ids['ancestor-child']),
429 ('target_ref', 'branch:default:' + commit_ids['ancestor-child']),
429 ('common_ancestor', commit_ids['ancestor']),
430 ('common_ancestor', commit_ids['ancestor']),
431 ('pullrequest_title', 'Title'),
430 ('pullrequest_desc', 'Description'),
432 ('pullrequest_desc', 'Description'),
431 ('pullrequest_title', 'Title'),
433 ('description_renderer', 'markdown'),
432 ('__start__', 'review_members:sequence'),
434 ('__start__', 'review_members:sequence'),
433 ('__start__', 'reviewer:mapping'),
435 ('__start__', 'reviewer:mapping'),
434 ('user_id', '2'),
436 ('user_id', '2'),
@@ -493,8 +495,9 b' class TestPullrequestsView(object):'
493 ('target_repo', target.repo_name),
495 ('target_repo', target.repo_name),
494 ('target_ref', 'branch:default:' + commit_ids['ancestor-child']),
496 ('target_ref', 'branch:default:' + commit_ids['ancestor-child']),
495 ('common_ancestor', commit_ids['ancestor']),
497 ('common_ancestor', commit_ids['ancestor']),
498 ('pullrequest_title', 'Title'),
496 ('pullrequest_desc', 'Description'),
499 ('pullrequest_desc', 'Description'),
497 ('pullrequest_title', 'Title'),
500 ('description_renderer', 'markdown'),
498 ('__start__', 'review_members:sequence'),
501 ('__start__', 'review_members:sequence'),
499 ('__start__', 'reviewer:mapping'),
502 ('__start__', 'reviewer:mapping'),
500 ('user_id', '1'),
503 ('user_id', '1'),
@@ -61,7 +61,8 b' class RepoPullRequestsView(RepoAppView, '
61 c = self._get_local_tmpl_context(include_app_defaults=True)
61 c = self._get_local_tmpl_context(include_app_defaults=True)
62 c.REVIEW_STATUS_APPROVED = ChangesetStatus.STATUS_APPROVED
62 c.REVIEW_STATUS_APPROVED = ChangesetStatus.STATUS_APPROVED
63 c.REVIEW_STATUS_REJECTED = ChangesetStatus.STATUS_REJECTED
63 c.REVIEW_STATUS_REJECTED = ChangesetStatus.STATUS_REJECTED
64
64 # backward compat., we use for OLD PRs a plain renderer
65 c.renderer = 'plain'
65 return c
66 return c
66
67
67 def _get_pull_requests_list(
68 def _get_pull_requests_list(
@@ -297,6 +298,7 b' class RepoPullRequestsView(RepoAppView, '
297 pull_request_at_ver)
298 pull_request_at_ver)
298
299
299 c.pull_request = pull_request_display_obj
300 c.pull_request = pull_request_display_obj
301 c.renderer = pull_request_at_ver.description_renderer or c.renderer
300 c.pull_request_latest = pull_request_latest
302 c.pull_request_latest = pull_request_latest
301
303
302 if compare or (at_version and not at_version == 'latest'):
304 if compare or (at_version and not at_version == 'latest'):
@@ -894,6 +896,7 b' class RepoPullRequestsView(RepoAppView, '
894 )
896 )
895
897
896 description = _form['pullrequest_desc']
898 description = _form['pullrequest_desc']
899 description_renderer = _form['description_renderer']
897
900
898 try:
901 try:
899 pull_request = PullRequestModel().create(
902 pull_request = PullRequestModel().create(
@@ -906,6 +909,7 b' class RepoPullRequestsView(RepoAppView, '
906 reviewers=reviewers,
909 reviewers=reviewers,
907 title=pullrequest_title,
910 title=pullrequest_title,
908 description=description,
911 description=description,
912 description_renderer=description_renderer,
909 reviewer_data=reviewer_rules,
913 reviewer_data=reviewer_rules,
910 auth_user=self._rhodecode_user
914 auth_user=self._rhodecode_user
911 )
915 )
@@ -970,10 +974,14 b' class RepoPullRequestsView(RepoAppView, '
970
974
971 def _edit_pull_request(self, pull_request):
975 def _edit_pull_request(self, pull_request):
972 _ = self.request.translate
976 _ = self.request.translate
977
973 try:
978 try:
974 PullRequestModel().edit(
979 PullRequestModel().edit(
975 pull_request, self.request.POST.get('title'),
980 pull_request,
976 self.request.POST.get('description'), self._rhodecode_user)
981 self.request.POST.get('title'),
982 self.request.POST.get('description'),
983 self.request.POST.get('description_renderer'),
984 self._rhodecode_user)
977 except ValueError:
985 except ValueError:
978 msg = _(u'Cannot update closed pull requests.')
986 msg = _(u'Cannot update closed pull requests.')
979 h.flash(msg, category='error')
987 h.flash(msg, category='error')
@@ -1814,7 +1814,11 b" def render(source, renderer='rst', menti"
1814 return relative_links(html_source, relative_urls)
1814 return relative_links(html_source, relative_urls)
1815 return html_source
1815 return html_source
1816
1816
1817 if renderer == 'rst':
1817 if renderer == 'plain':
1818 return literal(
1819 MarkupRenderer.plain(source, leading_newline=False))
1820
1821 elif renderer == 'rst':
1818 if repo_name:
1822 if repo_name:
1819 # process patterns on comments if we pass in repo name
1823 # process patterns on comments if we pass in repo name
1820 source, issues = process_patterns(
1824 source, issues = process_patterns(
@@ -1824,6 +1828,7 b" def render(source, renderer='rst', menti"
1824 '<div class="rst-block">%s</div>' %
1828 '<div class="rst-block">%s</div>' %
1825 maybe_convert_relative_links(
1829 maybe_convert_relative_links(
1826 MarkupRenderer.rst(source, mentions=mentions)))
1830 MarkupRenderer.rst(source, mentions=mentions)))
1831
1827 elif renderer == 'markdown':
1832 elif renderer == 'markdown':
1828 if repo_name:
1833 if repo_name:
1829 # process patterns on comments if we pass in repo name
1834 # process patterns on comments if we pass in repo name
@@ -1835,6 +1840,7 b" def render(source, renderer='rst', menti"
1835 maybe_convert_relative_links(
1840 maybe_convert_relative_links(
1836 MarkupRenderer.markdown(source, flavored=True,
1841 MarkupRenderer.markdown(source, flavored=True,
1837 mentions=mentions)))
1842 mentions=mentions)))
1843
1838 elif renderer == 'jupyter':
1844 elif renderer == 'jupyter':
1839 return literal(
1845 return literal(
1840 '<div class="ipynb">%s</div>' %
1846 '<div class="ipynb">%s</div>' %
@@ -319,14 +319,18 b' class MarkupRenderer(object):'
319 return cls.URL_PAT.sub(url_func, text)
319 return cls.URL_PAT.sub(url_func, text)
320
320
321 @classmethod
321 @classmethod
322 def plain(cls, source, universal_newline=True):
322 def plain(cls, source, universal_newline=True, leading_newline=True):
323 source = safe_unicode(source)
323 source = safe_unicode(source)
324 if universal_newline:
324 if universal_newline:
325 newline = '\n'
325 newline = '\n'
326 source = newline.join(source.splitlines())
326 source = newline.join(source.splitlines())
327
327
328 source = cls.urlify_text(source)
328 rendered_source = cls.urlify_text(source)
329 return '<br />' + source.replace("\n", '<br />')
329 source = ''
330 if leading_newline:
331 source += '<br />'
332 source += rendered_source.replace("\n", '<br />')
333 return source
330
334
331 @classmethod
335 @classmethod
332 def markdown(cls, source, safe=True, flavored=True, mentions=False,
336 def markdown(cls, source, safe=True, flavored=True, mentions=False,
@@ -3454,6 +3454,8 b' class _PullRequestBase(BaseModel):'
3454 description = Column(
3454 description = Column(
3455 'description', UnicodeText().with_variant(UnicodeText(10240), 'mysql'),
3455 'description', UnicodeText().with_variant(UnicodeText(10240), 'mysql'),
3456 nullable=True)
3456 nullable=True)
3457 description_renderer = Column('description_renderer', Unicode(64), nullable=True)
3458
3457 # new/open/closed status of pull request (not approve/reject/etc)
3459 # new/open/closed status of pull request (not approve/reject/etc)
3458 status = Column('status', Unicode(255), nullable=False, default=STATUS_NEW)
3460 status = Column('status', Unicode(255), nullable=False, default=STATUS_NEW)
3459 created_on = Column(
3461 created_on = Column(
@@ -606,6 +606,7 b' def PullRequestForm(localizer, repo_id):'
606 review_members = formencode.ForEach(ReviewerForm())
606 review_members = formencode.ForEach(ReviewerForm())
607 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3, max=255)
607 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3, max=255)
608 pullrequest_desc = v.UnicodeString(strip=True, required=False)
608 pullrequest_desc = v.UnicodeString(strip=True, required=False)
609 description_renderer = v.UnicodeString(strip=True, required=False)
609
610
610 return _PullRequestForm
611 return _PullRequestForm
611
612
@@ -444,6 +444,7 b' class PullRequestModel(BaseModel):'
444
444
445 def create(self, created_by, source_repo, source_ref, target_repo,
445 def create(self, created_by, source_repo, source_ref, target_repo,
446 target_ref, revisions, reviewers, title, description=None,
446 target_ref, revisions, reviewers, title, description=None,
447 description_renderer=None,
447 reviewer_data=None, translator=None, auth_user=None):
448 reviewer_data=None, translator=None, auth_user=None):
448 translator = translator or get_current_request().translate
449 translator = translator or get_current_request().translate
449
450
@@ -460,6 +461,7 b' class PullRequestModel(BaseModel):'
460 pull_request.revisions = revisions
461 pull_request.revisions = revisions
461 pull_request.title = title
462 pull_request.title = title
462 pull_request.description = description
463 pull_request.description = description
464 pull_request.description_renderer = description_renderer
463 pull_request.author = created_by_user
465 pull_request.author = created_by_user
464 pull_request.reviewer_data = reviewer_data
466 pull_request.reviewer_data = reviewer_data
465
467
@@ -980,7 +982,7 b' class PullRequestModel(BaseModel):'
980 renderer = RstTemplateRenderer()
982 renderer = RstTemplateRenderer()
981 return renderer.render('pull_request_update.mako', **params)
983 return renderer.render('pull_request_update.mako', **params)
982
984
983 def edit(self, pull_request, title, description, user):
985 def edit(self, pull_request, title, description, description_renderer, user):
984 pull_request = self.__get_pull_request(pull_request)
986 pull_request = self.__get_pull_request(pull_request)
985 old_data = pull_request.get_api_data(with_merge_state=False)
987 old_data = pull_request.get_api_data(with_merge_state=False)
986 if pull_request.is_closed():
988 if pull_request.is_closed():
@@ -989,6 +991,7 b' class PullRequestModel(BaseModel):'
989 pull_request.title = title
991 pull_request.title = title
990 pull_request.description = description
992 pull_request.description = description
991 pull_request.updated_on = datetime.datetime.now()
993 pull_request.updated_on = datetime.datetime.now()
994 pull_request.description_renderer = description_renderer
992 Session().add(pull_request)
995 Session().add(pull_request)
993 self._log_audit_action(
996 self._log_audit_action(
994 'repo.pull_request.edit', {'old_data': old_data},
997 'repo.pull_request.edit', {'old_data': old_data},
@@ -361,7 +361,7 b' var updateCommits = function(repo_name, '
361 /**
361 /**
362 * PULL REQUEST edit info
362 * PULL REQUEST edit info
363 */
363 */
364 var editPullRequest = function(repo_name, pull_request_id, title, description) {
364 var editPullRequest = function(repo_name, pull_request_id, title, description, renderer) {
365 var url = pyroutes.url(
365 var url = pyroutes.url(
366 'pullrequest_update',
366 'pullrequest_update',
367 {"repo_name": repo_name, "pull_request_id": pull_request_id});
367 {"repo_name": repo_name, "pull_request_id": pull_request_id});
@@ -369,6 +369,7 b' var editPullRequest = function(repo_name'
369 var postData = {
369 var postData = {
370 'title': title,
370 'title': title,
371 'description': description,
371 'description': description,
372 'description_renderer': renderer,
372 'edit_pull_request': true,
373 'edit_pull_request': true,
373 'csrf_token': CSRF_TOKEN
374 'csrf_token': CSRF_TOKEN
374 };
375 };
@@ -55,6 +55,7 b''
55 <label for="pullrequest_desc">${_('Description')}:</label>
55 <label for="pullrequest_desc">${_('Description')}:</label>
56 </div>
56 </div>
57 <div class="textarea text-area editor">
57 <div class="textarea text-area editor">
58 <input id="pr-renderer-input" type="hidden" name="description_renderer" value="${c.visual.default_renderer}">
58 ${dt.markup_form('pullrequest_desc')}
59 ${dt.markup_form('pullrequest_desc')}
59 </div>
60 </div>
60 </div>
61 </div>
@@ -166,13 +166,14 b''
166 </div>
166 </div>
167 </div>
167 </div>
168 <div class="field">
168 <div class="field">
169 <div class="pr-description-label label-summary">
169 <div class="pr-description-label label-summary" title="${_('Rendered using {} renderer').format(c.renderer)}">
170 <label>${_('Description')}:</label>
170 <label>${_('Description')}:</label>
171 </div>
171 </div>
172 <div id="pr-desc" class="input">
172 <div id="pr-desc" class="input">
173 <div class="pr-description">${h.render(c.pull_request.description, renderer=c.visual.default_renderer)}</div>
173 <div class="pr-description">${h.render(c.pull_request.description, renderer=c.renderer)}</div>
174 </div>
174 </div>
175 <div id="pr-desc-edit" class="input textarea editor" style="display: none;">
175 <div id="pr-desc-edit" class="input textarea editor" style="display: none;">
176 <input id="pr-renderer-input" type="hidden" name="description_renderer" value="${c.visual.default_renderer}">
176 ${dt.markup_form('pr-description-input', form_text=c.pull_request.description)}
177 ${dt.markup_form('pr-description-input', form_text=c.pull_request.description)}
177 </div>
178 </div>
178 </div>
179 </div>
@@ -795,9 +796,10 b''
795 $('#edit_pull_request').on('click', function(e){
796 $('#edit_pull_request').on('click', function(e){
796 var title = $('#pr-title-input').val();
797 var title = $('#pr-title-input').val();
797 var description = codeMirrorInstance.getValue();
798 var description = codeMirrorInstance.getValue();
799 var renderer = $('#pr-renderer-input').val();
798 editPullRequest(
800 editPullRequest(
799 "${c.repo_name}", "${c.pull_request.pull_request_id}",
801 "${c.repo_name}", "${c.pull_request.pull_request_id}",
800 title, description);
802 title, description, renderer);
801 });
803 });
802
804
803 $('#update_pull_request').on('click', function(e){
805 $('#update_pull_request').on('click', function(e){
General Comments 0
You need to be logged in to leave comments. Login now