Hey everyone! Hope I can get some help here.So I run this pretty simple script for my custom field.
I don't think that 100 limit applies here.
You are only counting items containing "wix.wixanswers.com" --> 95
But did you already check how many items are in commentsList?
You can use:
commentsList.size()
Hello,
I leave you the script as it runs constantly, it only stops due to the maximum ScriptRunner time or you will not find anything else
def commentsList = []def startAt = 0def maxResults = 100def textToCheck = "wix.wixanswers.com"def count = 0while (true) { def response = get("/rest/api/3/issue/${issue.key}/comment?startAt=${startAt}&maxResults=${maxResults}") .header('Content-Type', 'application/json') .asObject(Map) if (response.status != 200) { logger.error("Error al obtener los comentarios: ${response.status}") break } def comments = response.body?.comments ?: [] commentsList.addAll(comments) if (comments.size() < maxResults) { break } startAt += maxResults}commentsList.each { comment -> if (comment.body.contains(textToCheck)) { count++ }}return count
Hey Charlie! Thanks for your reply.I confirmed that the value of 100 is max number of comments jira shows per page.I actually used commentsList.size() and break to cycle through pages.
def textToCheck = "wix.wixanswers.com"def count = 0def startAt = 0def maxResults = 100
// This will store all comments from the issuedef allComments = []
// Fetch comments in a paginated waywhile (true) {// Retrieve comments with paginationdef response = get("/rest/api/2/issue/${issue.key}/comment").queryString("startAt", startAt).queryString("maxResults", maxResults).asObject(Map)def commentsList = response.body?.commentsif (commentsList) {allComments.addAll(commentsList)// If the number of comments retrieved is less than maxResults, we are doneif (commentsList.size() < maxResults) {break} else {// Move to the next pagestartAt += maxResults}} else {break}}
// Now, allComments contains all comments, let's check for the textallComments.each { comment ->if (comment.body.contains(textToCheck)) {count += 1}}
return count
This one worked perfectly.
Thanks!
Thanks! I pretty much ended up with the same solution))Thanks for your input!Problem has been solved!
Ok, glad you found a solution!
It looks like you're new here. Sign in or register to get started.