diff --git a/setup.cfg b/setup.cfg index 3f166ec..218d09b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/src/md2cf/utils/confluencemd.py b/src/md2cf/utils/confluencemd.py index b02b08f..fc98695 100644 --- a/src/md2cf/utils/confluencemd.py +++ b/src/md2cf/utils/confluencemd.py @@ -10,6 +10,7 @@ CF_URL = re.compile(r"(?Phttps?://[^/]+)/.*/(?P\d+)") IMAGE_PATTERN = re.compile(r"\!\[(?P.*)\]\((?P[^:)]+)\)") +ISSUE_PATTERN = re.compile(r"\[(?P\w[\w\d]*-\d+)\]") class ConfluenceMD(atlassian.Confluence): @@ -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"{key} {summary} – {status}") + return html + def rewrite_images( self, page_id: str, html: str, images: List[Tuple[str, str]] ) -> str: @@ -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