Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Event listener not triggering

Mathieu Yargeau November 3, 2014

I followed the steps here:
https://developer.atlassian.com/stash/docs/latest/how-tos/responding-to-application-events.html

 

I don't know why, but when I create a repository, the code inside my function is never executed. I placed a breakpoint in it and it doesn't do anything...

 

package com.company.stash;
 
import com.atlassian.event.api.EventListener;
import com.atlassian.stash.event.RepositoryCreatedEvent;
import com.atlassian.stash.repository.Repository;
import com.atlassian.stash.hook.repository.RepositoryHookService;
import com.atlassian.stash.hook.repository.RepositoryHook;
 
public class RepoInit
{
 private RepositoryHookService hookService;
 
 public RepoInit(RepositoryHookService hookService)
 {
  this.hookService = hookService;
 }
 
 @EventListener
 public void onRepositoryCreated(RepositoryCreatedEvent event)
 {
  //Enables Anthill auto-build hook
  String hookKey = "SomeKey";
  RepositoryHook hook = hookService.getByKey(event.getRepository(), hookKey);
    
  if(hook != null && !hook.isEnabled())
  {
   hookService.enable(event.getRepository(), hookKey);
  }
 }
}

My atlassian-plugin.xml:

 

<atlassian-plugin key="com.company.plugin" name="Company plugin" plugins-version="2">
    <plugin-info>
        <description>description>
        <version>1.0.0.4</version>
    </plugin-info>
    <component-import key="commitService" interface="com.atlassian.stash.commit.CommitService"/>
    <component-import key="hookService" interface="com.atlassian.stash.hook.repository.RepositoryHook"/>
    
    <component key="repoInit" class="com.company.stash.RepoInit" public="true"/>
</atlassian-plugin>

 

What did I do wrong?

 

The only thing I don't understand in the documentation is the fact that the class is named `MyStashEventListener` when the class referenced in the component item (in the xml file) is different `MyEventListener`.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Marcin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 3, 2014

Have you checked the Stash logs when you install your plugin to see if it throws any errors when it gets enabled? Also in Stash admin under Manage Add-ons make sure you plugin is listed and "Enabled". I created a simple plugin with the same sort of code and it worked fine, so at a glance I can't see anything obviously wrong. It might be something outside the parts of the code you've pasted. The MyStashEventListener / MyEventListener does appear to be a documentation bug, I have created an issue to ensure the documentation gets updated (https://jira.atlassian.com/browse/STASH-5457)

0 votes
Mathieu Yargeau November 4, 2014

The plugin was enabled and other aspects of the plugin was working (merge check). However, looking at the installation logs revealed the issue: I wrote the wrong interface for the hook service component-import. It works now. Thanks :)

TAGS
AUG Leaders

Atlassian Community Events