How do I create a JIRA Script Runner transition condition that evaluates open pull requests for an issue?

tony October 7, 2014

I want to design an issue workflow that is well integrated with GitHub (or more generally, with the DVCS that the project is using).

Specifically, I want to prevent someone from marking the story as "Done" until all pull requests have been closed.

I have read a bit about Script Runner scripts and understand that development debugging is a bit painful; however, I'm willing to learn Groovy and do some experimentation. I've even browsed the source for the DVCS plugin and I am familiar with some of its classes and interfaces.

My problem is that I don't know how to get access to the DVCS plugin .. the Groovy script's binding contains an issue object, but JIRA's Issue class has no direct references to plugin-related objects. There is a DVCS PullRequestService interface, but there's no way for me to access an implementation of that interface given only an Issue.

What's the best way for me to get started? I would imagine that this is a fairly common use case; perhaps someone else in the JIRA community has done it before.

P.S. I noticed that JIRA has canned conditions for "no open Crucible reviews" and "no open changesets" – but neither of these works with the DVCS plugin. That's a great pity, because otherwise my task would be done and I wouldn't need to learn Groovy or experiment!

1 answer

1 accepted

1 vote
Answer accepted
JamieA
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.
October 7, 2014

If you used one of the many "script runner" or "groovy" tags you would get better/quicker responses. No one follows either of the tags you used, precisely because everyone uses them. Rant over.

Why do you think debugging is painful? I think it's easy, it's exactly the same as with a java plugin... attach your debugger, set your breakpoints, debug.

You can get components from other plugins using the method here: https://jamieechlin.atlassian.net/wiki/display/GRV/Scripting+Other+Plugins

But yes you will need to be familiar with the API of the DVCS plugin.

It's an interesting question but I'm not sure it's a great idea... anyone can create a pull request pretty much, which will block closing the issue.

 

tony October 8, 2014

Thank you for pointing me in the right direction! I've tagged my post accurately. I suppose "painful" is relative -- as someone who's not deeply embedded in the Java ecosystem and accustomed to consuming Jira purely as an app, it'll require a few hours of my time to install all of the necessary dependencies. Well worth the trouble if I can get the plugin I need authored. Regarding the wisdom of adding this condition -- the DVCS API seems pretty data-rich; I will probably only block transition on the existence of open PRs to master, which shouldn't be too onerous. Agreed that this could "jam the works" of a story being completed, but I'm applying this workflow to some closed-source repositories whose development teams tend to behave themselves. I'd rather people be aware of the open PR and investigate it than leave it to hang out for months or days after the story is "released."

JamieA
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.
October 8, 2014

OK. PullRequestService is in stash not in jira - so you'd need to be looking for a remote version, or better something similar in the DVCS jira plugin. Is there one?

JamieA
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.
October 8, 2014

Yes.... the following code works for me, if you are on Script Runner 3 and up: https://gist.github.com/jechlin/99f0853f579c7e4edb34

JamieA
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.
October 8, 2014

You can test a variant of that in the script console, and take it from there...

tony October 8, 2014

Absolutely; thanks a million! You've saved me probably a day of experimentation and setup.

Suggest an answer

Log in or Sign up to answer