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`.
Community moderators have prevented the ability to post new answers.
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)
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.