How to use the project event filter in scriptrunner script ?

Renaud Delaplace October 1, 2019

Hello,

I am using a script listener triggered by the issue_commented event in order to recopy comments to a linked issue.

I would like to restrict the use to some projects though and I noticed that the project filter of the event is only applying for the issue concerned by the event.

So now my idea would be to get the list of values entered in the project filter and use it in the script to check if the linked issue is in the project listed.

But I cannot find how to recover this list of values in the script. Could somebody help me with that ?

 

Thank you very much in advance.

1 answer

0 votes
Ilya Turov
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 1, 2019

hello, looks like this one will give you list of listeners:

import com.onresolve.scriptrunner.runner.util.OSPropertyPersister
import com.onresolve.scriptrunner.runner.ListenerManagerImpl
import com.onresolve.scriptrunner.runner.ListenerManager
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def listenerManager = ScriptRunnerImpl.getPluginComponent(ListenerManager)

OSPropertyPersister.loadList(ListenerManagerImpl.CONFIG_LISTENERS)

where you can find them by id and get list of project keys

Renaud Delaplace October 2, 2019

Thank you very much for your quick answer, could you please precise to me how I will get the list of project keys ?

OSPropertyPersister.projects ?
Ilya Turov
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 2, 2019

like this:

def listenerList = OSPropertyPersister.loadList(ListenerManagerImpl.CONFIG_LISTENERS)
def projects = listenerList.find {
it.id == "fb47asb6-7619-42a9-8ef3-a9ce66e2d842"
}.projects

where you can find id in a listener page edit url:

$baseUrl/plugins/servlet/scriptrunner/admin/listeners/edit/fb47asb6-7619-42a9-8ef3-a9ce66e2d842

if listener is for all projects, the list it returns will be empty

Renaud Delaplace October 2, 2019

Oh I really wouldn't have found it myself.

I still get error message in edit mode for the line below as well as for another line where I iterate, but strangely it does work.

def projects = listenerList.find {
it.id == "fb47asb6-7619-42a9-8ef3-a9ce66e2d842"
}.projects
Ilya Turov
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 2, 2019

Yeah, groovy does some static typechecking and because we are not defining stuff statically, but dynamically here, it's not sure methods we are calling are legit.

Something along those lines.

Renaud Delaplace October 2, 2019

I get it. Thank you very much though.

Suggest an answer

Log in or Sign up to answer