|
| 1 | +import org.apache.log4j.Level |
| 2 | +import org.apache.log4j.Logger |
| 3 | + |
| 4 | +import com.atlassian.jira.issue.IssueManager |
| 5 | +import com.atlassian.jira.component.ComponentAccessor |
| 6 | +import com.atlassian.jira.issue.Issue |
| 7 | +import com.atlassian.jira.issue.IssueImpl |
| 8 | +import com.atlassian.jira.issue.link.IssueLink |
| 9 | +import com.atlassian.jira.issue.link.IssueLinkImpl |
| 10 | +import com.atlassian.jira.issue.link.DefaultIssueLinkManager |
| 11 | +import com.atlassian.jira.issue.link.IssueLinkManager |
| 12 | + |
| 13 | +import com.atlassian.jira.project.version.Version |
| 14 | + |
| 15 | +import com.atlassian.jira.issue.fields.CustomField |
| 16 | +import com.atlassian.jira.issue.fields.ImmutableCustomField |
| 17 | +//import com.atlassian.jira.issue.RendererManager |
| 18 | +//import com.atlassian.jira.issue.fields.renderer.IssueRenderContext |
| 19 | +//import com.atlassian.jira.issue.fields.renderer.wiki.AtlassianWikiRenderer |
| 20 | + |
| 21 | +IssueManager issueManager = ComponentAccessor.getIssueManager() |
| 22 | + |
| 23 | +@com.onresolve.scriptrunner.parameters.annotation.ShortTextInput(description = "Enter Jira to execute the script on - leave empty for non-debug modes", label = "Jira Request Issue") |
| 24 | +String jiraDebugIssue |
| 25 | + |
| 26 | +Logger logger = Logger.getLogger("parent.parentSiblings") |
| 27 | + |
| 28 | +logger.info("jiraDebugIssue=" + jiraDebugIssue) |
| 29 | + |
| 30 | +//Issue issue |
| 31 | +if ( jiraDebugIssue != null ){ |
| 32 | + issue = issueManager.getIssueObject(jiraDebugIssue) // Add an issue for testing |
| 33 | + logger.setLevel(Level.ALL) // ALL, WARN |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +def findParent(Issue issue, Logger logger, IssueLinkManager issueLinkManager){ |
| 39 | + if(issue.subTask){ |
| 40 | + logger.info("Issue link type subtask - next: " + issue.subTask ) |
| 41 | + return findParent(issue.getParentObject(), logger, issueLinkManager) |
| 42 | + } |
| 43 | + for(IssueLink issueLink : issueLinkManager.getInwardLinks(issue.id)){ |
| 44 | + if (issueLink.issueLinkType.name == "Epic-Story Link" ) { |
| 45 | + logger.info("Issue link type E: " + issueLink.issueLinkType.name + " : " + issueLink.getSourceObject().getKey()) |
| 46 | + return issueLink.getSourceObject() |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +try { |
| 52 | + |
| 53 | + IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager() |
| 54 | + Issue parentIssue = findParent(issue, logger, issueLinkManager) as Issue |
| 55 | + Issue parentIssueNotNull |
| 56 | + if ( parentIssue ) { |
| 57 | + parentIssueNotNull=parentIssue |
| 58 | + logger.info("Returned: " + parentIssueNotNull) |
| 59 | + } else { |
| 60 | + logger.info("Returned null: " + parentIssueNotNull) |
| 61 | + } |
| 62 | + |
| 63 | + def customFieldManager = ComponentAccessor.getCustomFieldManager() |
| 64 | + ImmutableCustomField siblings_cf = customFieldManager.getCustomFieldObjectsByName("Siblings")[0] as ImmutableCustomField |
| 65 | + def value |
| 66 | + if ( parentIssueNotNull ) { |
| 67 | + value = parentIssueNotNull.getCustomFieldValue(siblings_cf) |
| 68 | + logger.info("value: " + value) |
| 69 | + if (value) { |
| 70 | + value |
| 71 | + /* |
| 72 | + // It is already rendered in parent: |
| 73 | + def rendererManager = ComponentAccessor.getComponent(RendererManager) |
| 74 | + def renderContext = new IssueRenderContext(issue) |
| 75 | + rendererManager.getRenderedContent(AtlassianWikiRenderer.RENDERER_TYPE, value, renderContext) |
| 76 | + */ |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | +} catch(Exception e){ |
| 81 | + log.error(e) |
| 82 | +} |
0 commit comments