##// END OF EJS Templates
extensions: adapt hooks to latest version of extensions (pre-push)
marcink -
r1456:c0280798 default
parent child Browse files
Show More
@@ -1,395 +1,396 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2013-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21
22 22 """
23 23 Set of hooks run by RhodeCode Enterprise
24 24 """
25 25
26 26 import os
27 27 import collections
28 28 import logging
29 29
30 30 import rhodecode
31 31 from rhodecode import events
32 32 from rhodecode.lib import helpers as h
33 33 from rhodecode.lib.utils import action_logger
34 34 from rhodecode.lib.utils2 import safe_str
35 35 from rhodecode.lib.exceptions import HTTPLockedRC, UserCreationError
36 36 from rhodecode.model.db import Repository, User
37 37
38 38 log = logging.getLogger(__name__)
39 39
40 40
41 41 HookResponse = collections.namedtuple('HookResponse', ('status', 'output'))
42 42
43 43
44 44 def is_shadow_repo(extras):
45 45 """
46 46 Returns ``True`` if this is an action executed against a shadow repository.
47 47 """
48 48 return extras['is_shadow_repo']
49 49
50 50
51 51 def _get_scm_size(alias, root_path):
52 52
53 53 if not alias.startswith('.'):
54 54 alias += '.'
55 55
56 56 size_scm, size_root = 0, 0
57 57 for path, unused_dirs, files in os.walk(safe_str(root_path)):
58 58 if path.find(alias) != -1:
59 59 for f in files:
60 60 try:
61 61 size_scm += os.path.getsize(os.path.join(path, f))
62 62 except OSError:
63 63 pass
64 64 else:
65 65 for f in files:
66 66 try:
67 67 size_root += os.path.getsize(os.path.join(path, f))
68 68 except OSError:
69 69 pass
70 70
71 71 size_scm_f = h.format_byte_size_binary(size_scm)
72 72 size_root_f = h.format_byte_size_binary(size_root)
73 73 size_total_f = h.format_byte_size_binary(size_root + size_scm)
74 74
75 75 return size_scm_f, size_root_f, size_total_f
76 76
77 77
78 78 # actual hooks called by Mercurial internally, and GIT by our Python Hooks
79 79 def repo_size(extras):
80 80 """Present size of repository after push."""
81 81 repo = Repository.get_by_repo_name(extras.repository)
82 82 vcs_part = safe_str(u'.%s' % repo.repo_type)
83 83 size_vcs, size_root, size_total = _get_scm_size(vcs_part,
84 84 repo.repo_full_path)
85 85 msg = ('Repository `%s` size summary %s:%s repo:%s total:%s\n'
86 86 % (repo.repo_name, vcs_part, size_vcs, size_root, size_total))
87 87 return HookResponse(0, msg)
88 88
89 89
90 90 def pre_push(extras):
91 91 """
92 92 Hook executed before pushing code.
93 93
94 94 It bans pushing when the repository is locked.
95 95 """
96
96 97 usr = User.get_by_username(extras.username)
97 98 output = ''
98 99 if extras.locked_by[0] and usr.user_id != int(extras.locked_by[0]):
99 100 locked_by = User.get(extras.locked_by[0]).username
100 101 reason = extras.locked_by[2]
101 102 # this exception is interpreted in git/hg middlewares and based
102 103 # on that proper return code is server to client
103 104 _http_ret = HTTPLockedRC(
104 105 _locked_by_explanation(extras.repository, locked_by, reason))
105 106 if str(_http_ret.code).startswith('2'):
106 107 # 2xx Codes don't raise exceptions
107 108 output = _http_ret.title
108 109 else:
109 110 raise _http_ret
110 111
111 112 # Propagate to external components. This is done after checking the
112 113 # lock, for consistent behavior.
113 114 if not is_shadow_repo(extras):
114 115 pre_push_extension(repo_store_path=Repository.base_path(), **extras)
115 116 events.trigger(events.RepoPrePushEvent(
116 117 repo_name=extras.repository, extras=extras))
117 118
118 119 return HookResponse(0, output)
119 120
120 121
121 122 def pre_pull(extras):
122 123 """
123 124 Hook executed before pulling the code.
124 125
125 126 It bans pulling when the repository is locked.
126 127 """
127 128
128 129 output = ''
129 130 if extras.locked_by[0]:
130 131 locked_by = User.get(extras.locked_by[0]).username
131 132 reason = extras.locked_by[2]
132 133 # this exception is interpreted in git/hg middlewares and based
133 134 # on that proper return code is server to client
134 135 _http_ret = HTTPLockedRC(
135 136 _locked_by_explanation(extras.repository, locked_by, reason))
136 137 if str(_http_ret.code).startswith('2'):
137 138 # 2xx Codes don't raise exceptions
138 139 output = _http_ret.title
139 140 else:
140 141 raise _http_ret
141 142
142 143 # Propagate to external components. This is done after checking the
143 144 # lock, for consistent behavior.
144 145 if not is_shadow_repo(extras):
145 146 pre_pull_extension(**extras)
146 147 events.trigger(events.RepoPrePullEvent(
147 148 repo_name=extras.repository, extras=extras))
148 149
149 150 return HookResponse(0, output)
150 151
151 152
152 153 def post_pull(extras):
153 154 """Hook executed after client pulls the code."""
154 155 user = User.get_by_username(extras.username)
155 156 action = 'pull'
156 157 action_logger(user, action, extras.repository, extras.ip, commit=True)
157 158
158 159 # Propagate to external components.
159 160 if not is_shadow_repo(extras):
160 161 post_pull_extension(**extras)
161 162 events.trigger(events.RepoPullEvent(
162 163 repo_name=extras.repository, extras=extras))
163 164
164 165 output = ''
165 166 # make lock is a tri state False, True, None. We only make lock on True
166 167 if extras.make_lock is True and not is_shadow_repo(extras):
167 168 Repository.lock(Repository.get_by_repo_name(extras.repository),
168 169 user.user_id,
169 170 lock_reason=Repository.LOCK_PULL)
170 171 msg = 'Made lock on repo `%s`' % (extras.repository,)
171 172 output += msg
172 173
173 174 if extras.locked_by[0]:
174 175 locked_by = User.get(extras.locked_by[0]).username
175 176 reason = extras.locked_by[2]
176 177 _http_ret = HTTPLockedRC(
177 178 _locked_by_explanation(extras.repository, locked_by, reason))
178 179 if str(_http_ret.code).startswith('2'):
179 180 # 2xx Codes don't raise exceptions
180 181 output += _http_ret.title
181 182
182 183 return HookResponse(0, output)
183 184
184 185
185 186 def post_push(extras):
186 187 """Hook executed after user pushes to the repository."""
187 188 action_tmpl = extras.action + ':%s'
188 189 commit_ids = extras.commit_ids[:29000]
189 190
190 191 action = action_tmpl % ','.join(commit_ids)
191 192 action_logger(
192 193 extras.username, action, extras.repository, extras.ip, commit=True)
193 194
194 195 # Propagate to external components.
195 196 if not is_shadow_repo(extras):
196 197 post_push_extension(
197 198 repo_store_path=Repository.base_path(),
198 199 pushed_revs=commit_ids,
199 200 **extras)
200 201 events.trigger(events.RepoPushEvent(
201 202 repo_name=extras.repository,
202 203 pushed_commit_ids=commit_ids,
203 204 extras=extras))
204 205
205 206 output = ''
206 207 # make lock is a tri state False, True, None. We only release lock on False
207 208 if extras.make_lock is False and not is_shadow_repo(extras):
208 209 Repository.unlock(Repository.get_by_repo_name(extras.repository))
209 210 msg = 'Released lock on repo `%s`\n' % extras.repository
210 211 output += msg
211 212
212 213 if extras.locked_by[0]:
213 214 locked_by = User.get(extras.locked_by[0]).username
214 215 reason = extras.locked_by[2]
215 216 _http_ret = HTTPLockedRC(
216 217 _locked_by_explanation(extras.repository, locked_by, reason))
217 218 # TODO: johbo: if not?
218 219 if str(_http_ret.code).startswith('2'):
219 220 # 2xx Codes don't raise exceptions
220 221 output += _http_ret.title
221 222
222 223 output += 'RhodeCode: push completed\n'
223 224
224 225 return HookResponse(0, output)
225 226
226 227
227 228 def _locked_by_explanation(repo_name, user_name, reason):
228 229 message = (
229 230 'Repository `%s` locked by user `%s`. Reason:`%s`'
230 231 % (repo_name, user_name, reason))
231 232 return message
232 233
233 234
234 235 def check_allowed_create_user(user_dict, created_by, **kwargs):
235 236 # pre create hooks
236 237 if pre_create_user.is_active():
237 238 allowed, reason = pre_create_user(created_by=created_by, **user_dict)
238 239 if not allowed:
239 240 raise UserCreationError(reason)
240 241
241 242
242 243 class ExtensionCallback(object):
243 244 """
244 245 Forwards a given call to rcextensions, sanitizes keyword arguments.
245 246
246 247 Does check if there is an extension active for that hook. If it is
247 248 there, it will forward all `kwargs_keys` keyword arguments to the
248 249 extension callback.
249 250 """
250 251
251 252 def __init__(self, hook_name, kwargs_keys):
252 253 self._hook_name = hook_name
253 254 self._kwargs_keys = set(kwargs_keys)
254 255
255 256 def __call__(self, *args, **kwargs):
256 257 log.debug('Calling extension callback for %s', self._hook_name)
257 258
258 259 kwargs_to_pass = dict((key, kwargs[key]) for key in self._kwargs_keys)
259 260 callback = self._get_callback()
260 261 if callback:
261 262 return callback(**kwargs_to_pass)
262 263 else:
263 264 log.debug('extensions callback not found skipping...')
264 265
265 266 def is_active(self):
266 267 return hasattr(rhodecode.EXTENSIONS, self._hook_name)
267 268
268 269 def _get_callback(self):
269 270 return getattr(rhodecode.EXTENSIONS, self._hook_name, None)
270 271
271 272
272 273 pre_pull_extension = ExtensionCallback(
273 274 hook_name='PRE_PULL_HOOK',
274 275 kwargs_keys=(
275 276 'server_url', 'config', 'scm', 'username', 'ip', 'action',
276 277 'repository'))
277 278
278 279
279 280 post_pull_extension = ExtensionCallback(
280 281 hook_name='PULL_HOOK',
281 282 kwargs_keys=(
282 283 'server_url', 'config', 'scm', 'username', 'ip', 'action',
283 284 'repository'))
284 285
285 286
286 287 pre_push_extension = ExtensionCallback(
287 288 hook_name='PRE_PUSH_HOOK',
288 289 kwargs_keys=(
289 290 'server_url', 'config', 'scm', 'username', 'ip', 'action',
290 'repository', 'repo_store_path'))
291 'repository', 'repo_store_path', 'commit_ids'))
291 292
292 293
293 294 post_push_extension = ExtensionCallback(
294 295 hook_name='PUSH_HOOK',
295 296 kwargs_keys=(
296 297 'server_url', 'config', 'scm', 'username', 'ip', 'action',
297 298 'repository', 'repo_store_path', 'pushed_revs'))
298 299
299 300
300 301 pre_create_user = ExtensionCallback(
301 302 hook_name='PRE_CREATE_USER_HOOK',
302 303 kwargs_keys=(
303 304 'username', 'password', 'email', 'firstname', 'lastname', 'active',
304 305 'admin', 'created_by'))
305 306
306 307
307 308 log_create_pull_request = ExtensionCallback(
308 309 hook_name='CREATE_PULL_REQUEST',
309 310 kwargs_keys=(
310 311 'server_url', 'config', 'scm', 'username', 'ip', 'action',
311 312 'repository', 'pull_request_id', 'url', 'title', 'description',
312 313 'status', 'created_on', 'updated_on', 'commit_ids', 'review_status',
313 314 'mergeable', 'source', 'target', 'author', 'reviewers'))
314 315
315 316
316 317 log_merge_pull_request = ExtensionCallback(
317 318 hook_name='MERGE_PULL_REQUEST',
318 319 kwargs_keys=(
319 320 'server_url', 'config', 'scm', 'username', 'ip', 'action',
320 321 'repository', 'pull_request_id', 'url', 'title', 'description',
321 322 'status', 'created_on', 'updated_on', 'commit_ids', 'review_status',
322 323 'mergeable', 'source', 'target', 'author', 'reviewers'))
323 324
324 325
325 326 log_close_pull_request = ExtensionCallback(
326 327 hook_name='CLOSE_PULL_REQUEST',
327 328 kwargs_keys=(
328 329 'server_url', 'config', 'scm', 'username', 'ip', 'action',
329 330 'repository', 'pull_request_id', 'url', 'title', 'description',
330 331 'status', 'created_on', 'updated_on', 'commit_ids', 'review_status',
331 332 'mergeable', 'source', 'target', 'author', 'reviewers'))
332 333
333 334
334 335 log_review_pull_request = ExtensionCallback(
335 336 hook_name='REVIEW_PULL_REQUEST',
336 337 kwargs_keys=(
337 338 'server_url', 'config', 'scm', 'username', 'ip', 'action',
338 339 'repository', 'pull_request_id', 'url', 'title', 'description',
339 340 'status', 'created_on', 'updated_on', 'commit_ids', 'review_status',
340 341 'mergeable', 'source', 'target', 'author', 'reviewers'))
341 342
342 343
343 344 log_update_pull_request = ExtensionCallback(
344 345 hook_name='UPDATE_PULL_REQUEST',
345 346 kwargs_keys=(
346 347 'server_url', 'config', 'scm', 'username', 'ip', 'action',
347 348 'repository', 'pull_request_id', 'url', 'title', 'description',
348 349 'status', 'created_on', 'updated_on', 'commit_ids', 'review_status',
349 350 'mergeable', 'source', 'target', 'author', 'reviewers'))
350 351
351 352
352 353 log_create_user = ExtensionCallback(
353 354 hook_name='CREATE_USER_HOOK',
354 355 kwargs_keys=(
355 356 'username', 'full_name_or_username', 'full_contact', 'user_id',
356 357 'name', 'firstname', 'short_contact', 'admin', 'lastname',
357 358 'ip_addresses', 'extern_type', 'extern_name',
358 359 'email', 'api_key', 'api_keys', 'last_login',
359 360 'full_name', 'active', 'password', 'emails',
360 361 'inherit_default_permissions', 'created_by', 'created_on'))
361 362
362 363
363 364 log_delete_user = ExtensionCallback(
364 365 hook_name='DELETE_USER_HOOK',
365 366 kwargs_keys=(
366 367 'username', 'full_name_or_username', 'full_contact', 'user_id',
367 368 'name', 'firstname', 'short_contact', 'admin', 'lastname',
368 369 'ip_addresses',
369 370 'email', 'api_key', 'last_login',
370 371 'full_name', 'active', 'password', 'emails',
371 372 'inherit_default_permissions', 'deleted_by'))
372 373
373 374
374 375 log_create_repository = ExtensionCallback(
375 376 hook_name='CREATE_REPO_HOOK',
376 377 kwargs_keys=(
377 378 'repo_name', 'repo_type', 'description', 'private', 'created_on',
378 379 'enable_downloads', 'repo_id', 'user_id', 'enable_statistics',
379 380 'clone_uri', 'fork_id', 'group_id', 'created_by'))
380 381
381 382
382 383 log_delete_repository = ExtensionCallback(
383 384 hook_name='DELETE_REPO_HOOK',
384 385 kwargs_keys=(
385 386 'repo_name', 'repo_type', 'description', 'private', 'created_on',
386 387 'enable_downloads', 'repo_id', 'user_id', 'enable_statistics',
387 388 'clone_uri', 'fork_id', 'group_id', 'deleted_by', 'deleted_on'))
388 389
389 390
390 391 log_create_repository_group = ExtensionCallback(
391 392 hook_name='CREATE_REPO_GROUP_HOOK',
392 393 kwargs_keys=(
393 394 'group_name', 'group_parent_id', 'group_description',
394 395 'group_id', 'user_id', 'created_by', 'created_on',
395 396 'enable_locking'))
@@ -1,520 +1,520 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 """
22 22 Reference example of the rcextensions module.
23 23
24 24 This module is also used during integration tests to verify that all showed
25 25 examples are valid.
26 26 """
27 27
28 28 import collections
29 29 import os
30 30 import imp
31 31
32 32 here = os.path.dirname(os.path.abspath(__file__))
33 33
34 34
35 35 def load_extension(filename, async=False):
36 36 """
37 37 use to load extensions inside rcextension folder.
38 38 for example::
39 39
40 40 callback = load_extension('email.py', async=False)
41 41 if callback:
42 42 callback('foobar')
43 43
44 44 put file named email.py inside rcextensions folder to load it. Changing
45 45 async=True will make the call of the plugin async, it's useful for
46 46 blocking calls like sending an email or notification with APIs.
47 47 """
48 48 mod = ''.join(filename.split('.')[:-1])
49 49 loaded = imp.load_source(mod, os.path.join(here, filename))
50 50
51 51 callback = getattr(loaded, 'run', None)
52 52 if not callback:
53 53 raise Exception('Plugin missing `run` method')
54 54 if async:
55 55 # modify callback so it's actually an async call
56 56 def _async_callback(*args, **kwargs):
57 57 import threading
58 58 thr = threading.Thread(target=callback, args=args, kwargs=kwargs)
59 59 thr.start()
60 60 if kwargs.get('_async_block'):
61 61 del kwargs['_async_block']
62 62 thr.join()
63 63
64 64 return _async_callback
65 65 return callback
66 66
67 67
68 68 # Additional mappings that are not present in the pygments lexers
69 69 # used for building stats
70 70 # format is {'ext':['Names']} eg. {'py':['Python']} note: there can be
71 71 # more than one name for extension
72 # NOTE: that this will overide any mappings in LANGUAGES_EXTENSIONS_MAP
72 # NOTE: that this will override any mappings in LANGUAGES_EXTENSIONS_MAP
73 73 # build by pygments
74 74 EXTRA_MAPPINGS = {}
75 75
76 76 # additional lexer definitions for custom files it's overrides pygments lexers,
77 77 # and uses defined name of lexer to colorize the files. Format is {'ext':
78 78 # 'lexer_name'} List of lexers can be printed running:
79 79 # >> python -c "import pprint;from pygments import lexers;
80 80 # pprint.pprint([(x[0], x[1]) for x in lexers.get_all_lexers()]);"
81 81
82 82 EXTRA_LEXERS = {}
83 83
84 84
85 85 calls = collections.defaultdict(list)
86 86
87 87
88 88 def log_call(name):
89 89 def wrap(f):
90 90 def wrapper(*args, **kwargs):
91 91 calls[name].append((args, kwargs))
92 92 return f(*args, **kwargs)
93 93 return wrapper
94 94 return wrap
95 95
96 96
97 97 # =============================================================================
98 98 # POST CREATE REPOSITORY HOOK
99 99 # =============================================================================
100 100 # this function will be executed after each repository is created
101 101
102 102
103 103 def _crrepohook(*args, **kwargs):
104 104 """
105 105 Post create repository HOOK
106 106 kwargs available:
107 107 :param repo_name:
108 108 :param repo_type:
109 109 :param description:
110 110 :param private:
111 111 :param created_on:
112 112 :param enable_downloads:
113 113 :param repo_id:
114 114 :param user_id:
115 115 :param enable_statistics:
116 116 :param clone_uri:
117 117 :param fork_id:
118 118 :param group_id:
119 119 :param created_by:
120 120 """
121 121
122 122 expected_parameters = (
123 123 'repo_name', 'repo_type', 'description', 'private', 'created_on',
124 124 'enable_downloads', 'repo_id', 'user_id', 'enable_statistics',
125 125 'clone_uri', 'fork_id', 'group_id', 'created_by')
126 126 _verify_kwargs(expected_parameters, kwargs)
127 127
128 128 return 0
129 129
130 130 CREATE_REPO_HOOK = _crrepohook
131 131
132 132
133 133 # =============================================================================
134 134 # POST CREATE REPOSITORY GROUP HOOK
135 135 # =============================================================================
136 136 # this function will be executed after each repository group is created
137 137
138 138
139 139 def _crrepogrouphook(*args, **kwargs):
140 140 """
141 141 Post create repository group HOOK
142 142 kwargs available:
143 143
144 144 :param group_name:
145 145 :param group_parent_id:
146 146 :param group_description:
147 147 :param group_id:
148 148 :param user_id:
149 149 :param created_by:
150 150 :param created_on:
151 151 :param enable_locking:
152 152 """
153 153
154 154 expected_parameters = (
155 155 'group_name', 'group_parent_id', 'group_description',
156 156 'group_id', 'user_id', 'created_by', 'created_on',
157 157 'enable_locking')
158 158 _verify_kwargs(expected_parameters, kwargs)
159 159
160 160 return 0
161 161
162 162 CREATE_REPO_GROUP_HOOK = _crrepogrouphook
163 163
164 164 # =============================================================================
165 165 # PRE CREATE USER HOOK
166 166 # =============================================================================
167 167 # this function will be executed before each user is created
168 168
169 169
170 170 def _pre_cruserhook(*args, **kwargs):
171 171 """
172 172 Pre create user HOOK, it returns a tuple of bool, reason.
173 173 If bool is False the user creation will be stopped and reason
174 174 will be displayed to the user.
175 175 kwargs available:
176 176 :param username:
177 177 :param password:
178 178 :param email:
179 179 :param firstname:
180 180 :param lastname:
181 181 :param active:
182 182 :param admin:
183 183 :param created_by:
184 184 """
185 185
186 186 expected_parameters = (
187 187 'username', 'password', 'email', 'firstname', 'lastname', 'active',
188 188 'admin', 'created_by')
189 189 _verify_kwargs(expected_parameters, kwargs)
190 190
191 191 reason = 'allowed'
192 192 return True, reason
193 193 PRE_CREATE_USER_HOOK = _pre_cruserhook
194 194
195 195 # =============================================================================
196 196 # POST CREATE USER HOOK
197 197 # =============================================================================
198 198 # this function will be executed after each user is created
199 199
200 200
201 201 def _cruserhook(*args, **kwargs):
202 202 """
203 203 Post create user HOOK
204 204 kwargs available:
205 205 :param username:
206 206 :param full_name_or_username:
207 207 :param full_contact:
208 208 :param user_id:
209 209 :param name:
210 210 :param firstname:
211 211 :param short_contact:
212 212 :param admin:
213 213 :param lastname:
214 214 :param ip_addresses:
215 215 :param extern_type:
216 216 :param extern_name:
217 217 :param email:
218 218 :param api_key:
219 219 :parma api_keys:
220 220 :param last_login:
221 221 :param full_name:
222 222 :param active:
223 223 :param password:
224 224 :param emails:
225 225 :param inherit_default_permissions:
226 226 :param created_by:
227 227 :param created_on:
228 228 """
229 229
230 230 expected_parameters = (
231 231 'username', 'full_name_or_username', 'full_contact', 'user_id',
232 232 'name', 'firstname', 'short_contact', 'admin', 'lastname',
233 233 'ip_addresses', 'extern_type', 'extern_name',
234 234 'email', 'api_key', 'api_keys', 'last_login',
235 235 'full_name', 'active', 'password', 'emails',
236 236 'inherit_default_permissions', 'created_by', 'created_on')
237 237 _verify_kwargs(expected_parameters, kwargs)
238 238
239 239 return 0
240 240 CREATE_USER_HOOK = _cruserhook
241 241
242 242
243 243 # =============================================================================
244 244 # POST DELETE REPOSITORY HOOK
245 245 # =============================================================================
246 246 # this function will be executed after each repository deletion
247 247
248 248
249 249 def _dlrepohook(*args, **kwargs):
250 250 """
251 251 Post delete repository HOOK
252 252 kwargs available:
253 253 :param repo_name:
254 254 :param repo_type:
255 255 :param description:
256 256 :param private:
257 257 :param created_on:
258 258 :param enable_downloads:
259 259 :param repo_id:
260 260 :param user_id:
261 261 :param enable_statistics:
262 262 :param clone_uri:
263 263 :param fork_id:
264 264 :param group_id:
265 265 :param deleted_by:
266 266 :param deleted_on:
267 267 """
268 268
269 269 expected_parameters = (
270 270 'repo_name', 'repo_type', 'description', 'private', 'created_on',
271 271 'enable_downloads', 'repo_id', 'user_id', 'enable_statistics',
272 272 'clone_uri', 'fork_id', 'group_id', 'deleted_by', 'deleted_on')
273 273 _verify_kwargs(expected_parameters, kwargs)
274 274
275 275 return 0
276 276 DELETE_REPO_HOOK = _dlrepohook
277 277
278 278
279 279 # =============================================================================
280 280 # POST DELETE USER HOOK
281 281 # =============================================================================
282 282 # this function will be executed after each user is deleted
283 283
284 284
285 285 def _dluserhook(*args, **kwargs):
286 286 """
287 287 Post delete user HOOK
288 288 kwargs available:
289 289 :param username:
290 290 :param full_name_or_username:
291 291 :param full_contact:
292 292 :param user_id:
293 293 :param name:
294 294 :param firstname:
295 295 :param short_contact:
296 296 :param admin:
297 297 :param lastname:
298 298 :param ip_addresses:
299 299 :param ldap_dn:
300 300 :param email:
301 301 :param api_key:
302 302 :param last_login:
303 303 :param full_name:
304 304 :param active:
305 305 :param password:
306 306 :param emails:
307 307 :param inherit_default_permissions:
308 308 :param deleted_by:
309 309 """
310 310
311 311 expected_parameters = (
312 312 'username', 'full_name_or_username', 'full_contact', 'user_id',
313 313 'name', 'firstname', 'short_contact', 'admin', 'lastname',
314 314 'ip_addresses',
315 315 # TODO: johbo: Check what's the status with the ldap_dn parameter
316 316 # 'ldap_dn',
317 317 'email', 'api_key', 'last_login',
318 318 'full_name', 'active', 'password', 'emails',
319 319 'inherit_default_permissions', 'deleted_by')
320 320 _verify_kwargs(expected_parameters, kwargs)
321 321
322 322 return 0
323 323 DELETE_USER_HOOK = _dluserhook
324 324
325 325
326 326 # =============================================================================
327 327 # PRE PUSH HOOK
328 328 # =============================================================================
329 329
330 330
331 331 # this function will be executed after each push it's executed after the
332 332 # build-in hook that RhodeCode uses for logging pushes
333 333 @log_call('pre_push')
334 334 def _prepushhook(*args, **kwargs):
335 335 """
336 336 Pre push hook
337 337 kwargs available:
338 338
339 339 :param server_url: url of instance that triggered this hook
340 340 :param config: path to .ini config used
341 341 :param scm: type of VS 'git' or 'hg'
342 342 :param username: name of user who pushed
343 343 :param ip: ip of who pushed
344 344 :param action: push
345 345 :param repository: repository name
346 346 :param repo_store_path: full path to where repositories are stored
347 347 """
348 348
349 349 expected_parameters = (
350 350 'server_url', 'config', 'scm', 'username', 'ip', 'action',
351 'repository', 'repo_store_path')
351 'repository', 'repo_store_path', 'commit_ids')
352 352 _verify_kwargs(expected_parameters, kwargs)
353 353
354 354 return 0
355 355 PRE_PUSH_HOOK = _prepushhook
356 356
357 357
358 358 # =============================================================================
359 359 # POST PUSH HOOK
360 360 # =============================================================================
361 361
362 362
363 363 # this function will be executed after each push it's executed after the
364 364 # build-in hook that RhodeCode uses for logging pushes
365 365 @log_call('post_push')
366 366 def _pushhook(*args, **kwargs):
367 367 """
368 368 Post push hook
369 369 kwargs available:
370 370
371 371 :param server_url: url of instance that triggered this hook
372 372 :param config: path to .ini config used
373 373 :param scm: type of VS 'git' or 'hg'
374 374 :param username: name of user who pushed
375 375 :param ip: ip of who pushed
376 376 :param action: push
377 377 :param repository: repository name
378 378 :param repo_store_path: full path to where repositories are stored
379 379 :param pushed_revs: list of pushed revisions
380 380 """
381 381
382 382 expected_parameters = (
383 383 'server_url', 'config', 'scm', 'username', 'ip', 'action',
384 384 'repository', 'repo_store_path', 'pushed_revs')
385 385 _verify_kwargs(expected_parameters, kwargs)
386 386
387 387 return 0
388 388 PUSH_HOOK = _pushhook
389 389
390 390
391 391 # =============================================================================
392 392 # PRE PULL HOOK
393 393 # =============================================================================
394 394
395 395 # this function will be executed after each push it's executed after the
396 396 # build-in hook that RhodeCode uses for logging pulls
397 397 def _prepullhook(*args, **kwargs):
398 398 """
399 399 Post pull hook
400 400 kwargs available::
401 401
402 402 :param server_url: url of instance that triggered this hook
403 403 :param config: path to .ini config used
404 404 :param scm: type of VS 'git' or 'hg'
405 405 :param username: name of user who pulled
406 406 :param ip: ip of who pulled
407 407 :param action: pull
408 408 :param repository: repository name
409 409 """
410 410
411 411 expected_parameters = (
412 412 'server_url', 'config', 'scm', 'username', 'ip', 'action',
413 413 'repository')
414 414 _verify_kwargs(expected_parameters, kwargs)
415 415
416 416 return 0
417 417 PRE_PULL_HOOK = _prepullhook
418 418
419 419
420 420
421 421 # =============================================================================
422 422 # POST PULL HOOK
423 423 # =============================================================================
424 424
425 425 # this function will be executed after each push it's executed after the
426 426 # build-in hook that RhodeCode uses for logging pulls
427 427 def _pullhook(*args, **kwargs):
428 428 """
429 429 Post pull hook
430 430 kwargs available::
431 431
432 432 :param server_url: url of instance that triggered this hook
433 433 :param config: path to .ini config used
434 434 :param scm: type of VS 'git' or 'hg'
435 435 :param username: name of user who pulled
436 436 :param ip: ip of who pulled
437 437 :param action: pull
438 438 :param repository: repository name
439 439 """
440 440
441 441 expected_parameters = (
442 442 'server_url', 'config', 'scm', 'username', 'ip', 'action',
443 443 'repository')
444 444 _verify_kwargs(expected_parameters, kwargs)
445 445
446 446 return 0
447 447 PULL_HOOK = _pullhook
448 448
449 449
450 450 # =============================================================================
451 451 # PULL REQUEST RELATED HOOKS
452 452 # =============================================================================
453 453
454 454 def _create_pull_request_hook(*args, **kwargs):
455 455 expected_parameters = (
456 456 'server_url', 'config', 'scm', 'username', 'ip', 'action',
457 457 'repository', 'pull_request_id', 'url', 'title', 'description',
458 458 'status', 'created_on', 'updated_on', 'commit_ids', 'review_status',
459 459 'mergeable', 'source', 'target', 'author', 'reviewers')
460 460 _verify_kwargs(expected_parameters, kwargs)
461 461 return 0
462 462 CREATE_PULL_REQUEST = _create_pull_request_hook
463 463
464 464
465 465 def _merge_pull_request_hook(*args, **kwargs):
466 466 expected_parameters = (
467 467 'server_url', 'config', 'scm', 'username', 'ip', 'action',
468 468 'repository', 'pull_request_id', 'url', 'title', 'description',
469 469 'status', 'created_on', 'updated_on', 'commit_ids', 'review_status',
470 470 'mergeable', 'source', 'target', 'author', 'reviewers')
471 471 _verify_kwargs(expected_parameters, kwargs)
472 472 return 0
473 473 MERGE_PULL_REQUEST = _merge_pull_request_hook
474 474
475 475
476 476 def _close_pull_request_hook(*args, **kwargs):
477 477 expected_parameters = (
478 478 'server_url', 'config', 'scm', 'username', 'ip', 'action',
479 479 'repository', 'pull_request_id', 'url', 'title', 'description',
480 480 'status', 'created_on', 'updated_on', 'commit_ids', 'review_status',
481 481 'mergeable', 'source', 'target', 'author', 'reviewers')
482 482 _verify_kwargs(expected_parameters, kwargs)
483 483 return 0
484 484 CLOSE_PULL_REQUEST = _close_pull_request_hook
485 485
486 486
487 487 def _review_pull_request_hook(*args, **kwargs):
488 488 expected_parameters = (
489 489 'server_url', 'config', 'scm', 'username', 'ip', 'action',
490 490 'repository', 'pull_request_id', 'url', 'title', 'description',
491 491 'status', 'created_on', 'updated_on', 'commit_ids', 'review_status',
492 492 'mergeable', 'source', 'target', 'author', 'reviewers')
493 493 _verify_kwargs(expected_parameters, kwargs)
494 494 return 0
495 495 REVIEW_PULL_REQUEST = _review_pull_request_hook
496 496
497 497
498 498 def _update_pull_request_hook(*args, **kwargs):
499 499 expected_parameters = (
500 500 'server_url', 'config', 'scm', 'username', 'ip', 'action',
501 501 'repository', 'pull_request_id', 'url', 'title', 'description',
502 502 'status', 'created_on', 'updated_on', 'commit_ids', 'review_status',
503 503 'mergeable', 'source', 'target', 'author', 'reviewers')
504 504 _verify_kwargs(expected_parameters, kwargs)
505 505 return 0
506 506 UPDATE_PULL_REQUEST = _update_pull_request_hook
507 507
508 508
509 509 def _verify_kwargs(expected_parameters, kwargs):
510 510 """
511 511 Verify that exactly `expected_parameters` are passed in as `kwargs`.
512 512 """
513 513 expected_parameters = set(expected_parameters)
514 514 kwargs_keys = set(kwargs.keys())
515 515 if kwargs_keys != expected_parameters:
516 516 missing_kwargs = expected_parameters - kwargs_keys
517 517 unexpected_kwargs = kwargs_keys - expected_parameters
518 518 raise AssertionError(
519 "Missing parameters: %r, unexpected parameters: %s" %
519 "rcextensions: Missing parameters: %r, unexpected parameters: %s" %
520 520 (missing_kwargs, unexpected_kwargs))
General Comments 0
You need to be logged in to leave comments. Login now