Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created February 22, 2017 14:43
Show Gist options
  • Save jechlin/4c9817846ed98f025053003846541a6f to your computer and use it in GitHub Desktop.
Save jechlin/4c9817846ed98f025053003846541a6f to your computer and use it in GitHub Desktop.
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
components(httpMethod: "GET") { MultivaluedMap queryParams ->
def projectId = queryParams.getFirst("projectId") as Long
def rt = [:]
def query = queryParams.getFirst("query") as String
def pcm = ComponentAccessor.projectComponentManager
def candidates = pcm.findAllForProject(projectId).findAll {
it.name.contains(query)
}
rt = [
items : candidates.collect { component ->
[
value: component.name,
html : component.name.replaceAll(/(?i)$query/) { "<b>${it}</b>" },
label: component.name,
]
},
total : candidates.size(),
footer: "Choose component... "
]
return Response.ok(new JsonBuilder(rt).toString()).build();
}
@limoxizhao
Copy link

Hello,i'm so happy that i find you so interested in scriptrunner for jira.i am a beginner,i am so puzzled about it.Now ,i need do a function that calculated a transition be operationed and use the plugin of scriptrunner,can you give me some advice or write a simple code for me ,it's will very help me ,wait for you apply,thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment