Show More
@@ -18,6 +18,7 b'' | |||||
18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 |
|
19 | |||
20 | import io |
|
20 | import io | |
|
21 | import os | |||
21 | import sys |
|
22 | import sys | |
22 | import json |
|
23 | import json | |
23 | import logging |
|
24 | import logging | |
@@ -124,6 +125,7 b' def _get_hooks_client(extras):' | |||||
124 | def _call_hook(hook_name, extras, writer): |
|
125 | def _call_hook(hook_name, extras, writer): | |
125 | hooks = _get_hooks_client(extras) |
|
126 | hooks = _get_hooks_client(extras) | |
126 | result = hooks(hook_name, extras) |
|
127 | result = hooks(hook_name, extras) | |
|
128 | log.debug('Hooks got result: %s', result) | |||
127 | writer.write(result['output']) |
|
129 | writer.write(result['output']) | |
128 | _handle_exception(result) |
|
130 | _handle_exception(result) | |
129 |
|
131 | |||
@@ -131,22 +133,14 b' def _call_hook(hook_name, extras, writer' | |||||
131 |
|
133 | |||
132 |
|
134 | |||
133 | def _extras_from_ui(ui): |
|
135 | def _extras_from_ui(ui): | |
134 |
|
|
136 | hook_data = ui.config('rhodecode', 'RC_SCM_DATA') | |
|
137 | if not hook_data: | |||
|
138 | # maybe it's inside environ ? | |||
|
139 | hook_data = os.environ.get('RC_SCM_DATA') | |||
|
140 | extras = json.loads(hook_data) | |||
135 | return extras |
|
141 | return extras | |
136 |
|
142 | |||
137 |
|
143 | |||
138 | def repo_size(ui, repo, **kwargs): |
|
|||
139 | return _call_hook('repo_size', _extras_from_ui(ui), HgMessageWriter(ui)) |
|
|||
140 |
|
||||
141 |
|
||||
142 | def pre_pull(ui, repo, **kwargs): |
|
|||
143 | return _call_hook('pre_pull', _extras_from_ui(ui), HgMessageWriter(ui)) |
|
|||
144 |
|
||||
145 |
|
||||
146 | def post_pull(ui, repo, **kwargs): |
|
|||
147 | return _call_hook('post_pull', _extras_from_ui(ui), HgMessageWriter(ui)) |
|
|||
148 |
|
||||
149 |
|
||||
150 | def _rev_range_hash(repo, node): |
|
144 | def _rev_range_hash(repo, node): | |
151 |
|
145 | |||
152 | commits = [] |
|
146 | commits = [] | |
@@ -159,6 +153,33 b' def _rev_range_hash(repo, node):' | |||||
159 | return commits |
|
153 | return commits | |
160 |
|
154 | |||
161 |
|
155 | |||
|
156 | def repo_size(ui, repo, **kwargs): | |||
|
157 | extras = _extras_from_ui(ui) | |||
|
158 | return _call_hook('repo_size', extras, HgMessageWriter(ui)) | |||
|
159 | ||||
|
160 | ||||
|
161 | def pre_pull(ui, repo, **kwargs): | |||
|
162 | extras = _extras_from_ui(ui) | |||
|
163 | return _call_hook('pre_pull', extras, HgMessageWriter(ui)) | |||
|
164 | ||||
|
165 | ||||
|
166 | def pre_pull_ssh(ui, repo, **kwargs): | |||
|
167 | if _extras_from_ui(ui).get('SSH'): | |||
|
168 | return pre_pull(ui, repo, **kwargs) | |||
|
169 | return 0 | |||
|
170 | ||||
|
171 | ||||
|
172 | def post_pull(ui, repo, **kwargs): | |||
|
173 | extras = _extras_from_ui(ui) | |||
|
174 | return _call_hook('post_pull', extras, HgMessageWriter(ui)) | |||
|
175 | ||||
|
176 | ||||
|
177 | def post_pull_ssh(ui, repo, **kwargs): | |||
|
178 | if _extras_from_ui(ui).get('SSH'): | |||
|
179 | return post_pull(ui, repo, **kwargs) | |||
|
180 | return 0 | |||
|
181 | ||||
|
182 | ||||
162 | def pre_push(ui, repo, node=None, **kwargs): |
|
183 | def pre_push(ui, repo, node=None, **kwargs): | |
163 | extras = _extras_from_ui(ui) |
|
184 | extras = _extras_from_ui(ui) | |
164 |
|
185 | |||
@@ -182,6 +203,27 b' def pre_push(ui, repo, node=None, **kwar' | |||||
182 | return _call_hook('pre_push', extras, HgMessageWriter(ui)) |
|
203 | return _call_hook('pre_push', extras, HgMessageWriter(ui)) | |
183 |
|
204 | |||
184 |
|
205 | |||
|
206 | def pre_push_ssh(ui, repo, node=None, **kwargs): | |||
|
207 | if _extras_from_ui(ui).get('SSH'): | |||
|
208 | return pre_push(ui, repo, node, **kwargs) | |||
|
209 | ||||
|
210 | return 0 | |||
|
211 | ||||
|
212 | ||||
|
213 | def pre_push_ssh_auth(ui, repo, node=None, **kwargs): | |||
|
214 | extras = _extras_from_ui(ui) | |||
|
215 | if extras.get('SSH'): | |||
|
216 | permission = extras['SSH_PERMISSIONS'] | |||
|
217 | ||||
|
218 | if 'repository.write' == permission or 'repository.admin' == permission: | |||
|
219 | return 0 | |||
|
220 | ||||
|
221 | # non-zero ret code | |||
|
222 | return 1 | |||
|
223 | ||||
|
224 | return 0 | |||
|
225 | ||||
|
226 | ||||
185 | def post_push(ui, repo, node, **kwargs): |
|
227 | def post_push(ui, repo, node, **kwargs): | |
186 | extras = _extras_from_ui(ui) |
|
228 | extras = _extras_from_ui(ui) | |
187 |
|
229 | |||
@@ -208,12 +250,19 b' def post_push(ui, repo, node, **kwargs):' | |||||
208 | return _call_hook('post_push', extras, HgMessageWriter(ui)) |
|
250 | return _call_hook('post_push', extras, HgMessageWriter(ui)) | |
209 |
|
251 | |||
210 |
|
252 | |||
|
253 | def post_push_ssh(ui, repo, node, **kwargs): | |||
|
254 | if _extras_from_ui(ui).get('SSH'): | |||
|
255 | return post_push(ui, repo, node, **kwargs) | |||
|
256 | return 0 | |||
|
257 | ||||
|
258 | ||||
211 | def key_push(ui, repo, **kwargs): |
|
259 | def key_push(ui, repo, **kwargs): | |
212 | if kwargs['new'] != '0' and kwargs['namespace'] == 'bookmarks': |
|
260 | if kwargs['new'] != '0' and kwargs['namespace'] == 'bookmarks': | |
213 | # store new bookmarks in our UI object propagated later to post_push |
|
261 | # store new bookmarks in our UI object propagated later to post_push | |
214 | ui._rc_pushkey_branches = repo[kwargs['key']].bookmarks() |
|
262 | ui._rc_pushkey_branches = repo[kwargs['key']].bookmarks() | |
215 | return |
|
263 | return | |
216 |
|
264 | |||
|
265 | ||||
217 | # backward compat |
|
266 | # backward compat | |
218 | log_pull_action = post_pull |
|
267 | log_pull_action = post_pull | |
219 |
|
268 |
General Comments 0
You need to be logged in to leave comments.
Login now