##// END OF EJS Templates
comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which...
marcink -
r4445:5a5c90c0 default
parent child Browse files
Show More
@@ -26,6 +26,7 b' from .hooks import ('
26 26 _pre_create_user_hook,
27 27 _create_user_hook,
28 28 _comment_commit_repo_hook,
29 _comment_edit_commit_repo_hook,
29 30 _delete_repo_hook,
30 31 _delete_user_hook,
31 32 _pre_push_hook,
@@ -35,6 +36,7 b' from .hooks import ('
35 36 _create_pull_request_hook,
36 37 _review_pull_request_hook,
37 38 _comment_pull_request_hook,
39 _comment_edit_pull_request_hook,
38 40 _update_pull_request_hook,
39 41 _merge_pull_request_hook,
40 42 _close_pull_request_hook,
@@ -43,6 +45,7 b' from .hooks import ('
43 45 # set as module attributes, we use those to call hooks. *do not change this*
44 46 CREATE_REPO_HOOK = _create_repo_hook
45 47 COMMENT_COMMIT_REPO_HOOK = _comment_commit_repo_hook
48 COMMENT_EDIT_COMMIT_REPO_HOOK = _comment_edit_commit_repo_hook
46 49 CREATE_REPO_GROUP_HOOK = _create_repo_group_hook
47 50 PRE_CREATE_USER_HOOK = _pre_create_user_hook
48 51 CREATE_USER_HOOK = _create_user_hook
@@ -55,6 +58,7 b' PULL_HOOK = _pull_hook'
55 58 CREATE_PULL_REQUEST = _create_pull_request_hook
56 59 REVIEW_PULL_REQUEST = _review_pull_request_hook
57 60 COMMENT_PULL_REQUEST = _comment_pull_request_hook
61 COMMENT_EDIT_PULL_REQUEST = _comment_edit_pull_request_hook
58 62 UPDATE_PULL_REQUEST = _update_pull_request_hook
59 63 MERGE_PULL_REQUEST = _merge_pull_request_hook
60 64 CLOSE_PULL_REQUEST = _close_pull_request_hook
@@ -83,6 +83,33 b' def _comment_commit_repo_hook(*args, **k'
83 83
84 84
85 85 @has_kwargs({
86 'repo_name': '',
87 'repo_type': '',
88 'description': '',
89 'private': '',
90 'created_on': '',
91 'enable_downloads': '',
92 'repo_id': '',
93 'user_id': '',
94 'enable_statistics': '',
95 'clone_uri': '',
96 'fork_id': '',
97 'group_id': '',
98 'created_by': '',
99 'repository': '',
100 'comment': '',
101 'commit': ''
102 })
103 def _comment_edit_commit_repo_hook(*args, **kwargs):
104 """
105 POST CREATE REPOSITORY COMMENT ON COMMIT HOOK. This function will be executed after
106 a comment is made on this repository commit.
107
108 """
109 return HookResponse(0, '')
110
111
112 @has_kwargs({
86 113 'group_name': '',
87 114 'group_parent_id': '',
88 115 'group_description': '',
@@ -408,6 +435,38 b' def _comment_pull_request_hook(*args, **'
408 435 'scm': 'type of version control "git", "hg", "svn"',
409 436 'username': 'username of actor who triggered this event',
410 437 'ip': 'ip address of actor who triggered this hook',
438
439 'action': '',
440 'repository': 'repository name',
441 'pull_request_id': '',
442 'url': '',
443 'title': '',
444 'description': '',
445 'status': '',
446 'comment': '',
447 'created_on': '',
448 'updated_on': '',
449 'commit_ids': '',
450 'review_status': '',
451 'mergeable': '',
452 'source': '',
453 'target': '',
454 'author': '',
455 'reviewers': '',
456 })
457 def _comment_edit_pull_request_hook(*args, **kwargs):
458 """
459 This hook will be executed after comment is made on a pull request
460 """
461 return HookResponse(0, '')
462
463
464 @has_kwargs({
465 'server_url': 'url of instance that triggered this hook',
466 'config': 'path to .ini config used',
467 'scm': 'type of version control "git", "hg", "svn"',
468 'username': 'username of actor who triggered this event',
469 'ip': 'ip address of actor who triggered this hook',
411 470 'action': '',
412 471 'repository': 'repository name',
413 472 'pull_request_id': '',
@@ -33,7 +33,7 b' from pyramid_mailer.message import Messa'
33 33 import rhodecode
34 34 from rhodecode.lib import audit_logger
35 35 from rhodecode.lib.celerylib import get_logger, async_task, RequestContextTask
36 from rhodecode.lib.hooks_base import log_create_repository
36 from rhodecode.lib import hooks_base
37 37 from rhodecode.lib.utils2 import safe_int, str2bool
38 38 from rhodecode.model.db import (
39 39 Session, IntegrityError, true, Repository, RepoGroup, User)
@@ -187,7 +187,7 b' def create_repo(form_data, cur_user):'
187 187 clone_uri=clone_uri,
188 188 )
189 189 repo = Repository.get_by_repo_name(repo_name_full)
190 log_create_repository(created_by=owner.username, **repo.get_dict())
190 hooks_base.create_repository(created_by=owner.username, **repo.get_dict())
191 191
192 192 # update repo commit caches initially
193 193 repo.update_commit_cache()
@@ -273,7 +273,7 b' def create_repo_fork(form_data, cur_user'
273 273 clone_uri=source_repo_path,
274 274 )
275 275 repo = Repository.get_by_repo_name(repo_name_full)
276 log_create_repository(created_by=owner.username, **repo.get_dict())
276 hooks_base.create_repository(created_by=owner.username, **repo.get_dict())
277 277
278 278 # update repo commit caches initially
279 279 config = repo._config
@@ -400,7 +400,7 b' pre_create_user = ExtensionCallback('
400 400 'admin', 'created_by'))
401 401
402 402
403 log_create_pull_request = ExtensionCallback(
403 create_pull_request = ExtensionCallback(
404 404 hook_name='CREATE_PULL_REQUEST',
405 405 kwargs_keys=(
406 406 'server_url', 'config', 'scm', 'username', 'ip', 'action',
@@ -409,7 +409,7 b' log_create_pull_request = ExtensionCallb'
409 409 'mergeable', 'source', 'target', 'author', 'reviewers'))
410 410
411 411
412 log_merge_pull_request = ExtensionCallback(
412 merge_pull_request = ExtensionCallback(
413 413 hook_name='MERGE_PULL_REQUEST',
414 414 kwargs_keys=(
415 415 'server_url', 'config', 'scm', 'username', 'ip', 'action',
@@ -418,7 +418,7 b' log_merge_pull_request = ExtensionCallba'
418 418 'mergeable', 'source', 'target', 'author', 'reviewers'))
419 419
420 420
421 log_close_pull_request = ExtensionCallback(
421 close_pull_request = ExtensionCallback(
422 422 hook_name='CLOSE_PULL_REQUEST',
423 423 kwargs_keys=(
424 424 'server_url', 'config', 'scm', 'username', 'ip', 'action',
@@ -427,7 +427,7 b' log_close_pull_request = ExtensionCallba'
427 427 'mergeable', 'source', 'target', 'author', 'reviewers'))
428 428
429 429
430 log_review_pull_request = ExtensionCallback(
430 review_pull_request = ExtensionCallback(
431 431 hook_name='REVIEW_PULL_REQUEST',
432 432 kwargs_keys=(
433 433 'server_url', 'config', 'scm', 'username', 'ip', 'action',
@@ -436,7 +436,7 b' log_review_pull_request = ExtensionCallb'
436 436 'mergeable', 'source', 'target', 'author', 'reviewers'))
437 437
438 438
439 log_comment_pull_request = ExtensionCallback(
439 comment_pull_request = ExtensionCallback(
440 440 hook_name='COMMENT_PULL_REQUEST',
441 441 kwargs_keys=(
442 442 'server_url', 'config', 'scm', 'username', 'ip', 'action',
@@ -445,7 +445,16 b' log_comment_pull_request = ExtensionCall'
445 445 'mergeable', 'source', 'target', 'author', 'reviewers'))
446 446
447 447
448 log_update_pull_request = ExtensionCallback(
448 comment_edit_pull_request = ExtensionCallback(
449 hook_name='COMMENT_EDIT_PULL_REQUEST',
450 kwargs_keys=(
451 'server_url', 'config', 'scm', 'username', 'ip', 'action',
452 'repository', 'pull_request_id', 'url', 'title', 'description',
453 'status', 'comment', 'created_on', 'updated_on', 'commit_ids', 'review_status',
454 'mergeable', 'source', 'target', 'author', 'reviewers'))
455
456
457 update_pull_request = ExtensionCallback(
449 458 hook_name='UPDATE_PULL_REQUEST',
450 459 kwargs_keys=(
451 460 'server_url', 'config', 'scm', 'username', 'ip', 'action',
@@ -454,7 +463,7 b' log_update_pull_request = ExtensionCallb'
454 463 'mergeable', 'source', 'target', 'author', 'reviewers'))
455 464
456 465
457 log_create_user = ExtensionCallback(
466 create_user = ExtensionCallback(
458 467 hook_name='CREATE_USER_HOOK',
459 468 kwargs_keys=(
460 469 'username', 'full_name_or_username', 'full_contact', 'user_id',
@@ -465,7 +474,7 b' log_create_user = ExtensionCallback('
465 474 'inherit_default_permissions', 'created_by', 'created_on'))
466 475
467 476
468 log_delete_user = ExtensionCallback(
477 delete_user = ExtensionCallback(
469 478 hook_name='DELETE_USER_HOOK',
470 479 kwargs_keys=(
471 480 'username', 'full_name_or_username', 'full_contact', 'user_id',
@@ -476,7 +485,7 b' log_delete_user = ExtensionCallback('
476 485 'inherit_default_permissions', 'deleted_by'))
477 486
478 487
479 log_create_repository = ExtensionCallback(
488 create_repository = ExtensionCallback(
480 489 hook_name='CREATE_REPO_HOOK',
481 490 kwargs_keys=(
482 491 'repo_name', 'repo_type', 'description', 'private', 'created_on',
@@ -484,7 +493,7 b' log_create_repository = ExtensionCallbac'
484 493 'clone_uri', 'fork_id', 'group_id', 'created_by'))
485 494
486 495
487 log_delete_repository = ExtensionCallback(
496 delete_repository = ExtensionCallback(
488 497 hook_name='DELETE_REPO_HOOK',
489 498 kwargs_keys=(
490 499 'repo_name', 'repo_type', 'description', 'private', 'created_on',
@@ -492,7 +501,7 b' log_delete_repository = ExtensionCallbac'
492 501 'clone_uri', 'fork_id', 'group_id', 'deleted_by', 'deleted_on'))
493 502
494 503
495 log_comment_commit_repository = ExtensionCallback(
504 comment_commit_repository = ExtensionCallback(
496 505 hook_name='COMMENT_COMMIT_REPO_HOOK',
497 506 kwargs_keys=(
498 507 'repo_name', 'repo_type', 'description', 'private', 'created_on',
@@ -500,8 +509,16 b' log_comment_commit_repository = Extensio'
500 509 'clone_uri', 'fork_id', 'group_id',
501 510 'repository', 'created_by', 'comment', 'commit'))
502 511
512 comment_edit_commit_repository = ExtensionCallback(
513 hook_name='COMMENT_EDIT_COMMIT_REPO_HOOK',
514 kwargs_keys=(
515 'repo_name', 'repo_type', 'description', 'private', 'created_on',
516 'enable_downloads', 'repo_id', 'user_id', 'enable_statistics',
517 'clone_uri', 'fork_id', 'group_id',
518 'repository', 'created_by', 'comment', 'commit'))
503 519
504 log_create_repository_group = ExtensionCallback(
520
521 create_repository_group = ExtensionCallback(
505 522 hook_name='CREATE_REPO_GROUP_HOOK',
506 523 kwargs_keys=(
507 524 'group_name', 'group_parent_id', 'group_description',
@@ -94,7 +94,7 b' def trigger_comment_commit_hooks(usernam'
94 94 extras.commit = commit.serialize()
95 95 extras.comment = comment.get_api_data()
96 96 extras.created_by = username
97 hooks_base.log_comment_commit_repository(**extras)
97 hooks_base.comment_commit_repository(**extras)
98 98
99 99
100 100 def trigger_comment_commit_edit_hooks(username, repo_name, repo_type, repo, data=None):
@@ -121,8 +121,7 b' def trigger_comment_commit_edit_hooks(us'
121 121 extras.commit = commit.serialize()
122 122 extras.comment = comment.get_api_data()
123 123 extras.created_by = username
124 # TODO(marcink): rcextensions handlers ??
125 hooks_base.log_comment_commit_repository(**extras)
124 hooks_base.comment_edit_commit_repository(**extras)
126 125
127 126
128 127 def trigger_create_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
@@ -141,7 +140,7 b' def trigger_create_pull_request_hook(use'
141 140 extras = _get_vcs_operation_context(username, repo_name, repo_type, 'create_pull_request')
142 141 events.trigger(events.PullRequestCreateEvent(pull_request))
143 142 extras.update(pull_request.get_api_data(with_merge_state=False))
144 hooks_base.log_create_pull_request(**extras)
143 hooks_base.create_pull_request(**extras)
145 144
146 145
147 146 def trigger_merge_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
@@ -160,7 +159,7 b' def trigger_merge_pull_request_hook(user'
160 159 extras = _get_vcs_operation_context(username, repo_name, repo_type, 'merge_pull_request')
161 160 events.trigger(events.PullRequestMergeEvent(pull_request))
162 161 extras.update(pull_request.get_api_data())
163 hooks_base.log_merge_pull_request(**extras)
162 hooks_base.merge_pull_request(**extras)
164 163
165 164
166 165 def trigger_close_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
@@ -179,7 +178,7 b' def trigger_close_pull_request_hook(user'
179 178 extras = _get_vcs_operation_context(username, repo_name, repo_type, 'close_pull_request')
180 179 events.trigger(events.PullRequestCloseEvent(pull_request))
181 180 extras.update(pull_request.get_api_data())
182 hooks_base.log_close_pull_request(**extras)
181 hooks_base.close_pull_request(**extras)
183 182
184 183
185 184 def trigger_review_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
@@ -199,7 +198,7 b' def trigger_review_pull_request_hook(use'
199 198 status = data.get('status')
200 199 events.trigger(events.PullRequestReviewEvent(pull_request, status))
201 200 extras.update(pull_request.get_api_data())
202 hooks_base.log_review_pull_request(**extras)
201 hooks_base.review_pull_request(**extras)
203 202
204 203
205 204 def trigger_comment_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
@@ -221,7 +220,7 b' def trigger_comment_pull_request_hook(us'
221 220 events.trigger(events.PullRequestCommentEvent(pull_request, comment))
222 221 extras.update(pull_request.get_api_data())
223 222 extras.comment = comment.get_api_data()
224 hooks_base.log_comment_pull_request(**extras)
223 hooks_base.comment_pull_request(**extras)
225 224
226 225
227 226 def trigger_comment_pull_request_edit_hook(username, repo_name, repo_type, pull_request, data=None):
@@ -243,8 +242,7 b' def trigger_comment_pull_request_edit_ho'
243 242 events.trigger(events.PullRequestCommentEditEvent(pull_request, comment))
244 243 extras.update(pull_request.get_api_data())
245 244 extras.comment = comment.get_api_data()
246 # TODO(marcink): handle rcextensions...
247 hooks_base.log_comment_pull_request(**extras)
245 hooks_base.comment_edit_pull_request(**extras)
248 246
249 247
250 248 def trigger_update_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
@@ -263,4 +261,4 b' def trigger_update_pull_request_hook(use'
263 261 extras = _get_vcs_operation_context(username, repo_name, repo_type, 'update_pull_request')
264 262 events.trigger(events.PullRequestUpdateEvent(pull_request))
265 263 extras.update(pull_request.get_api_data())
266 hooks_base.log_update_pull_request(**extras)
264 hooks_base.update_pull_request(**extras)
@@ -33,7 +33,7 b' from rhodecode import events'
33 33 from rhodecode.lib.auth import HasUserGroupPermissionAny
34 34 from rhodecode.lib.caching_query import FromCache
35 35 from rhodecode.lib.exceptions import AttachedForksError, AttachedPullRequestsError
36 from rhodecode.lib.hooks_base import log_delete_repository
36 from rhodecode.lib import hooks_base
37 37 from rhodecode.lib.user_log_filter import user_log_filter
38 38 from rhodecode.lib.utils import make_db_config
39 39 from rhodecode.lib.utils2 import (
@@ -767,7 +767,7 b' class RepoModel(BaseModel):'
767 767 'deleted_by': cur_user,
768 768 'deleted_on': time.time(),
769 769 })
770 log_delete_repository(**old_repo_dict)
770 hooks_base.delete_repository(**old_repo_dict)
771 771 events.trigger(events.RepoDeleteEvent(repo))
772 772 except Exception:
773 773 log.error(traceback.format_exc())
@@ -308,13 +308,13 b' class RepoGroupModel(BaseModel):'
308 308 self._create_group(new_repo_group.group_name)
309 309
310 310 # trigger the post hook
311 from rhodecode.lib.hooks_base import log_create_repository_group
311 from rhodecode.lib import hooks_base
312 312 repo_group = RepoGroup.get_by_group_name(group_name)
313 313
314 314 # update repo group commit caches initially
315 315 repo_group.update_commit_cache()
316 316
317 log_create_repository_group(
317 hooks_base.create_repository_group(
318 318 created_by=user.username, **repo_group.get_dict())
319 319
320 320 # Trigger create event.
@@ -262,8 +262,7 b' class UserModel(BaseModel):'
262 262
263 263 from rhodecode.lib.auth import (
264 264 get_crypt_password, check_password)
265 from rhodecode.lib.hooks_base import (
266 log_create_user, check_allowed_create_user)
265 from rhodecode.lib import hooks_base
267 266
268 267 def _password_change(new_user, password):
269 268 old_password = new_user.password or ''
@@ -327,7 +326,7 b' class UserModel(BaseModel):'
327 326 if new_active_user and strict_creation_check:
328 327 # raises UserCreationError if it's not allowed for any reason to
329 328 # create new active user, this also executes pre-create hooks
330 check_allowed_create_user(user_data, cur_user, strict_check=True)
329 hooks_base.check_allowed_create_user(user_data, cur_user, strict_check=True)
331 330 events.trigger(events.UserPreCreate(user_data))
332 331 new_user = User()
333 332 edit = False
@@ -390,7 +389,7 b' class UserModel(BaseModel):'
390 389 kwargs = new_user.get_dict()
391 390 # backward compat, require api_keys present
392 391 kwargs['api_keys'] = kwargs['auth_tokens']
393 log_create_user(created_by=cur_user, **kwargs)
392 hooks_base.create_user(created_by=cur_user, **kwargs)
394 393 events.trigger(events.UserPostCreate(user_data))
395 394 return new_user
396 395 except (DatabaseError,):
@@ -569,7 +568,7 b' class UserModel(BaseModel):'
569 568 def delete(self, user, cur_user=None, handle_repos=None,
570 569 handle_repo_groups=None, handle_user_groups=None,
571 570 handle_pull_requests=None, handle_artifacts=None, handle_new_owner=None):
572 from rhodecode.lib.hooks_base import log_delete_user
571 from rhodecode.lib import hooks_base
573 572
574 573 if not cur_user:
575 574 cur_user = getattr(get_current_rhodecode_user(), 'username', None)
@@ -638,7 +637,7 b' class UserModel(BaseModel):'
638 637 self.sa.expire(user)
639 638 self.sa.delete(user)
640 639
641 log_delete_user(deleted_by=cur_user, **user_data)
640 hooks_base.delete_user(deleted_by=cur_user, **user_data)
642 641 except Exception:
643 642 log.error(traceback.format_exc())
644 643 raise
General Comments 0
You need to be logged in to leave comments. Login now