##// END OF EJS Templates
slack: fix links in commit/pr events
dan -
r419:d85a7d46 default
parent child Browse files
Show More
@@ -31,7 +31,8 b' import pylons'
31 import rhodecode
31 import rhodecode
32
32
33 from rhodecode.lib import hooks_base
33 from rhodecode.lib import hooks_base
34 from rhodecode.lib.utils2 import AttributeDict
34 from rhodecode.lib.utils2 import (
35 AttributeDict, safe_str, get_routes_generator_for_server_url)
35
36
36
37
37 log = logging.getLogger(__name__)
38 log = logging.getLogger(__name__)
@@ -240,16 +241,7 b' class Hooks(object):'
240
241
241 def _call_hook(self, hook, extras):
242 def _call_hook(self, hook, extras):
242 extras = AttributeDict(extras)
243 extras = AttributeDict(extras)
243 netloc = urlparse.urlparse(extras.server_url).netloc
244 pylons_router = get_routes_generator_for_server_url(extras.server_url)
244 environ = {
245 'SERVER_NAME': netloc.split(':')[0],
246 'SERVER_PORT': ':' in netloc and netloc.split(':')[1] or '80',
247 'SCRIPT_NAME': '',
248 'PATH_INFO': '/',
249 'HTTP_HOST': 'localhost',
250 'REQUEST_METHOD': 'GET',
251 }
252 pylons_router = URLGenerator(rhodecode.CONFIG['routes.map'], environ)
253 pylons.url._push_object(pylons_router)
245 pylons.url._push_object(pylons_router)
254
246
255 try:
247 try:
@@ -41,6 +41,7 b' import pygments.lexers'
41 import sqlalchemy
41 import sqlalchemy
42 import sqlalchemy.engine.url
42 import sqlalchemy.engine.url
43 import webob
43 import webob
44 import routes.util
44
45
45 import rhodecode
46 import rhodecode
46
47
@@ -858,3 +859,28 b' class Optional(object):'
858 if isinstance(val, cls):
859 if isinstance(val, cls):
859 return val.getval()
860 return val.getval()
860 return val
861 return val
862
863
864 def get_routes_generator_for_server_url(server_url):
865 parsed_url = urlobject.URLObject(server_url)
866 netloc = safe_str(parsed_url.netloc)
867 script_name = safe_str(parsed_url.path)
868
869 if ':' in netloc:
870 server_name, server_port = netloc.split(':')
871 else:
872 server_name = netloc
873 server_port = (parsed_url.scheme == 'https' and '443' or '80')
874
875 environ = {
876 'REQUEST_METHOD': 'GET',
877 'PATH_INFO': '/',
878 'SERVER_NAME': server_name,
879 'SERVER_PORT': server_port,
880 'SCRIPT_NAME': script_name,
881 }
882 if parsed_url.scheme == 'https':
883 environ['HTTPS'] = 'on'
884 environ['wsgi.url_scheme'] = 'https'
885
886 return routes.util.URLGenerator(rhodecode.CONFIG['routes.map'], environ)
@@ -750,7 +750,7 b' class PullRequestModel(BaseModel):'
750
750
751 def get_url(self, pull_request):
751 def get_url(self, pull_request):
752 return h.url('pullrequest_show',
752 return h.url('pullrequest_show',
753 repo_name=pull_request.target_repo.repo_name,
753 repo_name=safe_str(pull_request.target_repo.repo_name),
754 pull_request_id=pull_request.pull_request_id,
754 pull_request_id=pull_request.pull_request_id,
755 qualified=True)
755 qualified=True)
756
756
@@ -142,7 +142,8 b' class RepoModel(BaseModel):'
142 return None
142 return None
143
143
144 def get_url(self, repo):
144 def get_url(self, repo):
145 return h.url('summary_home', repo_name=repo.repo_name, qualified=True)
145 return h.url('summary_home', repo_name=safe_str(repo.repo_name),
146 qualified=True)
146
147
147 def get_users(self, name_contains=None, limit=20, only_active=True):
148 def get_users(self, name_contains=None, limit=20, only_active=True):
148 # TODO: mikhail: move this method to the UserModel.
149 # TODO: mikhail: move this method to the UserModel.
@@ -18,9 +18,41 b''
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 from rhodecode.lib.utils2 import obfuscate_url_pw
21 import pytest
22
23 from rhodecode.lib.utils2 import (
24 obfuscate_url_pw, get_routes_generator_for_server_url)
22
25
23
26
24 def test_obfuscate_url_pw():
27 def test_obfuscate_url_pw():
25 engine = u'/home/repos/malmö'
28 engine = u'/home/repos/malmö'
26 assert obfuscate_url_pw(engine)
29 assert obfuscate_url_pw(engine)
30
31
32 @pytest.mark.parametrize('scheme', ['https', 'http'])
33 @pytest.mark.parametrize('domain', [
34 'www.test.com', 'test.com', 'test.co.uk', '192.168.1.3'])
35 @pytest.mark.parametrize('port', [None, '80', '443', '999'])
36 @pytest.mark.parametrize('script_path', [None, '/', '/prefix', '/prefix/more'])
37 def test_routes_generator(pylonsapp, scheme, domain, port, script_path):
38 server_url = '%s://%s' % (scheme, domain)
39 if port is not None:
40 server_url += ':' + port
41 if script_path:
42 server_url += script_path
43
44
45 expected_url = '%s://%s' % (scheme, domain)
46 if scheme == 'https':
47 if port not in (None, '443'):
48 expected_url += ':' + port
49 elif scheme == 'http':
50 if port not in ('80', None):
51 expected_url += ':' + port
52
53 if script_path:
54 expected_url = (expected_url + script_path).rstrip('/')
55
56 url_generator = get_routes_generator_for_server_url(server_url)
57 assert url_generator(
58 '/a_test_path', qualified=True) == expected_url + '/a_test_path'
General Comments 0
You need to be logged in to leave comments. Login now