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

Repository Level Pull Request Custom Hook

Matt July 29, 2015

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.

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Daniel Wester
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2015

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.

0 votes
Alejo Villarrubia [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2015

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.

0 votes
Matt July 29, 2015

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.

0 votes
Mibex_Software
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2015

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

Mibex_Software
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2015

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?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events