Skip to content

Commit ae5a7ac

Browse files
committed
init
1 parent c224daf commit ae5a7ac

22 files changed

+1264
-1
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
charset = utf-8
12+
13+
# 4 space indentation
14+
[*.py]
15+
indent_style = space
16+
indent_size = 4

.github/workflows/test.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: build
2+
on: [push]
3+
jobs:
4+
test-and-run:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
python-version: ["3.9", "3.10", "3.11", "3.12"]
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Set up Python ${{ matrix.python-version }}
12+
uses: actions/setup-python@v4
13+
with:
14+
python-version: ${{ matrix.python-version }}
15+
- name: Display Python version
16+
run: python -c "import sys; print(sys.version)"
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install -r requirements.txt
21+
- name: unit tests
22+
run: pytest
23+
- name: code coverage
24+
run: pytest --cov=lib lib/
25+
- name: convert single
26+
run: |
27+
python3 index.py -ek 9a81c16f-31e6-4be7-be6e-dfc872fe4155/35d2082a-431b-46b7-90da-75a526882f2f \
28+
-if ./lib/input/ac-single-test1.input.storage \
29+
-of ./lib/output/ac-single-test1.output.storage
30+
- name: convert multi
31+
run: |
32+
python3 index.py -ek 9a81c16f-31e6-4be7-be6e-dfc872fe4155/35d2082a-431b-46b7-90da-75a526882f2f \
33+
-if ./lib/input/ac-multi-test1.input.storage \
34+
-of ./lib/output/ac-multi-test1.output.storage
35+
- name: convert remote
36+
run: |
37+
python3 index.py -ek 9a81c16f-31e6-4be7-be6e-dfc872fe4155/35d2082a-431b-46b7-90da-75a526882f2f \
38+
-if ./lib/input/ac-remote-test1.input.storage \
39+
-of ./lib/output/ac-remote-test1.output.storage

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.pytest_cache
2+
__pycache__
3+
lib/output/*
4+
!lib/output/.gitkeep
5+
.coverage
6+
.DS_Store

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2023 codeclou GmbH
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,153 @@
1-
# advanced-codeblocks-cloud-migration-helper
1+
<img src="https://user-images.githubusercontent.com/12599965/56864901-501d8b80-69c8-11e9-9e87-c7e687615a0a.png" align="right" />
2+
3+
# Advanced Codeblocks for Confluence
4+
5+
## :rocket: Cloud Migration Helper
6+
7+
This migration helper transforms a Server/DataCenter Confluence page in <a href="https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html">Storage Format</a> to
8+
Cloud Confluence Storage Format. It will convert the <a href="https://marketplace.atlassian.com/apps/1211159/advanced-codeblocks-for-confluence?hosting=datacenter&tab=overview">Advanced Codeblocks for Confluence</a> macros to their Cloud forge app equivalent.
9+
10+
- :book: **[Read the complete migration guide here](https://codeclou.github.io/advanced-codeblocks-cloud-migration-helper)**
11+
12+
For example a Data Center Confluence page containing the Advanced Codeblocks Single Macro will look like this:
13+
14+
```
15+
<p>some text</p>
16+
<ac:structured-macro ac:name="advanced-single-codeblock-macro" ac:schema-version="1" ac:macro-id="0a76fb27-ee70-41a4-bead-063a0908804d">
17+
<ac:parameter ac:name="enableddl">true</ac:parameter>
18+
<ac:parameter ac:name="theme">light-mono</ac:parameter>
19+
<ac:parameter ac:name="lang">Bash</ac:parameter>
20+
<ac:parameter ac:name="globaltitle">test</ac:parameter>
21+
<ac:plain-text-body><![CDATA[echo "foo"]]></ac:plain-text-body>
22+
</ac:structured-macro>
23+
```
24+
25+
The Cloud App equivalent will look like this:
26+
27+
```
28+
<p>some text</p>
29+
<ac:adf-extension>
30+
<ac:adf-node type="extension">
31+
<ac:adf-attribute key="extension-type">com.atlassian.ecosystem</ac:adf-attribute>
32+
<ac:adf-attribute key="extension-key">9a81c16f-31e6-4be7-be6e-dfc872fe4155/35d2082a-431b-46b7-90da-75a526882f2f/static/advancedsinglecodeblockmacro</ac:adf-attribute>
33+
<ac:adf-attribute key="parameters">
34+
<ac:adf-parameter key="local-id">0658e817-aaf6-7e1d-8000-36a917095fd3</ac:adf-parameter>
35+
<ac:adf-parameter key="extension-id">ari:cloud:ecosystem::extension/9a81c16f-31e6-4be7-be6e-dfc872fe4155/35d2082a-431b-46b7-90da-75a526882f2f/static/advancedsinglecodeblockmacro</ac:adf-parameter>
36+
<ac:adf-parameter key="extension-title">Advanced Codeblocks Single</ac:adf-parameter>
37+
<ac:adf-parameter key="guest-params">
38+
<ac:adf-parameter key="globaltitle">test</ac:adf-parameter>
39+
<ac:adf-parameter key="code">echo "foo"</ac:adf-parameter>
40+
<ac:adf-parameter key="enableddl">
41+
<ac:adf-parameter-value>true</ac:adf-parameter-value>
42+
</ac:adf-parameter>
43+
<ac:adf-parameter key="theme">light-mono</ac:adf-parameter>
44+
<ac:adf-parameter key="lang">Bash</ac:adf-parameter>
45+
</ac:adf-parameter>
46+
</ac:adf-attribute>
47+
<ac:adf-attribute key="text">Advanced Codeblocks Single</ac:adf-attribute>
48+
<ac:adf-attribute key="layout">default</ac:adf-attribute>
49+
<ac:adf-attribute key="local-id">0658e817-aaf6-7d86-8000-4dd60f28b018</ac:adf-attribute>
50+
</ac:adf-node>
51+
<ac:adf-fallback>
52+
<!-- shortened ... -->
53+
</ac:adf-fallback>
54+
</ac:adf-extension>
55+
```
56+
57+
&nbsp;
58+
59+
---
60+
61+
&nbsp;
62+
63+
### Installation
64+
65+
```
66+
git clone https://github.com/codeclou/advanced-codeblocks-cloud-migration-helper.git
67+
cd advanced-codeblocks-cloud-migration-helper
68+
pip3 install -r requirements.txt
69+
```
70+
71+
&nbsp;
72+
73+
---
74+
75+
&nbsp;
76+
77+
### Disclaimer
78+
79+
**:bangbang: Please check the output storage file for errors before submitting it into your Confluence page. codeclou GmbH is not responsible for damages to your Confluence installation and/or content. Please test the output on a test instance first. This tool is provided as an example on how to transform your storage format from server to cloud. It might need further adaption to your specific needs.**
80+
81+
&nbsp;
82+
83+
---
84+
85+
&nbsp;
86+
87+
### Run transformer
88+
89+
The extension key must be extracted from the cloud page, see the documentation for details.
90+
91+
```
92+
# single macro
93+
python3 index.py -ek 9a81c16f-31e6-4be7-be6e-dfc872fe4155/35d2082a-431b-46b7-90da-75a526882f2f \
94+
-if ./lib/input/ac-single-test1.input.storage \
95+
-of ./lib/output/ac-single-test1.output.storage
96+
97+
# multi macro
98+
python3 index.py -ek 9a81c16f-31e6-4be7-be6e-dfc872fe4155/35d2082a-431b-46b7-90da-75a526882f2f \
99+
-if ./lib/input/ac-multi-test1.input.storage \
100+
-of ./lib/output/ac-multi-test1.output.storage
101+
102+
# multi remote macro
103+
python3 index.py -ek 9a81c16f-31e6-4be7-be6e-dfc872fe4155/35d2082a-431b-46b7-90da-75a526882f2f \
104+
-if ./lib/input/ac-remote-test1.input.storage \
105+
-of ./lib/output/ac-remote-test1.output.storage
106+
```
107+
108+
Will produce an output like this:
109+
110+
```
111+
======================================
112+
ADVANCED CODEBLOCKS MIGRATION HELPER
113+
======================================
114+
115+
extension key part: 9a81c16f-31e6-4be7-be6e-dfc872fe4155/35d2082a-431b-46b7-90da-75a526882f2f
116+
117+
START > reading storage format file from: ./lib/input/ac-single-test1.input.storage
118+
119+
>> advanced-single-codeblock-macro
120+
macro param lang : Bash
121+
macro param enableddl : true
122+
macro param globaltitle : test
123+
macro param theme : light-mono
124+
macro body (shortened) : echo "foo"
125+
macro attr local id : 0658e829-ab6b-7f11-8000-c612fa7cbd38
126+
macro param local id : 0658e829-ab6b-7fa8-8000-1b5180ffb326
127+
128+
DONE > written transformed storage format to: ./lib/output/ac-single-test1.output.storage
129+
```
130+
131+
The local ids will be auto generated using uuid v7. The classic server/DC macro-id is not used in Cloud and will be discarded.
132+
133+
&nbsp;
134+
135+
---
136+
137+
&nbsp;
138+
139+
### Run tests
140+
141+
you might need to add pytest to $PATH first, then:
142+
143+
```
144+
pytest
145+
```
146+
147+
---
148+
149+
&nbsp;
150+
151+
### License
152+
153+
[MIT](./LICENSE) © [codeclou GmbH](https://github.com/codeclou)

index.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Licensed under the MIT license: https://github.com/codeclou/advanced-codeblocks-cloud-migration-helper/blob/main/LICENSE
2+
3+
from argparse import ArgumentParser
4+
from lib.macro_storage_format_parser import MacroStorageFormatParser
5+
6+
print("======================================")
7+
print(" ADVANCED CODEBLOCKS MIGRATION HELPER")
8+
print("======================================")
9+
print(" ")
10+
11+
#
12+
# COMMANDLINE ARGUMENTS
13+
#
14+
parser = ArgumentParser()
15+
parser.add_argument("-if", "--inputfile", dest="inputfile",
16+
help="the inputfile, a confluence page in storage format XML", metavar="INPUTFILE", required=True)
17+
parser.add_argument("-of", "--outputfile", dest="outputfile",
18+
help="the outputfile, a confluence page in storage format XML", metavar="OUTPUTFILE", required=True)
19+
parser.add_argument("-ek", "--extension-key", dest="extensionkey",
20+
help="the extension key, TODO ", metavar="EXTENSIONKEY", required=True)
21+
args = parser.parse_args()
22+
23+
#
24+
# RUN TRANSFORMER
25+
#
26+
print("extension key part: " + args.extensionkey)
27+
print(" ")
28+
parser = MacroStorageFormatParser(args.inputfile, args.outputfile, args.extensionkey, False)
29+
parser.transform();

lib/__init__.py

Whitespace-only changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<p>Start of page.</p>
2+
<ac:task-list>
3+
<ac:task>
4+
<ac:task-status>incomplete</ac:task-status>
5+
<ac:task-body>task list item</ac:task-body>
6+
</ac:task>
7+
</ac:task-list>
8+
<ac:link>
9+
<ri:attachment ri:filename="atlassian_logo.gif" />
10+
<ac:plain-text-link-body>
11+
<![CDATA[Link to a Confluence Attachment]]>
12+
</ac:plain-text-link-body>
13+
</ac:link>
14+
<ac:structured-macro ac:name="advanced-codeblock-macro" ac:schema-version="1" ac:macro-id="82bb07fb-13ea-4437-b8e5-503ef909fca4">
15+
<ac:parameter ac:name="enableddl">true</ac:parameter>
16+
<ac:parameter ac:name="lang">Apache</ac:parameter>
17+
<ac:parameter ac:name="globaltitle">AC_testsysteme_ddl</ac:parameter>
18+
<ac:plain-text-body>
19+
<![CDATA[[testsystem 1]
20+
base.url = www.myserver1.com
21+
document.root = /www/server1
22+
23+
[testsystem 2]
24+
base.url = www.myserver2.com
25+
document.root = /www/server2
26+
27+
[content]
28+
<VirtualHost *:80>
29+
DocumentRoot ${document.root}
30+
ServerName ${base.url}
31+
...
32+
</VirtualHost>]]></ac:plain-text-body>
33+
</ac:structured-macro>
34+
<ac:link ac:anchor="Anchor Link">
35+
<ac:link-body>
36+
<ac:image>
37+
<ri:url ri:value="http://confluence.atlassian.com/images/logo/confluence_48_trans.png" />
38+
</ac:image>
39+
</ac:link-body>
40+
</ac:link>
41+
<ac:emoticon ac:name="tick" />
42+
<p>A selection list:&nbsp;<at:var at:name="MyList" />
43+
</p>
44+
<p>emoji inside p <ac:emoticon ac:name="tick" />
45+
</p>
46+
47+
<p>End of page.</p>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
<p>test123</p><ac:structured-macro ac:name="advanced-codeblock-macro" ac:schema-version="1" ac:macro-id="544fd4da-43cf-4d4b-b675-34ee3cb50000"><ac:parameter ac:name="enableddl">true</ac:parameter><ac:parameter ac:name="theme">light-spring</ac:parameter><ac:parameter ac:name="lang">Apache</ac:parameter><ac:parameter ac:name="expandFirst">true</ac:parameter><ac:parameter ac:name="globaltitle">multi title</ac:parameter><ac:plain-text-body><![CDATA[[test a]
3+
foo = bar
4+
5+
[content]
6+
<VirtualHost>
7+
serverName = ${foo}
8+
</VirtualHost> ]]></ac:plain-text-body></ac:structured-macro>
9+
<p><br /></p>
10+
<p><br /></p>
11+
<p><br /></p>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>remote</p><ac:structured-macro ac:name="advanced-remote-codeblock-macro" ac:schema-version="1" ac:macro-id="931fb126-017c-4208-b33b-81135b2a0cf7"><ac:parameter ac:name="remotefileurl">https://codeclou.io/file.py</ac:parameter><ac:parameter ac:name="theme">light-spring</ac:parameter><ac:parameter ac:name="lang">Apache</ac:parameter><ac:parameter ac:name="expandFirst">true</ac:parameter><ac:parameter ac:name="remotefilehttppassword">pass</ac:parameter><ac:parameter ac:name="remotefilehttpuser">user</ac:parameter><ac:parameter ac:name="globaltitle">remotey</ac:parameter><ac:plain-text-body><![CDATA[[test a]
2+
foo = bar]]></ac:plain-text-body></ac:structured-macro>
3+
<p><br /></p>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
<table class="wrapped"><colgroup> <col /> <col /> </colgroup>
3+
<tbody>
4+
<tr>
5+
<th scope="col">Hello</th>
6+
<th scope="col">Table</th></tr>
7+
<tr>
8+
<td>foo</td>
9+
<td>
10+
<div class="content-wrapper"><ac:structured-macro ac:name="code" ac:schema-version="1" ac:macro-id="3b2a2c57-ef21-41b6-b943-d71dd1672efd"><ac:parameter ac:name="language">bash</ac:parameter><ac:parameter ac:name="theme">DJango</ac:parameter><ac:parameter ac:name="title">Simple Code</ac:parameter><ac:parameter ac:name="linenumbers">true</ac:parameter><ac:plain-text-body><![CDATA[foo = bar]]></ac:plain-text-body></ac:structured-macro></div></td></tr>
11+
<tr>
12+
<td>blubb</td>
13+
<td>fo emoji <ac:emoticon ac:name="grinning face with smiling eyes" ac:emoji-id="1f604" /> bar</td></tr>
14+
<tr>
15+
<td>bla</td>
16+
<td>
17+
<div class="content-wrapper"><ac:structured-macro ac:name="advanced-single-codeblock-macro" ac:schema-version="1" ac:macro-id="0a76fb27-ee70-41a4-bead-063a0908804d"><ac:parameter ac:name="enableddl">true</ac:parameter><ac:parameter ac:name="theme">light-mono</ac:parameter><ac:parameter ac:name="lang">Bash</ac:parameter><ac:parameter ac:name="globaltitle">test</ac:parameter><ac:plain-text-body><![CDATA[echo "foo"]]></ac:plain-text-body></ac:structured-macro></div></td></tr></tbody></table>
18+
<p><br /></p>

0 commit comments

Comments
 (0)