Prevent Comments on Project based on the Sender

Scenario

The Jira Instance has two Projects (i.e. Blue and Green) handled by two teams. Occasionally, an Issue from one Project should also be created in the other Project to be handled by both teams, and so a ‘Blue’ Team Member is added to a ‘Green’ issue so they can be informed of the issue. However, any replies from the ‘Blue’ Team Member will create comments in the ‘Green’ Issue, rather than creating a new ‘Blue’ Issue. To prevent the ‘Blue’ Team Member from commenting on a ‘Green’ issue (and visa versa), the following Script could be used to detect comments on an issue and redirect to a another Project if needed.

Implementation

The Script works by identifying when a comment should be dropped, based on the Project Key of the target Issue and the sender address. Then dropping the comment and diverting issue creation to the specified Project.

//Check if Email is adding a comment if(relatedIssue !== null){ //define expected ProjectKey Values var blueKey = "BLUE"; var greenKey = "GREEN"; //define the a restricted Sender variable var restrictedSender = ""; //define a variable for the new target Project var allowedProject = ""; var projectKey = relatedIssue.getProjectObject().getKey(); if(projectKey.equals(blueKey)){ print("ProjectKey is " + blueKey); //set restricted sender and allowed project restrictedSender = "green@test.com"; allowedProject = greenKey; }else if(projectKey.equals(greenKey)){ print("ProjectKey is " + greenKey); //set restricted sender and allowed project restrictedSender = "blue@test.com"; allowedProject = blueKey; } //if a value is found for restrictedSender then one of the two Projects is being commented on if(!restrictedSender.isEmpty()){ print("Restricted Sender is: " + restrictedSender) //if the sender matches the Restricted Sender then... if(fromAddress !== null && fromAddress.getAddress().equals(restrictedSender)){ print("Restricted Sender [" + restrictedSender + "] matches actual sender [" + fromAddress.getAddress() + "]" ); //drop Comment and create new Issue resultMap.put("issueKey", "") resultMap.put("labels", "hello-world"); resultMap.put("project", allowedProject); resultMap.put("priority", "medium"); resultMap.put("issueType", "task"); resultMap.put("summary", subject); resultMap.put("description", body); } } }