Skip to content

Commit

Permalink
Add Jira macro (#108)
Browse files Browse the repository at this point in the history
See #104

Co-authored-by: rvogel <[email protected]>
  • Loading branch information
osnard and rvogel authored Apr 22, 2024
1 parent 6aed7f5 commit 3a27d4e
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Composer/_defaultpages/Template/Jira
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<noinclude>Links to JIRA can be handled with "Interwiki-Links"
</noinclude><includeonly>[[jira:{{{key}}}]]</includeonly>
4 changes: 3 additions & 1 deletion src/Converter/ConfluenceConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroColumn;
use HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroContenByLabel;
use HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroDrawio;
use HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroJira;
use HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroNoFormat;
use HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroPanel;
use HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroRecentlyUpdated;
Expand Down Expand Up @@ -252,7 +253,8 @@ private function runProcessors( $dom ) {
),
new StructuredMacroContenByLabel( $this->currentPageTitle ),
new ExpandMacro(),
new MacroAlign()
new MacroAlign(),
new StructuredMacroJira()
];

/** @var IProcessor $processor */
Expand Down
52 changes: 52 additions & 0 deletions src/Converter/Processor/StructuredMacroJira.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace HalloWelt\MigrateConfluence\Converter\Processor;

use HalloWelt\MediaWiki\Lib\WikiText\Template;

class StructuredMacroJira extends StructuredMacroProcessorBase {

/**
* @return string
*/
protected function getMacroName(): string {
return 'jira';
}

/**
* @param \DOMElement $node
* @return void
*/
protected function doProcessMacro( $node ): void {
$params = $this->readParams( $node );
$wikitextTemplate = new Template( $this->getWikiTextTemplateName(), $params );
$wikitextTemplate->setRenderFormatted( false );
$node->parentNode->replaceChild(
$node->ownerDocument->createTextNode(
(string)$wikitextTemplate
),
$node
);
}

protected function getWikiTextTemplateName(): string {
return 'Jira';
}

/**
* @param \DOMElement $node
* @return array
*/
protected function readParams( \DOMElement $node ): array {
$params = [];
foreach ( $node->childNodes as $childNode ) {
if ( $childNode->nodeName === 'ac:parameter' ) {
$paramName = $childNode->getAttribute( 'ac:name' );
$paramValue = $childNode->nodeValue;
$params[$paramName] = $paramValue;
}
}
return $params;
}

}
32 changes: 32 additions & 0 deletions tests/phpunit/Converter/Processor/StructuredMacroJiraTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace HalloWelt\MigrateConfluence\Tests\Converter\Processor;

use HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroJira;
use PHPUnit\Framework\TestCase;

class StructuredMacroJiraTest extends TestCase {

/**
* @covers \HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroJira::process
* @return void
*/
public function testProcess() {
$jiraMacroProcessor = new StructuredMacroJira();
$dom = new \DOMDocument();
$dom->load(
__DIR__ . '/../../data/jira-input.xml'
);
$expectedDOM = new \DOMDocument();
$expectedDOM->load(
__DIR__ . '/../../data/jira-output.xml'
);

$jiraMacroProcessor->process( $dom );

$this->assertEqualXMLStructure(
$expectedDOM->documentElement,
$dom->documentElement
);
}
}
7 changes: 7 additions & 0 deletions tests/phpunit/data/jira-input.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<xml xmlns:ac="sample_namespace" xmlns:ri="sample_second_namespace">
<ac:structured-macro ac:name="jira" ac:schema-version="1" ac:macro-id="...">
<ac:parameter ac:name="server">My JIRA</ac:parameter>
<ac:parameter ac:name="serverId">1a43h4459d325e4b</ac:parameter>
<ac:parameter ac:name="key">ABC-3423</ac:parameter>
</ac:structured-macro>
</xml>
3 changes: 3 additions & 0 deletions tests/phpunit/data/jira-output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<xml xmlns:ac="sample_namespace" xmlns:ri="sample_second_namespace">
{{Jira|server = My JIRA|serverId = 1a43h4459d325e4b|key = ABC-3423}}
</xml>

0 comments on commit 3a27d4e

Please sign in to comment.