Skip to content

Commit

Permalink
convrert [issue] to links
Browse files Browse the repository at this point in the history
  • Loading branch information
szn committed Mar 27, 2024
1 parent 71b7210 commit 6147ce7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = confluence.md
version = 0.2.10
version = 0.2.11
author = Szymon Nieradka
description = Markdown to Confluence - upload any .md files to your Confluence cloud page
long_description = file: README.md
Expand Down
26 changes: 26 additions & 0 deletions src/md2cf/utils/confluencemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

CF_URL = re.compile(r"(?P<host>https?://[^/]+)/.*/(?P<page_id>\d+)")
IMAGE_PATTERN = re.compile(r"\!\[(?P<alt>.*)\]\((?P<path>[^:)]+)\)")
ISSUE_PATTERN = re.compile(r"\[(?P<key>\w[\w\d]*-\d+)\]")


class ConfluenceMD(atlassian.Confluence):
Expand All @@ -34,12 +35,36 @@ def __init__(
cloud=bool(token),
token=token,
)
self.jira = atlassian.Jira(
url=url,
username=username,
password=(password or token),
verify_ssl=verify_ssl,
cloud=bool(token),
token=token
)
self.md_file = md_file
self.add_meta = add_meta
self.add_info_panel = add_info_panel
self.add_label = add_label
self.md_file_dir = os.path.dirname(md_file)

def rewrite_issues(self, html):
logger.debug("Replacing [ISSUE-KEY] with html links")
issues = []
for issue in ISSUE_PATTERN.finditer(html):
issues.append(issue.group("key"))

for key in issues:
logger.debug(f" - [{key}] with html link")
issue = self.jira.issue(key)
summary = issue['fields']['summary']
status = issue['fields']['status']['name']
html = html.replace(
f"[{key}]",
f"<a href=\"{self.url}/browse/{key}\">{key} {summary}{status}</a>")
return html

def rewrite_images(
self, page_id: str, html: str, images: List[Tuple[str, str]]
) -> str:
Expand Down Expand Up @@ -241,6 +266,7 @@ def md_file_to_html(self, page_id: Optional[str]) -> Tuple[Any, Optional[str], O
if self.add_info_panel:
html = self.get_info_panel() + html

html = self.rewrite_issues(html)
html = self.rewrite_images(page_id if page_id else page_id_from_meta, html, images)
return html, page_id_from_meta, url, len(images) > 0

Expand Down

0 comments on commit 6147ce7

Please sign in to comment.