Open Bhavya-ss opened 1 week ago
def issueKey = issue.key // Get the comments def issueResponse = get("/rest/api/2/issue/${issueKey}") .header("Content-Type", "application/json") .asObject(Map)
// Get the comments def comments = issueResponse.body.fields.comment.comments
// Find the most recent comment def mostRecentComment = comments.max { it.created }
// Get the author and the public status of the most recent comment def commentAuthor = mostRecentComment.author.accountId def publicTrue = mostRecentComment.jsdPublic
println("Most recent comment: ${mostRecentComment.body}") println("Author: ${commentAuthor}") println("Is public: ${publicTrue}")
def groupName = "jira-servicemanagement-users-bhavyass"
def groupsResponse = get("/rest/api/3/user?accountId=${commentAuthor}&expand=groups") .header('Content-Type', 'application/json') .asObject(Map) def isMember = groupsResponse.body.groups.items.any { group -> group.name == groupName }
// Check if the user is not a member of the specified group if (!isMember) { println("User is not a member of the group ${groupName}.") // Check if the most recent comment is public and the author is the same as the reporter if (publicTrue && commentAuthor == issueResponse.body.fields.reporter?.accountId) { def status = issue.fields.status.name // Check if the status is not 'closed' if (status != 'closed') { // Transition the issue def transition = post("/rest/api/2/issue/${issueKey}/transitions") .header("Content-Type", "application/json") .body([transition: [id: 21]]) .asObject(Map)
println("Issue transitioned successfully.")
} else {
println("Issue is already in progress.")
}
} else {
println("No action required.")
}
} else { println("User is a member of the group ${groupName}.") }
def issueKey = 'JP-154'
// Retrieve the issue def issueResponse = get("/rest/api/2/issue/${issueKey}") .header("Content-Type", "application/json") .asObject(Map)
// Get the comments def comments = issueResponse.body.fields.comment.comments
// Find the most recent comment def mostRecentComment = comments.max { it.created }
// Get the author and the public status of the most recent comment def commentAuthor = mostRecentComment.author.accountId def publicTrue = mostRecentComment.jsdPublic
println("Most recent comment: ${mostRecentComment.body}") println("Author: ${commentAuthor}") println("Is public: ${publicTrue}")
// Check if the most recent comment is public and the author is the same as the reporter if (publicTrue && commentAuthor == issueResponse.body.fields.reporter?.accountId) { def status = issueResponse.body.fields.status.name // Check if the status is not 'In Progress' if (status != 'In Progress') { // Transition the issue def transition = post("/rest/api/2/issue/${issueKey}/transitions") .header("Content-Type", "application/json") .body([transition: [id: 11]]) .asObject(Map)
} else { println("No action required.") }