Developing Plugins/Extensions¶
An Extension or a Plugin is simply a Python module with a run
method that
expects a number of parameters, depending on which event it is listening
for. To get an extension working, use the following steps:
- Create an extension or plugin using the below example.
- Save the plugin inside the
/home/user/.rccontrol/instance-id/rcextensions
folder. - Add a hook to the
/home/user/.rccontrol/instance-id/rcextensions/__init__.py
file. For more information, see Making your Extension listen for Events. - Restart your RhodeCode Enterprise instance.
Extension example¶
In the following example, the run
method listens for a push to a repository
and parses the commit.
def run(*args, **kwargs):
revs = kwargs.get('pushed_revs')
if not revs:
return 0
from rhodecode.lib.utils2 import extract_mentioned_users
from rhodecode.model.db import Repository
repo = Repository.get_by_repo_name(kwargs['repository'])
changesets = []
reviewers = []
# reviewer fields from extra_fields, users can store their custom
# reviewers inside the extra fields to pre-define a set of people who
# will get notifications about changesets
field_key = kwargs.get('reviewers_extra_field')
if field_key:
for xfield in repo.extra_fields:
if xfield.field_key == field_key:
reviewers.extend(xfield.field_value.split())
vcs_repo = repo.scm_instance_no_cache()
for rev in kwargs['pushed_revs']:
cs = vcs_repo.get_changeset(rev) # or get_commit. See API doc
cs_data = cs.__json__()
cs_data['mentions'] = extract_mentioned_users(cs_data['message'])
cs_data['reviewers'] = reviewers
# optionally add more logic to parse the commits, like reading extra
# fields of repository to read managers of reviewers
changesets.append(cs_data)
return changesets