-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathget_jira_issues_rest_endpoint.groovy
More file actions
49 lines (36 loc) · 2.44 KB
/
Copy pathget_jira_issues_rest_endpoint.groovy
File metadata and controls
49 lines (36 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.*
log.level = Level.ALL
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// edit this query to suit
def query = jqlQueryParser.parseQuery("project = TIS and assignee != \"admin\" and updated <= -7d and resolution is EMPTY")
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
log.debug("Total issues: ${results.total}")
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
// Adding a REST Endpoint
// https://scriptrunner.adaptavist.com/latest/jira/rest-endpoints.html
@BaseScript CustomEndpointDelegate delegate // this line makes methods in your script recognisable as endpoints, and is required
// JSON Format
// http://jira.teamsinspace.com:8080/rest/scriptrunner/latest/custom/getInactiveIssues
getInactiveIssues( // the name of the REST endpoint, which forms part of the URL
httpMethod: "GET", groups: ["jira-administrators"] // configuration of the endpoint, in this case which HTTP verb to handle, and what groups to allow
) { MultivaluedMap queryParams, String body -> // parameters which are provided to your method body
return Response.ok(new JsonBuilder([inactive_issues_count: results.total]).toString()).build() // the body of your method, where you will return a javax.ws.rs.core.Response object
}
// Prometheus Format
// http://jira.teamsinspace.com:8080/rest/scriptrunner/latest/custom/getStaledIssues
getStaledIssues( // the name of the REST endpoint, which forms part of the URL
httpMethod: "GET", groups: ["jira-administrators"] // configuration of the endpoint, in this case which HTTP verb to handle, and what groups to allow
) { MultivaluedMap queryParams, String body -> // parameters which are provided to your method body
return Response.ok(new String("staled_issues_count" + " " + results.total)).build() // the body of your method, where you will return a javax.ws.rs.core.Response object
}