With a Scriptrunner Listener script, I'm trying to access the comments in an issue.
def issueKey = issue.key
def allCommentsResponse = get("/rest/api/3/issue/${issueKey}/comment")
.header('Content-Type', 'application/json')
.asObject(Map)
if (allCommentsResponse.status == 200) {
def comments = allCommentsResponse.body.comments
logger.info("Found ${comments.size()} comments in issue ${issueKey}:")
comments.each { comment ->
def author = comment.author?.displayName ?: "Unknown"
def content = comment.body?.content?.collect { paragraph ->
paragraph?.content?.collect { item -> item?.text }.join(" ")
}.join("\n")
logger.info("Comment by ${author}: ${content}")
}
The problem arises when a comment is set to internal and additionally restricted to a role.
Let's say in an example issue I have four comments
User 2 (05.12.2024 11:12) (internal, restricted to role Service Desk Team)
comment4 text blabla
User 1 (05.12.2024 10:03) (internal, restricted to role Developer)
comment3 text bar
User 2 (04.12.2024 15:17) (internal, no role restriciton)
comment2 text xyz
User 1 (04.12.2024 13:51) (external for customer, no restriction)
comment1 text foo
Then I get for the logging only comment 1, comment2 and comment4.
Comment3 is missing, even though it got the call that a comment was created. After Comment3, it'd log "Found 2 comments" and after Comment4 it'd log "Found 3 comments".
For whatever reason any role restriction that is not "Service Desk Team", the response doesn't seem to see these comments and I don't think there is a way to manually grant the Scriptrunner access to specific roles.
My question: is there a way to reliably get all comments in the API response? Could it be a bug or did I do a mistake?