I was asked to provide stats for all users submitted issue in the last year.
My first thought was export issues to Excel which seemed to disappear.
So I created a script to run in the console to do the math which worked but only up to 100 maxResult
def query = 'project = "Project name" AND created > "-365d" ORDER BY created ASC'
def searchReq = get("/rest/api/2/search")
.queryString("jql", query)
.queryString("maxResults", "1000") //only returns 100!
.asObject(Map)
Map searchResult = searchReq.body
def issuesByUser = [:]
def user = ''
def count = 0
searchResult.issues.each { Map issue ->
user = issue.fields.reporter.displayName
created = issue.fields.created
count += 1
//logger.info("${count} ${user} ${created}")
issuesByUser.putIfAbsent(user, 0)
issuesByUser.find{it.key == user}.value += 1
}
logger.info("Total ${count} issue")
def total = 0
issuesByUser.each {i ->
logger.info("${i.key} ${i.value}")
total += i.value
}
logger.info("Total ${total} issue")
I could use some help with that!
Thank you
Hi Alexy,
When using the Search for issues API if you want to return more than 100 issues you will need to use pagination by having multiple search queries which the extra issues.
This means for the second query and onwards you would an extra queryString paramater of startAt as documented in the API documentation page above as this would return the next 100 issues if you started from 100 and then 200 etc.
I hope this helps.
Regards,
Kristian
Thanks.
Just did that and got "Execution timed out after 60s."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def query = 'project = "Project name" AND created > "-365d" ORDER BY created ASC'
def issuesByUser = [:]
def user = ''
def count = 0
def pageSize = 100
def issuesGot = 0
Map searchResult = [:]
def totalIssues = 0
while (true) {
def searchReq = get("/rest/api/2/search")
.queryString("jql", query)
.queryString("maxResults", issuesGot+pageSize <= totalIssues ? pageSize : totalIssues - issuesGot - 1)
.queryString("startAt", issuesGot+1 )
// .queryString("fields", "Flagged")
.asObject(Map)
issuesGot += pageSize
totalIssues = searchReq.body.total
logger.info("Total issues ${totalIssues}")
//logger.info(searchReq.inspect())
searchResult = searchReq.body
searchResult.issues.each { Map issue ->
//print (issue.fields.reporter.displayName)
user = issue.fields.reporter.displayName
created = issue.fields.created
count += 1
//logger.info("${count} ${user} ${created}")
issuesByUser.putIfAbsent(user, 0)
issuesByUser.find{it.key == user}.value += 1
}
logger.info("Total ${count} issue")
if (count >= totalIssues) break
}
def total = 0
issuesByUser.each {i ->
logger.info("${i.key} ${i.value}")
total += i.value
}
logger.info("Total ${total} issue")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexy,
I can confirm that we impose a timeout limit on scripts of 60 seconds in order to prevent long-running code as described in the documentation page here.
This means you will need to split your logic up into multiple scripts if your script is exceeding the 60-second timeout limit.
However, I notice from your script you have the line of // .queryString("fields", "Flagged") commented out which means as you are not restricting the fields you need on each issue that you are returning every field on the issue which would cause the search API to take a long time to return.
I would advise uncommenting this line and only returning the fields you need on each issue and if you are just counting the issues then just to return the summary field as doing this will cause the API to return faster and may help with the timeout limits that you are getting.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Kristian!
The flagged part was from the script example provided
Can you please share a snippet where only few relevant fields returned?
Thanks a ton
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexy,
To return only the relevant fields you would need to change that line to be the fields you require, an example is below which shows how to return the summary and a custom field by its ID.
In this query string, you would need to specify the names of all system fields and any custom fields you wish to return.
queryString("fields", "summary,customfield_12345")
An example of using this is in the documentation page here.
However, in your code, it looks like just get the reporter field off the issues so you could try returning just this field off of the issues.
I hope this helps.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Kristian!
That worked so much faster this way with only few select fields requested!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alexey Paveliev ,
I will try to help you with the code, but please, did you try Pie chart gadget? It should give you the same results without groovy scripting...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, I mostly forget on Issue statistics gadget - it can be used, when you want only simple table :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks!
there are around 1200 issues submitted by too many people to fit in a chart
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See code below that times out at issues over 1200 but luckily works up to 1000 issues
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alexey Paveliev ,
did you also check the Issue statictics gadget? I think it is exactly what you need - list of users with number of created issue
I got results for ~ 20 000 issues and 300 users without any problem.
I wasn't able to find it in cloud documentation, but is looks the same in the server :-).
Please, don't get me wrong, I don't want to force you and I love ScriptRunner, but I always prefer OOB functionality and I use SR only if really necessary :-).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the suggestion. I was not able to find the report in my cloud instance though
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please see here. In general, you need to navigate to one of your dashboards, which you are able to edit, open dialog for adding gadget using button in the right top corner, click on Load all gadgets to get all available gadgets, search for Issue Statistics, add this gadget, configure it and save.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.