We solved this by writing a Stash plugin, which has now been open sourced and is available on github.
The trick is to annotate methods with com.atlassian.event.api.EventListener
, which will get Stash to call them when a corresponding event happens. Then just listen to events such as:
com.atlassian.stash.event.pull.PullRequestCommentAddedEvent
com.atlassian.stash.event.pull.PullRequestOpenedEvent
com.atlassian.stash.event.pull.PullRequestReopenedEvent
com.atlassian.stash.event.pull.PullRequestRescopedEvent
Aside from that, just follow Atlassian guidelines to create plugins. The open sourced plugin can serve as a reference.