/** This example script console script shows how to trim down issue links issues that Exceed a maximum number of links . * Note: you must be on a Premium or Enterpise plan to be able to use this archiving API* "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner* license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or* amended and must be included in any circumstances where the code snippet is shared by You or a third party." */// Specify the project key belowdefprojectKey=""// Specify the number of links belowintmaximumNumberOfLinks=0// Validate that a projectKey and maximum number of links has been specifiedif(projectKey.size()==0||maximumNumberOfLinks==0){return"You must specify a project Key and the maximum number of links to be able to archive the issues"}// Construct the JQL to return the issues to be archiveddefjqlQuery="project = ${projectKey} and numberOfLinks > ${maximumNumberOfLinks}"// Search for the issues we want to updatedefsearchReq=get("/rest/api/2/search").queryString("jql",jqlQuery).asObject(Map)// Verify the search completed successfullyassertsearchReq.status>=200&&searchReq.status<300// Save the search results as a MapMapsearchResult=searchReq.body// Loop over each issuesearchResult.issues.each{Mapissue->// Get the ID for all issue linksdefgetLinks=issue.fields.issuelinks// Define an array to store all issue link idsdefallLinkIds=[]// Add the Id of each issue link to the arraygetLinks.each{issueLink->allLinkIds.push(issueLink.id)}// Extract the Id's of the links whcih exceed the maximum limit leaving the newest issue linksdefissueLinksToDelete=allLinkIds.drop(maximumNumberOfLinks)// Loop over each issue link and delete itissueLinksToDelete.each{id->defdeleteIssueLink=delete("/rest/api/3/issueLink/${id}").asObject(String)// Validate the issue link was deleted correctlyassertdeleteIssueLink.status>=200&&deleteIssueLink.status<300// Log out what issue issue links were trimmed downlogger.info("Issue links trimmed down to leave the ${maximumNumberOfLinks} newest issue links on the ${issue.key} issue.")}}"Issue links trimmed down to leave the ${maximumNumberOfLinks} newest issue links on the isues which exceed this limit in the ${projectKey} project"
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.