##// END OF EJS Templates
hovercards: enable hovercards on parsed commits references.
dan -
r4047:4a632ba4 default
parent child Browse files
Show More
@@ -539,12 +539,24 b' def add_events_routes(config):'
539 539 pattern='/{repo_name}/pull-request/{pull_request_id}')
540 540 config.add_route(name='pull_requests_global',
541 541 pattern='/pull-request/{pull_request_id}')
542
542 543 config.add_route(name='repo_commit',
543 544 pattern='/{repo_name}/changeset/{commit_id}')
544
545 545 config.add_route(name='repo_files',
546 546 pattern='/{repo_name}/files/{commit_id}/{f_path}')
547 547
548 config.add_route(name='hovercard_user',
549 pattern='/_hovercard/user/{user_id}')
550
551 config.add_route(name='hovercard_user_group',
552 pattern='/_hovercard/user_group/{user_group_id}')
553
554 config.add_route(name='hovercard_pull_request',
555 pattern='/_hovercard/pull_request/{pull_request_id}')
556
557 config.add_route(name='hovercard_repo_commit',
558 pattern='/_hovercard/commit/{repo_name}/{commit_id}')
559
548 560
549 561 def bootstrap_config(request):
550 562 import pyramid.testing
@@ -1577,21 +1577,21 b' def urlify_text(text_, safe=True):'
1577 1577 def url_func(match_obj):
1578 1578 url_full = match_obj.groups()[0]
1579 1579 return '<a href="%(url)s">%(url)s</a>' % ({'url': url_full})
1580 _newtext = url_pat.sub(url_func, text_)
1580 _new_text = url_pat.sub(url_func, text_)
1581 1581 if safe:
1582 return literal(_newtext)
1583 return _newtext
1582 return literal(_new_text)
1583 return _new_text
1584 1584
1585 1585
1586 def urlify_commits(text_, repository):
1586 def urlify_commits(text_, repo_name):
1587 1587 """
1588 1588 Extract commit ids from text and make link from them
1589 1589
1590 1590 :param text_:
1591 :param repository: repo name to build the URL with
1591 :param repo_name: repo name to build the URL with
1592 1592 """
1593 1593
1594 URL_PAT = re.compile(r'(^|\s)([0-9a-fA-F]{12,40})($|\s)')
1594 url_pat = re.compile(r'(^|\s)([0-9a-fA-F]{12,40})($|\s)')
1595 1595
1596 1596 def url_func(match_obj):
1597 1597 commit_id = match_obj.groups()[1]
@@ -1599,20 +1599,24 b' def urlify_commits(text_, repository):'
1599 1599 suf = match_obj.groups()[2]
1600 1600
1601 1601 tmpl = (
1602 '%(pref)s<a class="%(cls)s" href="%(url)s">'
1602 '%(pref)s<a class="tooltip-hovercard %(cls)s" href="%(url)s" data-hovercard-alt="%(hovercard_alt)s" data-hovercard-url="%(hovercard_url)s">'
1603 1603 '%(commit_id)s</a>%(suf)s'
1604 1604 )
1605 1605 return tmpl % {
1606 1606 'pref': pref,
1607 1607 'cls': 'revision-link',
1608 'url': route_url('repo_commit', repo_name=repository, commit_id=commit_id),
1608 'url': route_url(
1609 'repo_commit', repo_name=repo_name, commit_id=commit_id),
1609 1610 'commit_id': commit_id,
1610 'suf': suf
1611 'suf': suf,
1612 'hovercard_alt': 'Commit: {}'.format(commit_id),
1613 'hovercard_url': route_url(
1614 'hovercard_repo_commit', repo_name=repo_name, commit_id=commit_id)
1611 1615 }
1612 1616
1613 newtext = URL_PAT.sub(url_func, text_)
1617 new_text = url_pat.sub(url_func, text_)
1614 1618
1615 return newtext
1619 return new_text
1616 1620
1617 1621
1618 1622 def _process_url_func(match_obj, repo_name, uid, entry,
@@ -1767,9 +1771,6 b' def urlify_commit_message(commit_text, r'
1767 1771 """
1768 1772 Parses given text message and makes proper links.
1769 1773 issues are linked to given issue-server, and rest is a commit link
1770
1771 :param commit_text:
1772 :param repository:
1773 1774 """
1774 1775 def escaper(_text):
1775 1776 return _text.replace('<', '&lt;').replace('>', '&gt;')
@@ -243,7 +243,7 b' var tooltipActivate = function () {'
243 243 });
244 244 var hovercardCache = {};
245 245
246 var loadHoverCard = function (url, callback) {
246 var loadHoverCard = function (url, altHovercard, callback) {
247 247 var id = url;
248 248
249 249 if (hovercardCache[id] !== undefined) {
@@ -257,7 +257,12 b' var tooltipActivate = function () {'
257 257 callback(hovercardCache[id]);
258 258 return true;
259 259 }).fail(function (data, textStatus, errorThrown) {
260 var msg = "<p class='error-message'>Error while fetching hovercard.\nError code {0} ({1}).</p>".format(data.status,data.statusText);
260
261 if (parseInt(data.status) === 404) {
262 var msg = "<p>{0}</p>".format(altHovercard || "No Data exists for this hovercard");
263 } else {
264 var msg = "<p class='error-message'>Error while fetching hovercard.\nError code {0} ({1}).</p>".format(data.status,data.statusText);
265 }
261 266 callback(msg);
262 267 return false
263 268 });
@@ -291,16 +296,17 b' var tooltipActivate = function () {'
291 296 // we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens
292 297 if ($origin.data('loaded') !== true) {
293 298 var hovercardUrl = $origin.data('hovercardUrl');
299 var altHovercard =$origin.data('hovercardAlt');
294 300
295 301 if (hovercardUrl !== undefined && hovercardUrl !== "") {
296 var loaded = loadHoverCard(hovercardUrl, function (data) {
302 var loaded = loadHoverCard(hovercardUrl, altHovercard, function (data) {
297 303 instance.content(data);
298 304 })
299 305 } else {
300 306 if ($origin.data('hovercardAltHtml')) {
301 307 var data = atob($origin.data('hovercardAltHtml'));
302 308 } else {
303 var data = '<div style="white-space: pre-wrap">{0}</div>'.format($origin.data('hovercardAlt'))
309 var data = '<div style="white-space: pre-wrap">{0}</div>'.format(altHovercard)
304 310 }
305 311 var loaded = true;
306 312 instance.content(data);
@@ -178,11 +178,13 b''
178 178 <div class="fields">
179 179 <div class="field">
180 180 <div class='textarea-full'>
181 <textarea id="test_pattern_data" >
181 <textarea id="test_pattern_data" rows="10">
182 This is an example text for testing issue tracker patterns.
182 183 This commit fixes ticket #451.
183 This is an example text for testing issue tracker patterns, add a pattern here and
184 hit preview to see the link.
185 184 Open a pull request !101 to contribute !
185 Added tag v1.3.0 for commit 0f3b629be725
186
187 Add a test pattern here and hit preview to see the link.
186 188 </textarea>
187 189 </div>
188 190 </div>
@@ -454,7 +454,10 b' def test_clone_url_generator(tmpl, repo_'
454 454 assert clone_url == expected
455 455
456 456
457 def _quick_url(text, tmpl="""<a class="revision-link" href="%s">%s</a>""", url_=None):
457 idx = 0
458
459
460 def _quick_url(text, tmpl="""<a class="tooltip-hovercard revision-link" href="%s" data-hovercard-alt="Commit: %s" data-hovercard-url="/some-url">%s</a>""", url_=None, commits=''):
458 461 """
459 462 Changes `some text url[foo]` => `some text <a href="/">foo</a>
460 463
@@ -462,47 +465,86 b' def _quick_url(text, tmpl="""<a class="r'
462 465 """
463 466 import re
464 467 # quickly change expected url[] into a link
465 URL_PAT = re.compile(r'(?:url\[)(.+?)(?:\])')
468 url_pat = re.compile(r'(?:url\[)(.+?)(?:\])')
469 commits = commits or []
470
471 global idx
472 idx = 0
466 473
467 474 def url_func(match_obj):
475 global idx
468 476 _url = match_obj.groups()[0]
469 return tmpl % (url_ or '/some-url', _url)
470 return URL_PAT.sub(url_func, text)
477 if commits:
478 commit = commits[idx]
479 idx += 1
480 return tmpl % (url_ or '/some-url', _url, commit)
481 else:
482 return tmpl % (url_ or '/some-url', _url)
483
484 return url_pat.sub(url_func, text)
471 485
472 486
473 @pytest.mark.parametrize("sample, expected", [
474 ("",
475 ""),
476 ("git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68",
477 "git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68"),
478 ("from rev 000000000000",
479 "from rev url[000000000000]"),
480 ("from rev 000000000000123123 also rev 000000000000",
481 "from rev url[000000000000123123] also rev url[000000000000]"),
482 ("this should-000 00",
483 "this should-000 00"),
484 ("longtextffffffffff rev 123123123123",
485 "longtextffffffffff rev url[123123123123]"),
486 ("rev ffffffffffffffffffffffffffffffffffffffffffffffffff",
487 "rev ffffffffffffffffffffffffffffffffffffffffffffffffff"),
488 ("ffffffffffff some text traalaa",
489 "url[ffffffffffff] some text traalaa"),
490 ("""Multi line
491 123123123123
492 some text 123123123123
493 sometimes !
494 """,
495 """Multi line
496 url[123123123123]
497 some text url[123123123123]
498 sometimes !
499 """)
487 @pytest.mark.parametrize("sample, expected, commits", [
488 (
489 "",
490 "",
491 [""]
492 ),
493 (
494 "git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68",
495 "git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68",
496 [""]
497 ),
498 (
499 "from rev 000000000000",
500 "from rev url[000000000000]",
501 ["000000000000"]
502 ),
503
504 (
505 "from rev 000000000000123123 also rev 000000000000",
506 "from rev url[000000000000123123] also rev url[000000000000]",
507 ["000000000000123123", "000000000000"]
508 ),
509 (
510 "this should-000 00",
511 "this should-000 00",
512 [""]
513 ),
514 (
515 "longtextffffffffff rev 123123123123",
516 "longtextffffffffff rev url[123123123123]",
517 ["123123123123"]
518 ),
519 (
520 "rev ffffffffffffffffffffffffffffffffffffffffffffffffff",
521 "rev ffffffffffffffffffffffffffffffffffffffffffffffffff",
522 ["ffffffffffffffffffffffffffffffffffffffffffffffffff"]
523 ),
524 (
525 "ffffffffffff some text traalaa",
526 "url[ffffffffffff] some text traalaa",
527 ["ffffffffffff"]
528 ),
529 (
530 """Multi line
531 123123123123
532 some text 000000000000
533 sometimes !
534 """,
535 """Multi line
536 url[123123123123]
537 some text url[000000000000]
538 sometimes !
539 """,
540 ["123123123123", "000000000000"]
541 )
500 542 ], ids=no_newline_id_generator)
501 def test_urlify_commits(sample, expected):
543 def test_urlify_commits(sample, expected, commits):
502 544 def fake_url(self, *args, **kwargs):
503 545 return '/some-url'
504 546
505 expected = _quick_url(expected)
547 expected = _quick_url(expected, commits=commits)
506 548
507 549 with mock.patch('rhodecode.lib.helpers.route_url', fake_url):
508 550 from rhodecode.lib.helpers import urlify_commits
General Comments 0
You need to be logged in to leave comments. Login now