Show More
@@ -539,12 +539,24 b' def add_events_routes(config):' | |||||
539 | pattern='/{repo_name}/pull-request/{pull_request_id}') |
|
539 | pattern='/{repo_name}/pull-request/{pull_request_id}') | |
540 | config.add_route(name='pull_requests_global', |
|
540 | config.add_route(name='pull_requests_global', | |
541 | pattern='/pull-request/{pull_request_id}') |
|
541 | pattern='/pull-request/{pull_request_id}') | |
|
542 | ||||
542 | config.add_route(name='repo_commit', |
|
543 | config.add_route(name='repo_commit', | |
543 | pattern='/{repo_name}/changeset/{commit_id}') |
|
544 | pattern='/{repo_name}/changeset/{commit_id}') | |
544 |
|
||||
545 | config.add_route(name='repo_files', |
|
545 | config.add_route(name='repo_files', | |
546 | pattern='/{repo_name}/files/{commit_id}/{f_path}') |
|
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 | def bootstrap_config(request): |
|
561 | def bootstrap_config(request): | |
550 | import pyramid.testing |
|
562 | import pyramid.testing |
@@ -1577,21 +1577,21 b' def urlify_text(text_, safe=True):' | |||||
1577 | def url_func(match_obj): |
|
1577 | def url_func(match_obj): | |
1578 | url_full = match_obj.groups()[0] |
|
1578 | url_full = match_obj.groups()[0] | |
1579 | return '<a href="%(url)s">%(url)s</a>' % ({'url': url_full}) |
|
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 | if safe: |
|
1581 | if safe: | |
1582 | return literal(_newtext) |
|
1582 | return literal(_new_text) | |
1583 | return _newtext |
|
1583 | return _new_text | |
1584 |
|
1584 | |||
1585 |
|
1585 | |||
1586 |
def urlify_commits(text_, repo |
|
1586 | def urlify_commits(text_, repo_name): | |
1587 | """ |
|
1587 | """ | |
1588 | Extract commit ids from text and make link from them |
|
1588 | Extract commit ids from text and make link from them | |
1589 |
|
1589 | |||
1590 | :param text_: |
|
1590 | :param text_: | |
1591 |
:param repo |
|
1591 | :param repo_name: repo name to build the URL with | |
1592 | """ |
|
1592 | """ | |
1593 |
|
1593 | |||
1594 |
|
|
1594 | url_pat = re.compile(r'(^|\s)([0-9a-fA-F]{12,40})($|\s)') | |
1595 |
|
1595 | |||
1596 | def url_func(match_obj): |
|
1596 | def url_func(match_obj): | |
1597 | commit_id = match_obj.groups()[1] |
|
1597 | commit_id = match_obj.groups()[1] | |
@@ -1599,20 +1599,24 b' def urlify_commits(text_, repository):' | |||||
1599 | suf = match_obj.groups()[2] |
|
1599 | suf = match_obj.groups()[2] | |
1600 |
|
1600 | |||
1601 | tmpl = ( |
|
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 | '%(commit_id)s</a>%(suf)s' |
|
1603 | '%(commit_id)s</a>%(suf)s' | |
1604 | ) |
|
1604 | ) | |
1605 | return tmpl % { |
|
1605 | return tmpl % { | |
1606 | 'pref': pref, |
|
1606 | 'pref': pref, | |
1607 | 'cls': 'revision-link', |
|
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 | 'commit_id': commit_id, |
|
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 = |
|
1617 | new_text = url_pat.sub(url_func, text_) | |
1614 |
|
1618 | |||
1615 | return newtext |
|
1619 | return new_text | |
1616 |
|
1620 | |||
1617 |
|
1621 | |||
1618 | def _process_url_func(match_obj, repo_name, uid, entry, |
|
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 | Parses given text message and makes proper links. |
|
1772 | Parses given text message and makes proper links. | |
1769 | issues are linked to given issue-server, and rest is a commit link |
|
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 | def escaper(_text): |
|
1775 | def escaper(_text): | |
1775 | return _text.replace('<', '<').replace('>', '>') |
|
1776 | return _text.replace('<', '<').replace('>', '>') |
@@ -243,7 +243,7 b' var tooltipActivate = function () {' | |||||
243 | }); |
|
243 | }); | |
244 | var hovercardCache = {}; |
|
244 | var hovercardCache = {}; | |
245 |
|
245 | |||
246 | var loadHoverCard = function (url, callback) { |
|
246 | var loadHoverCard = function (url, altHovercard, callback) { | |
247 | var id = url; |
|
247 | var id = url; | |
248 |
|
248 | |||
249 | if (hovercardCache[id] !== undefined) { |
|
249 | if (hovercardCache[id] !== undefined) { | |
@@ -257,7 +257,12 b' var tooltipActivate = function () {' | |||||
257 | callback(hovercardCache[id]); |
|
257 | callback(hovercardCache[id]); | |
258 | return true; |
|
258 | return true; | |
259 | }).fail(function (data, textStatus, errorThrown) { |
|
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 | callback(msg); |
|
266 | callback(msg); | |
262 | return false |
|
267 | return false | |
263 | }); |
|
268 | }); | |
@@ -291,16 +296,17 b' var tooltipActivate = function () {' | |||||
291 | // we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens |
|
296 | // we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens | |
292 | if ($origin.data('loaded') !== true) { |
|
297 | if ($origin.data('loaded') !== true) { | |
293 | var hovercardUrl = $origin.data('hovercardUrl'); |
|
298 | var hovercardUrl = $origin.data('hovercardUrl'); | |
|
299 | var altHovercard =$origin.data('hovercardAlt'); | |||
294 |
|
300 | |||
295 | if (hovercardUrl !== undefined && hovercardUrl !== "") { |
|
301 | if (hovercardUrl !== undefined && hovercardUrl !== "") { | |
296 | var loaded = loadHoverCard(hovercardUrl, function (data) { |
|
302 | var loaded = loadHoverCard(hovercardUrl, altHovercard, function (data) { | |
297 | instance.content(data); |
|
303 | instance.content(data); | |
298 | }) |
|
304 | }) | |
299 | } else { |
|
305 | } else { | |
300 | if ($origin.data('hovercardAltHtml')) { |
|
306 | if ($origin.data('hovercardAltHtml')) { | |
301 | var data = atob($origin.data('hovercardAltHtml')); |
|
307 | var data = atob($origin.data('hovercardAltHtml')); | |
302 | } else { |
|
308 | } else { | |
303 |
var data = '<div style="white-space: pre-wrap">{0}</div>'.format( |
|
309 | var data = '<div style="white-space: pre-wrap">{0}</div>'.format(altHovercard) | |
304 | } |
|
310 | } | |
305 | var loaded = true; |
|
311 | var loaded = true; | |
306 | instance.content(data); |
|
312 | instance.content(data); |
@@ -178,11 +178,13 b'' | |||||
178 | <div class="fields"> |
|
178 | <div class="fields"> | |
179 | <div class="field"> |
|
179 | <div class="field"> | |
180 | <div class='textarea-full'> |
|
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 | This commit fixes ticket #451. |
|
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 | Open a pull request !101 to contribute ! |
|
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 | </textarea> |
|
188 | </textarea> | |
187 | </div> |
|
189 | </div> | |
188 | </div> |
|
190 | </div> |
@@ -454,7 +454,10 b' def test_clone_url_generator(tmpl, repo_' | |||||
454 | assert clone_url == expected |
|
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 | Changes `some text url[foo]` => `some text <a href="/">foo</a> |
|
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 | import re |
|
466 | import re | |
464 | # quickly change expected url[] into a link |
|
467 | # quickly change expected url[] into a link | |
465 |
|
|
468 | url_pat = re.compile(r'(?:url\[)(.+?)(?:\])') | |
|
469 | commits = commits or [] | |||
|
470 | ||||
|
471 | global idx | |||
|
472 | idx = 0 | |||
466 |
|
473 | |||
467 | def url_func(match_obj): |
|
474 | def url_func(match_obj): | |
|
475 | global idx | |||
468 | _url = match_obj.groups()[0] |
|
476 | _url = match_obj.groups()[0] | |
469 | return tmpl % (url_ or '/some-url', _url) |
|
477 | if commits: | |
470 | return URL_PAT.sub(url_func, text) |
|
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", [ |
|
487 | @pytest.mark.parametrize("sample, expected, commits", [ | |
474 | ("", |
|
488 | ( | |
475 | ""), |
|
489 | "", | |
476 | ("git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68", |
|
490 | "", | |
477 | "git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68"), |
|
491 | [""] | |
478 | ("from rev 000000000000", |
|
492 | ), | |
479 | "from rev url[000000000000]"), |
|
493 | ( | |
480 | ("from rev 000000000000123123 also rev 000000000000", |
|
494 | "git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68", | |
481 | "from rev url[000000000000123123] also rev url[000000000000]"), |
|
495 | "git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68", | |
482 | ("this should-000 00", |
|
496 | [""] | |
483 | "this should-000 00"), |
|
497 | ), | |
484 | ("longtextffffffffff rev 123123123123", |
|
498 | ( | |
485 | "longtextffffffffff rev url[123123123123]"), |
|
499 | "from rev 000000000000", | |
486 | ("rev ffffffffffffffffffffffffffffffffffffffffffffffffff", |
|
500 | "from rev url[000000000000]", | |
487 | "rev ffffffffffffffffffffffffffffffffffffffffffffffffff"), |
|
501 | ["000000000000"] | |
488 | ("ffffffffffff some text traalaa", |
|
502 | ), | |
489 | "url[ffffffffffff] some text traalaa"), |
|
503 | ||
490 | ("""Multi line |
|
504 | ( | |
491 | 123123123123 |
|
505 | "from rev 000000000000123123 also rev 000000000000", | |
492 | some text 123123123123 |
|
506 | "from rev url[000000000000123123] also rev url[000000000000]", | |
493 | sometimes ! |
|
507 | ["000000000000123123", "000000000000"] | |
494 |
|
|
508 | ), | |
495 | """Multi line |
|
509 | ( | |
496 | url[123123123123] |
|
510 | "this should-000 00", | |
497 | some text url[123123123123] |
|
511 | "this should-000 00", | |
498 | sometimes ! |
|
512 | [""] | |
499 |
|
|
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 | ], ids=no_newline_id_generator) |
|
542 | ], ids=no_newline_id_generator) | |
501 | def test_urlify_commits(sample, expected): |
|
543 | def test_urlify_commits(sample, expected, commits): | |
502 | def fake_url(self, *args, **kwargs): |
|
544 | def fake_url(self, *args, **kwargs): | |
503 | return '/some-url' |
|
545 | return '/some-url' | |
504 |
|
546 | |||
505 | expected = _quick_url(expected) |
|
547 | expected = _quick_url(expected, commits=commits) | |
506 |
|
548 | |||
507 | with mock.patch('rhodecode.lib.helpers.route_url', fake_url): |
|
549 | with mock.patch('rhodecode.lib.helpers.route_url', fake_url): | |
508 | from rhodecode.lib.helpers import urlify_commits |
|
550 | from rhodecode.lib.helpers import urlify_commits |
General Comments 0
You need to be logged in to leave comments.
Login now