Skip to content

Commit

Permalink
[TECH-272] Fix regex match for links
Browse files Browse the repository at this point in the history
branch: feature/TECH-272-upgrade-monorepo
  • Loading branch information
SamTheisens committed May 15, 2023
1 parent 05dc610 commit 0426623
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mpyl/reporting/targets/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

def to_slack_markdown(markdown: str) -> str:
regex_replace = (
(re.compile(r'\[(.*)\]\((.*)\)', flags=re.M), r'<\2|\1>'),
(re.compile(r'\[(.*?)\]\((.*?)\)'), r'<\2|\1>'),
(re.compile(r'^- ', flags=re.M), '• '),
(re.compile(r'^ - ', flags=re.M), ' ◦ '),
(re.compile(r'^ - ', flags=re.M), ' ⬩ '),
Expand All @@ -54,8 +54,8 @@ def to_slack_markdown(markdown: str) -> str:
(re.compile(r'\*\*'), '*'),
(re.compile(r'~~'), '~'),
)
for regex, replacement in regex_replace:
markdown = regex.sub(replacement, markdown)
for pattern, replacement in regex_replace:
markdown = re.sub(pattern, replacement, markdown)
return markdown


Expand Down
7 changes: 7 additions & 0 deletions tests/reporting/targets/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ def test_convert_md_to_slack(self):
with open(self.test_formatting_resource_path / "markdown_run_with_plan.md", encoding='utf-8') as markdown:
markdown_report = to_slack_markdown(markdown.read())
assert_roundtrip(self.test_targets_resource_path / "markdown_run_slack.md", markdown_report)

def test_should_lazy_match_links(self):
md_with_links = "*[nodeservice](https://nodeservice-96.test.nl/swagger/index.html)* " \
"*[sbtservice](https://sbtservice-96.test.nl/swagger/index.html)*"

assert to_slack_markdown(md_with_links) == '*<https://nodeservice-96.test.nl/swagger/index.html|nodeservice>*' \
' *<https://sbtservice-96.test.nl/swagger/index.html|sbtservice>*'

0 comments on commit 0426623

Please sign in to comment.