How to delete recall issues

The following example shows how to prevent creating recall issues if the recall email has been received. This script includes the use of regular expressions to extract the email subject after word Recall: and generates the hash of the subject on issue creation through the Script Field Processor and JQL to find the issue with the same generated hash.

 

Since JEMH 3.3.21 we lock down access to arbitrary classes in the script context, they cannot be accessed using historic methods:

var pageFilter = PagerFilter.static.getUnlimitedFilter(); var jqlQueryBuilder = JqlQueryBuilder.static.newBuilder();

but need to be gained through fully specified class names:

var filter = Java.type("com.atlassian.jira.web.bean.PagerFilter").getUnlimitedFilter(); var builder = Java.type("com.atlassian.jira.jql.builder.JqlQueryBuilder").newBuilder();

These specific classes were not initially added, are available since JEMH 3.3.38

 

var subHash = 'none'; if (subject.startsWith("Recall:")) { //create regexp pattern to extract the subject of the email after Recall: word var pattern = Java.type("java.util.regex.Pattern").compile("Recall:\s?(.+)"); var matcher = pattern.matcher(subject); //if able to extract the subject, set variable and set the custom field if (matcher.find()) { var subWithoutRecall = matcher.group(1).trim(); subHash = jemhUtils.hash(subWithoutRecall); resultMap.put("summary_hash", subHash); } } else if (subject !== null && !subject.isEmpty()) { subHash = jemhUtils.hash(subject); } //get the user to run the JQL query as var user = userManager.getUserByName("admin"); var filter = Java.type("com.atlassian.jira.web.bean.PagerFilter").getUnlimitedFilter(); var builder = Java.type("com.atlassian.jira.jql.builder.JqlQueryBuilder").newBuilder(); //construct the JQL query var query = builder.where().field("summary_hash").like(subHash).buildQuery(); //get list of issues (could be empty) var results = searchService.search(user, query, filter).getResults(); //get first issue if exists and delete it if (results.size()>0) { var issue = results[0]; var issueKey = issue.getKey(); var issueToDelet = issueManager.getIssueObject(issueKey); issueManager.deleteIssueNoEvent(issueToDelet); jemhUtils.dropMessage("Issue is recalled"); }else{ resultMap.put("summary_hash",subHash); }