Changeset - 833b93e83349
[Not reviewed]
default
0 3 0
Thomas De Schampheleire - 5 years ago 2020-06-15 13:43:55
thomas.de_schampheleire@nokia.com
hooks: add extensible create-pullrequest hook

Add a hook that will be called when a new pull request is created, and which
can be implemented in the 'extensions' package.
3 files changed with 38 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/config/rcextensions/__init__.py
Show inline comments
 
@@ -104,6 +104,28 @@ def CREATE_USER_HOOK(*args, **kwargs):
 

	
 

	
 
#==============================================================================
 
# POST CREATE PULLREQUEST HOOK
 
#==============================================================================
 
# this function will be executed after a pull request is created
 
def CREATE_PULLREQUEST_HOOK(*args, **kwargs):
 
    """
 
    Post create pull request HOOK
 
    kwargs available:
 
      :param pull_request_id:
 
      :param title:
 
      :param description:
 
      :param created_on:
 
      :param org_repo_id:
 
      :param org_ref:
 
      :param other_repo_id:
 
      :param other_ref:
 
      :param created_by:
 
    There are other fields in 'class PullRequest' (kallithea/model/db.py) which
 
    may or may not be useful for this hook.
 
    """
 

	
 

	
 
#==============================================================================
 
# POST DELETE REPOSITORY HOOK
 
#==============================================================================
 
# this function will be executed after each repository deletion
kallithea/lib/hooks.py
Show inline comments
 
@@ -218,6 +218,19 @@ def log_create_user(user_dict, created_b
 
        callback(created_by=created_by, **user_dict)
 

	
 

	
 
def log_create_pullrequest(pullrequest_dict, created_by, **kwargs):
 
    """
 
    Post create pull request hook.
 

	
 
    :param pullrequest_dict: dict dump of pull request object
 
    """
 
    from kallithea import EXTENSIONS
 
    callback = getattr(EXTENSIONS, 'CREATE_PULLREQUEST_HOOK', None)
 
    if callable(callback):
 
        return callback(created_by=created_by, **pullrequest_dict)
 

	
 
    return 0
 

	
 
def log_delete_repository(repository_dict, deleted_by, **kwargs):
 
    """
 
    Post delete repository Hook.
kallithea/model/pull_request.py
Show inline comments
 
@@ -33,6 +33,7 @@ from tg import request
 
from tg.i18n import ugettext as _
 

	
 
from kallithea.lib import helpers as h
 
from kallithea.lib.hooks import log_create_pullrequest
 
from kallithea.lib.utils2 import ascii_bytes, extract_mentioned_users
 
from kallithea.model.db import ChangesetStatus, PullRequest, PullRequestReviewer, User
 
from kallithea.model.meta import Session
 
@@ -296,6 +297,8 @@ class CreatePullRequestAction(object):
 
        mention_recipients = extract_mentioned_users(self.description)
 
        PullRequestModel().add_reviewers(created_by, pr, self.reviewers, mention_recipients)
 

	
 
        log_create_pullrequest(pr.get_dict(), created_by)
 

	
 
        return pr
 

	
 

	
0 comments (0 inline, 0 general)