##// END OF EJS Templates
ssh: call custom hooks via SSH backend
marcink -
r3637:c15c96da default
parent child Browse files
Show More
@@ -25,6 +25,7 b' import tempfile'
25 import textwrap
25 import textwrap
26 import collections
26 import collections
27 from .base import VcsServer
27 from .base import VcsServer
28 from rhodecode.model.db import RhodeCodeUi
28 from rhodecode.model.settings import VcsSettingsModel
29 from rhodecode.model.settings import VcsSettingsModel
29
30
30 log = logging.getLogger(__name__)
31 log = logging.getLogger(__name__)
@@ -45,16 +46,7 b' class MercurialTunnelWrapper(object):'
45
46
46 content = textwrap.dedent(
47 content = textwrap.dedent(
47 '''
48 '''
48 # SSH hooks version=2.0.0
49 # RhodeCode SSH hooks version=2.0.0
49 [hooks]
50 pretxnchangegroup.ssh_auth=python:vcsserver.hooks.pre_push_ssh_auth
51 pretxnchangegroup.ssh=python:vcsserver.hooks.pre_push_ssh
52 changegroup.ssh=python:vcsserver.hooks.post_push_ssh
53
54 preoutgoing.ssh=python:vcsserver.hooks.pre_pull_ssh
55 outgoing.ssh=python:vcsserver.hooks.post_pull_ssh
56
57 # Custom Config version=2.0.0
58 {custom}
50 {custom}
59 '''
51 '''
60 ).format(custom='\n'.join(hg_flags))
52 ).format(custom='\n'.join(hg_flags))
@@ -105,7 +97,7 b' class MercurialTunnelWrapper(object):'
105
97
106 class MercurialServer(VcsServer):
98 class MercurialServer(VcsServer):
107 backend = 'hg'
99 backend = 'hg'
108 cli_flags = ['phases', 'largefiles', 'extensions', 'experimental']
100 cli_flags = ['phases', 'largefiles', 'extensions', 'experimental', 'hooks']
109
101
110 def __init__(self, store, ini_path, repo_name, user, user_permissions, config, env):
102 def __init__(self, store, ini_path, repo_name, user, user_permissions, config, env):
111 super(MercurialServer, self).__init__(user, user_permissions, config, env)
103 super(MercurialServer, self).__init__(user, user_permissions, config, env)
@@ -120,13 +112,31 b' class MercurialServer(VcsServer):'
120 ui_sections = collections.defaultdict(list)
112 ui_sections = collections.defaultdict(list)
121 ui = VcsSettingsModel(repo=repo_name).get_ui_settings(section=None, key=None)
113 ui = VcsSettingsModel(repo=repo_name).get_ui_settings(section=None, key=None)
122
114
115 # write default hooks
116 default_hooks = [
117 ('pretxnchangegroup.ssh_auth', 'python:vcsserver.hooks.pre_push_ssh_auth'),
118 ('pretxnchangegroup.ssh', 'python:vcsserver.hooks.pre_push_ssh'),
119 ('changegroup.ssh', 'python:vcsserver.hooks.post_push_ssh'),
120
121 ('preoutgoing.ssh', 'python:vcsserver.hooks.pre_pull_ssh'),
122 ('outgoing.ssh', 'python:vcsserver.hooks.post_pull_ssh'),
123 ]
124
125 for k, v in default_hooks:
126 ui_sections['hooks'].append((k, v))
127
123 for entry in ui:
128 for entry in ui:
124 if not entry.active:
129 if not entry.active:
125 continue
130 continue
126 sec = entry.section
131 sec = entry.section
132 key = entry.key
127
133
128 if sec in self.cli_flags:
134 if sec in self.cli_flags:
129 ui_sections[sec].append([entry.key, entry.value])
135 # we want only custom hooks, so we skip builtins
136 if sec == 'hooks' and key in RhodeCodeUi.HOOKS_BUILTIN:
137 continue
138
139 ui_sections[sec].append([key, entry.value])
130
140
131 flags = []
141 flags = []
132 for _sec, key_val in ui_sections.items():
142 for _sec, key_val in ui_sections.items():
@@ -411,6 +411,15 b' class RhodeCodeUi(Base, BaseModel):'
411 HOOK_PUSH = 'changegroup.push_logger'
411 HOOK_PUSH = 'changegroup.push_logger'
412 HOOK_PUSH_KEY = 'pushkey.key_push'
412 HOOK_PUSH_KEY = 'pushkey.key_push'
413
413
414 HOOKS_BUILTIN = [
415 HOOK_PRE_PULL,
416 HOOK_PULL,
417 HOOK_PRE_PUSH,
418 HOOK_PRETX_PUSH,
419 HOOK_PUSH,
420 HOOK_PUSH_KEY,
421 ]
422
414 # TODO: johbo: Unify way how hooks are configured for git and hg,
423 # TODO: johbo: Unify way how hooks are configured for git and hg,
415 # git part is currently hardcoded.
424 # git part is currently hardcoded.
416
425
General Comments 0
You need to be logged in to leave comments. Login now