Hi,
One of our customer requirement is to update the JIRA issue description value over the confluence page.
To get it done I implemented following solution with help of #ScriptRunner plugin.
- Created Listener at JIRA end on issue update.
- Created RestEnd point at confluence end to serve the request.
- On issue update trigger, Sending API request to confluence along with update field data in WIKI format.
- Inside Rest API, capturing the WIKI data & converting it into storage format and updating the page.
- Prerequisite is JIRA issue should have confluence page link.
Below is the Sample code to convert WIKI data into storage format. Written in script console.
import com.atlassian.confluence.content.render.xhtml.ConversionContext
import com.atlassian.confluence.content.render.xhtml.DefaultConversionContext
import com.atlassian.confluence.xhtml.api.XhtmlContent
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.core.DefaultSaveContext
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.pages.PageManager
import org.apache.commons.lang.StringUtils
import com.atlassian.confluence.core.ContentEntityObject
PageManager pagemanager = ComponentLocator.getComponent(PageManager);
XhtmlContent xhtmlContent = ComponentLocator.getComponent(XhtmlContent);
try{
Page page = pagemanager.getPage(75990487);
ContentEntityObject contentEntityObject = page.getBodyContent().getContent();
final List<RuntimeException> wikiMarkupToStorageConversionErrors = new ArrayList();
final ConversionContext conversionContext = new DefaultConversionContext(page.toPageContext())
String jiraText = "Hi This is +created+ for{color:#de350b}[SolutionBook|https://solutionbook.xxxx.com/]{color} testing purpose. _Please ignore._ ||*JIRA*||Confluence|||Test|Best|
* 1 * 2 * 3-Test-{code:java}{java code}{code}{panel}*Panel Header*Panel Text{panel}{noformat}*no* further _formatting_ is done here{noformat}aksdfhasdf"
String jiradata = xhtmlContent.convertWikiToStorage(jiraText,conversionContext,wikiMarkupToStorageConversionErrors)
String pageBody = page.getBodyAsString()
pageBody = pageBody.replace("suresh",jiradata);
page.setBodyAsString(pageBody);
pagemanager.saveContentEntity(page,null);
return "pageBodyStr"
}catch(e){
log.error("Something went wrong whilw updating toc parameter:"+e.getMessage());
}