The following will walk you through the important pieces of a script which uses ScriptRunner for Jira to create a Confluence SmartDraw chart representing issue hierarchy. At a high level, this script executes a JQL query against your Jira instance, returns the results, builds SmartDraw Object Notation (SDON) using the data, finds any hierarchy (Epics, Sub-Tasks, etc) and creates an SDON file. This SDON file is sent to a Confluence page and when you update the SmartDraw macro, you can reference the SDON file and generate your hierarchical Jira issue chart.
Jira issues and Customization
Customizing the chart
The Confluence page ID, the Confluence attachment ID, the JQL query and the colors for the hierarchical chart shapes are all stored and easily edited in this section. Don’t worry about the Confluence base URL — this will be determined later on by the application link.
The attachment and its ID must already exist prior to using this script.
If you add a new issuetype and color, you must also update the buildShape() method.
A list of issues
The JQL search results return Jira issue objects, but we want to simplify those objects into our own issues list. This will make the data easier to interact with down the road and allow us to store some other values within the list. Each JQL result (an issue object) is parsed and strings for its key, summary, parent (whether epic or standard issuetype) are stored as a map within our list. Then, we iterate back through the issues list and build our SDON "shapes" for each issue.
Building these shapes now and storing them in the issues using the buildShape method. This method will build the shape, a critical piece of the SDON format. This shape correlates to a square on the SmartDraw diagram. These shapes will later be plugged into another SDON structure. The issuetype, key and summary are added to the shape label and shape color is determined based on issuetype.
SmartDraw Object Notation Structure
SDON & Root Shape
SmartDraw SDON API information (SDON) format requires a very specific structure, with an important concept being the shape. It begins with the RootShape. Eventually, all the other shapes that are built will be plugged into the RootShape — and eventually the RootShape will be plugged into the sdonMap.
Modifying the existing SDON
The issues is searched to find Epics, then their epic-linked issues, then those issues' sub-tasks. A shape list is built from the top down like this. The process is then repeated, minus the Epics, for the standard issuetypes with sub-tasks. All of the new shapes are added to the shapeListArray and eventually the sdonMap (by way of the RootShape).
Confirming a Confluence application link exists
The Confluence application link is tested to see if it exists. If no application link exists, the script would obviously fail.
Creating the .SDON file
An attempt is made to create a temporary SDON file using the sdonMap (a collection of maps, lists) after it is converted to a string.
Attaching the SDON file to the Confluence Page
The file is attached to the Confluence page. The content (page) ID, the attachment ID and the temp SDON file created are referenced on this step.
Confluence and SmartDraw macro
If the attachment is successfully updated with the new SDON data, you can add or update the SmartDraw chart.
Navigate to your page
Edit the page
Insert a macro
Select the SmartDraw Diagram
Choose your SDON file in the top-left