Jump to content

Listener not responding to commit event (swarm module)

swarm module event listener commit

  • Please log in to reply
1 reply to this topic

#1 farlay



  • Members
  • Pip
  • 1 posts

Posted 15 August 2019 - 12:23 PM


I am working on a module that automatically requests a review for each commit. Following the slack example from the documentation I added a listener to the commit event with a priority set to -110 but I don't seem to get any response when a change is actually committed.

When I write to the log in the onBootstrap function I can see that the module is actually loaded but I can't get anything else out of it.

Any idea what I'm doing wrong? Source is added below


namespace ReviewAutoRequest;
use Zend\eventManager\Event;
use Zend\Log\Logger;

class Module {
public function getConfig() {
	 return include __DIR__ . '/config/module.config.php';

public function onBootstrap(Event $event) {
	 $application = $event->getApplication();
	 $services = $application->getServiceManager();
	 $logger = $services->get('logger');
	 $logger->info("ReviewAutoRequest bootstrapping");


$listeners = [ReviewAutoRequest\Listener\ReviewAutoRequestListener::class];

return [
'listeners' => $listeners,
'service_manager' =>[
	 'factories' => array_fill_keys(
Events\Listener\ListenerFactory::EVENT_LISTENER_CONFIG => [
	 Events\Listener\ListenerFactory::COMMIT => [
		 ReviewAutoRequest\Listener\ReviewAutoRequestListener::class => [
				 Events\Listener\ListenerFactory::PRIORITY => -110,
				 Events\Listener\ListenerFactory::CALLBACK => 'handleCommit',
				 Events\Listener\ListenerFactory::MANAGER_CONTEXT => 'queue'


namespace ReviewAutoRequest\Listener;

use Events\Listener\AbstractEventListener;
use P4\Spec\Change;
use P4\Spec\Exception\NotFoundException;
use Zend\EventManager\Event;
use Zend\Http\Client;
use Zend\Http\Request;

class ReviewAutoRequestListener extends AbstractEventListener {
public function handleCommit (Event $event) {
	 $logger = $this->services->get('logger');
	 $logger->info("ReviewAutoRequest: handle commit");
	 $p4Admin = $this->services->get('p4_admin');
	 $change = $event->getParam('change');

	 if(!$change instanceof Change){
		 try {
			 $change = Change::fetchById($event->getParam('id'), $p4Admin);
			 $event->setParam('change', $change);
		 } catch (NotFoundException $e) {
			 $logger->err("ReviewAutoRequest event not found:" + $e.getMessage());
		 } catch (\InvalidArgumentException $e) {
			 $logger->err("ReviewAutoRequest invalid argument:" + $e.getMessage());

	 if (!$change instanceof Change || !$change->isSubmitted()) {
		 $logger->info("ReviewAutoRequest: no changes found");

	 try {
		 $id = $change.getParam('id');
	 } catch (\Exception $e){
		 $logger->err("ReviewAutoRequest post exception:" . $e->getMessage());

	 'Zend\Loader\StandardAutoloader' => array(
		 'namespaces' => array(
			 'ReviewAutoRequest' => BASE_PATH . '/module/ReviewAutoRequest/src',
return [

#2 P4Dale


    Advanced Member

  • Staff
  • 50 posts

Posted 19 August 2019 - 03:44 PM

Before I look into this code; have you seen the latest version of Swarm 19.1, and soon coming out of tech preview in 19.2, feature called "workflow"?

This feature allows you to reject reviews that don't have a review link to them or auto create reviews for the users.

Please take a look at the below link and hopefully this feature will do what you are trying to code.


Please take a look at the option in the above link for "auto_create"

Hope this helps,



Swarm Dev.
Swarm Dev.

Also tagged with one or more of these keywords: swarm, module, event, listener, commit

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users