I'm trying to implement a pull request hook that listens for various pull request events (Open, Approved, Declined, etc). I'm using the @EventListener pattern to listen for these events but the problem is that my hook ends up being called for ALL pull requests events. I would like to restrict my hook to the repository or project level, not the system level.
Is it possible to do this?
Thanks.
Community moderators have prevented the ability to post new answers.
You'll need to handle the filtering in your code. Events are system wide. As part of the pullRequest event you'll receive a pullRequest object. https://developer.atlassian.com/static/javadoc/stash/3.11.1/api/reference/com/atlassian/stash/pull/PullRequest.html
So something like pullRequest.getToRef().getRepository() will get you the repository that's receiving the pull request.
Hi Matt,
ScriptRunner for Stash can do that for you quite easily.
You can set up a custom event handler to capture pull request related events (or any other event) and then perform some action. That behaviour can be applied to one, several or all the repositories of your Stash instance. I'll just drop a link to the documentation site here: https://scriptrunner.adaptavist.com/stash/latest/docs/event_handlers/
Apologies if you were purely interested in developing your own add-on.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the answers.
For clarification, what I'm concerned about is security and access control. Our corporate IT dept. manages our Stash server. Several teams and projects use the central stash server with appropriate permissions for viewing, cloning, etc. But what I've noticed is that a custom hook listening to events will capture all events, regardless of access control.
Thus my comment regarding repository level pull requests hooks. The repository hooks fire for the Pre/Post/Merge events and I was hopping there something like for pull requests (besides merges).
thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
could you please explain what you mean with "project or system level" in terms of pull request events? Pull requests and their events are always based on repositories and their branches (you can create cross-repository pull requests).
Cheers,
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That being said: you can get the pull request associated with a pull request event and therefore you can check if the repository (e.g., with getFromRef().getRepository) is the one of interest. Is that what you are looking for?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.