##// 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 51 EXTENSIONS = {}
52 52
53 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 55 __platform__ = platform.system()
56 56 __license__ = 'AGPLv3, and Commercial License'
57 57 __author__ = 'RhodeCode GmbH'
@@ -368,8 +368,9 b' class TestPullrequestsView(object):'
368 368 ('target_repo', target.repo_name),
369 369 ('target_ref', 'branch:default:' + commit_ids['ancestor']),
370 370 ('common_ancestor', commit_ids['ancestor']),
371 ('pullrequest_title', 'Title'),
371 372 ('pullrequest_desc', 'Description'),
372 ('pullrequest_title', 'Title'),
373 ('description_renderer', 'markdown'),
373 374 ('__start__', 'review_members:sequence'),
374 375 ('__start__', 'reviewer:mapping'),
375 376 ('user_id', '1'),
@@ -427,8 +428,9 b' class TestPullrequestsView(object):'
427 428 ('target_repo', target.repo_name),
428 429 ('target_ref', 'branch:default:' + commit_ids['ancestor-child']),
429 430 ('common_ancestor', commit_ids['ancestor']),
431 ('pullrequest_title', 'Title'),
430 432 ('pullrequest_desc', 'Description'),
431 ('pullrequest_title', 'Title'),
433 ('description_renderer', 'markdown'),
432 434 ('__start__', 'review_members:sequence'),
433 435 ('__start__', 'reviewer:mapping'),
434 436 ('user_id', '2'),
@@ -493,8 +495,9 b' class TestPullrequestsView(object):'
493 495 ('target_repo', target.repo_name),
494 496 ('target_ref', 'branch:default:' + commit_ids['ancestor-child']),
495 497 ('common_ancestor', commit_ids['ancestor']),
498 ('pullrequest_title', 'Title'),
496 499 ('pullrequest_desc', 'Description'),
497 ('pullrequest_title', 'Title'),
500 ('description_renderer', 'markdown'),
498 501 ('__start__', 'review_members:sequence'),
499 502 ('__start__', 'reviewer:mapping'),
500 503 ('user_id', '1'),
@@ -61,7 +61,8 b' class RepoPullRequestsView(RepoAppView, '
61 61 c = self._get_local_tmpl_context(include_app_defaults=True)
62 62 c.REVIEW_STATUS_APPROVED = ChangesetStatus.STATUS_APPROVED
63 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 66 return c
66 67
67 68 def _get_pull_requests_list(
@@ -297,6 +298,7 b' class RepoPullRequestsView(RepoAppView, '
297 298 pull_request_at_ver)
298 299
299 300 c.pull_request = pull_request_display_obj
301 c.renderer = pull_request_at_ver.description_renderer or c.renderer
300 302 c.pull_request_latest = pull_request_latest
301 303
302 304 if compare or (at_version and not at_version == 'latest'):
@@ -894,6 +896,7 b' class RepoPullRequestsView(RepoAppView, '
894 896 )
895 897
896 898 description = _form['pullrequest_desc']
899 description_renderer = _form['description_renderer']
897 900
898 901 try:
899 902 pull_request = PullRequestModel().create(
@@ -906,6 +909,7 b' class RepoPullRequestsView(RepoAppView, '
906 909 reviewers=reviewers,
907 910 title=pullrequest_title,
908 911 description=description,
912 description_renderer=description_renderer,
909 913 reviewer_data=reviewer_rules,
910 914 auth_user=self._rhodecode_user
911 915 )
@@ -970,10 +974,14 b' class RepoPullRequestsView(RepoAppView, '
970 974
971 975 def _edit_pull_request(self, pull_request):
972 976 _ = self.request.translate
977
973 978 try:
974 979 PullRequestModel().edit(
975 pull_request, self.request.POST.get('title'),
976 self.request.POST.get('description'), self._rhodecode_user)
980 pull_request,
981 self.request.POST.get('title'),
982 self.request.POST.get('description'),
983 self.request.POST.get('description_renderer'),
984 self._rhodecode_user)
977 985 except ValueError:
978 986 msg = _(u'Cannot update closed pull requests.')
979 987 h.flash(msg, category='error')
@@ -1814,7 +1814,11 b" def render(source, renderer='rst', menti"
1814 1814 return relative_links(html_source, relative_urls)
1815 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 1822 if repo_name:
1819 1823 # process patterns on comments if we pass in repo name
1820 1824 source, issues = process_patterns(
@@ -1824,6 +1828,7 b" def render(source, renderer='rst', menti"
1824 1828 '<div class="rst-block">%s</div>' %
1825 1829 maybe_convert_relative_links(
1826 1830 MarkupRenderer.rst(source, mentions=mentions)))
1831
1827 1832 elif renderer == 'markdown':
1828 1833 if repo_name:
1829 1834 # process patterns on comments if we pass in repo name
@@ -1835,6 +1840,7 b" def render(source, renderer='rst', menti"
1835 1840 maybe_convert_relative_links(
1836 1841 MarkupRenderer.markdown(source, flavored=True,
1837 1842 mentions=mentions)))
1843
1838 1844 elif renderer == 'jupyter':
1839 1845 return literal(
1840 1846 '<div class="ipynb">%s</div>' %
@@ -319,14 +319,18 b' class MarkupRenderer(object):'
319 319 return cls.URL_PAT.sub(url_func, text)
320 320
321 321 @classmethod
322 def plain(cls, source, universal_newline=True):
322 def plain(cls, source, universal_newline=True, leading_newline=True):
323 323 source = safe_unicode(source)
324 324 if universal_newline:
325 325 newline = '\n'
326 326 source = newline.join(source.splitlines())
327 327
328 source = cls.urlify_text(source)
329 return '<br />' + source.replace("\n", '<br />')
328 rendered_source = cls.urlify_text(source)
329 source = ''
330 if leading_newline:
331 source += '<br />'
332 source += rendered_source.replace("\n", '<br />')
333 return source
330 334
331 335 @classmethod
332 336 def markdown(cls, source, safe=True, flavored=True, mentions=False,
@@ -3454,6 +3454,8 b' class _PullRequestBase(BaseModel):'
3454 3454 description = Column(
3455 3455 'description', UnicodeText().with_variant(UnicodeText(10240), 'mysql'),
3456 3456 nullable=True)
3457 description_renderer = Column('description_renderer', Unicode(64), nullable=True)
3458
3457 3459 # new/open/closed status of pull request (not approve/reject/etc)
3458 3460 status = Column('status', Unicode(255), nullable=False, default=STATUS_NEW)
3459 3461 created_on = Column(
@@ -606,6 +606,7 b' def PullRequestForm(localizer, repo_id):'
606 606 review_members = formencode.ForEach(ReviewerForm())
607 607 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3, max=255)
608 608 pullrequest_desc = v.UnicodeString(strip=True, required=False)
609 description_renderer = v.UnicodeString(strip=True, required=False)
609 610
610 611 return _PullRequestForm
611 612
@@ -444,6 +444,7 b' class PullRequestModel(BaseModel):'
444 444
445 445 def create(self, created_by, source_repo, source_ref, target_repo,
446 446 target_ref, revisions, reviewers, title, description=None,
447 description_renderer=None,
447 448 reviewer_data=None, translator=None, auth_user=None):
448 449 translator = translator or get_current_request().translate
449 450
@@ -460,6 +461,7 b' class PullRequestModel(BaseModel):'
460 461 pull_request.revisions = revisions
461 462 pull_request.title = title
462 463 pull_request.description = description
464 pull_request.description_renderer = description_renderer
463 465 pull_request.author = created_by_user
464 466 pull_request.reviewer_data = reviewer_data
465 467
@@ -980,7 +982,7 b' class PullRequestModel(BaseModel):'
980 982 renderer = RstTemplateRenderer()
981 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 986 pull_request = self.__get_pull_request(pull_request)
985 987 old_data = pull_request.get_api_data(with_merge_state=False)
986 988 if pull_request.is_closed():
@@ -989,6 +991,7 b' class PullRequestModel(BaseModel):'
989 991 pull_request.title = title
990 992 pull_request.description = description
991 993 pull_request.updated_on = datetime.datetime.now()
994 pull_request.description_renderer = description_renderer
992 995 Session().add(pull_request)
993 996 self._log_audit_action(
994 997 'repo.pull_request.edit', {'old_data': old_data},
@@ -361,7 +361,7 b' var updateCommits = function(repo_name, '
361 361 /**
362 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 365 var url = pyroutes.url(
366 366 'pullrequest_update',
367 367 {"repo_name": repo_name, "pull_request_id": pull_request_id});
@@ -369,6 +369,7 b' var editPullRequest = function(repo_name'
369 369 var postData = {
370 370 'title': title,
371 371 'description': description,
372 'description_renderer': renderer,
372 373 'edit_pull_request': true,
373 374 'csrf_token': CSRF_TOKEN
374 375 };
@@ -55,6 +55,7 b''
55 55 <label for="pullrequest_desc">${_('Description')}:</label>
56 56 </div>
57 57 <div class="textarea text-area editor">
58 <input id="pr-renderer-input" type="hidden" name="description_renderer" value="${c.visual.default_renderer}">
58 59 ${dt.markup_form('pullrequest_desc')}
59 60 </div>
60 61 </div>
@@ -166,13 +166,14 b''
166 166 </div>
167 167 </div>
168 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 170 <label>${_('Description')}:</label>
171 171 </div>
172 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 174 </div>
175 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 177 ${dt.markup_form('pr-description-input', form_text=c.pull_request.description)}
177 178 </div>
178 179 </div>
@@ -795,9 +796,10 b''
795 796 $('#edit_pull_request').on('click', function(e){
796 797 var title = $('#pr-title-input').val();
797 798 var description = codeMirrorInstance.getValue();
799 var renderer = $('#pr-renderer-input').val();
798 800 editPullRequest(
799 801 "${c.repo_name}", "${c.pull_request.pull_request_id}",
800 title, description);
802 title, description, renderer);
801 803 });
802 804
803 805 $('#update_pull_request').on('click', function(e){
General Comments 0
You need to be logged in to leave comments. Login now