Created
April 27, 2021 05:17
-
-
Save vikrantyadav11/563ad7127ee0e08414adfae6de19c653 to your computer and use it in GitHub Desktop.
Update Fix Version of Linked issue using Scripted Listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.atlassian.jira.component.ComponentAccessor | |
import com.atlassian.jira.issue.ModifiedValue | |
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder | |
import com.atlassian.jira.issue.link.IssueLink | |
import com.atlassian.jira.issue.link.IssueLinkManager | |
import com.atlassian.jira.issue.Issue | |
import com.atlassian.jira.project.version.Version | |
import com.atlassian.jira.event.type.EventDispatchOption | |
import java.time.LocalDateTime | |
import java.time.format.DateTimeFormatter | |
import org.apache.log4j.Logger | |
import org.apache.log4j.Level | |
def logger = Logger.getLogger("com.acme.CreateSubtask") | |
logger.setLevel(Level.DEBUG) | |
def issueManager = ComponentAccessor.getIssueManager() | |
def versionManager = ComponentAccessor.getVersionManager() | |
final customFieldName = 'Fix Version/s' | |
Issue fix_Issue = event.getIssue() | |
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext() | |
Collection<Version> fixVersions | |
def user = authenticationContext.getLoggedInUser() | |
if (fix_Issue.issueTypeObject.name == "Story" ) { | |
List changeItems = event.getChangeLog().getRelated("ChildChangeItem") | |
if( fix_Issue.fixVersions?.name && changeItems.any {it.get('field')=='Fix Version'} ) { | |
fixVersions = new ArrayList<Version>(); | |
fixVersions = fix_Issue.getFixVersions() | |
logger.debug fixVersions | |
} | |
//return fixVersions | |
def linkedIssues = ComponentAccessor.issueLinkManager | |
.getOutwardLinks(issue.id) | |
logger.debug linkedIssues | |
.findAll { it.issueLinkType.name in ['Covers'] && it.destinationObject.issueType.name == "Story" } | |
log.info(linkedIssues) | |
if (!linkedIssues) { | |
logger.debug "no issue" | |
return | |
} | |
linkedIssues.each { | |
def linkedIssue = it.destinationObject | |
logger.debug linkedIssue | |
def newValue = fixVersions | |
versionManager.updateIssueFixVersions(linkedIssue, newValue) | |
issueManager.updateIssue(user, linkedIssue, EventDispatchOption.DO_NOT_DISPATCH, false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment