Hey everyone! Hope I can get some help here.
So I run this pretty simple script for my custom field.
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 = 0
def maxResults = 100
def textToCheck = "wix.wixanswers.com"
def count = 0
while (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
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 = 0
def startAt = 0
def maxResults = 100
// This will store all comments from the issue
def allComments = []
// Fetch comments in a paginated way
while (true) {
// Retrieve comments with pagination
def response = get("/rest/api/2/issue/${issue.key}/comment")
.queryString("startAt", startAt)
.queryString("maxResults", maxResults)
.asObject(Map)
def commentsList = response.body?.comments
if (commentsList) {
allComments.addAll(commentsList)
// If the number of comments retrieved is less than maxResults, we are done
if (commentsList.size() < maxResults) {
break
} else {
// Move to the next page
startAt += maxResults
}
} else {
break
}
}
// Now, allComments contains all comments, let's check for the text
allComments.each { comment ->
if (comment.body.contains(textToCheck)) {
count += 1
}
}
return count
This one worked perfectly.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.