mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-23 06:16:43 +00:00
Enable issue escaping
This commit is contained in:
parent
c90d4c3f82
commit
85df7d016a
@ -76,3 +76,7 @@ inputs:
|
|||||||
description: 'Base url of GitHub API'
|
description: 'Base url of GitHub API'
|
||||||
required: false
|
required: false
|
||||||
default: ${{ github.api_url }}
|
default: ${{ github.api_url }}
|
||||||
|
ESCAPE:
|
||||||
|
description: 'Escape all special Markdown characters'
|
||||||
|
required: false
|
||||||
|
default: true
|
||||||
23
main.py
23
main.py
@ -295,6 +295,9 @@ class TodoParser(object):
|
|||||||
ORG_PROJECTS_PATTERN = re.compile(r'(?<=org projects:\s).+')
|
ORG_PROJECTS_PATTERN = re.compile(r'(?<=org projects:\s).+')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
# Determine if the Issues should be escaped.
|
||||||
|
self.should_escape = os.getenv('INPUT_ESCAPE', 'true') == 'true'
|
||||||
|
|
||||||
# Load any custom identifiers, otherwise use the default.
|
# Load any custom identifiers, otherwise use the default.
|
||||||
custom_identifiers = os.getenv('INPUT_IDENTIFIERS')
|
custom_identifiers = os.getenv('INPUT_IDENTIFIERS')
|
||||||
self.identifiers = ['TODO']
|
self.identifiers = ['TODO']
|
||||||
@ -530,6 +533,9 @@ class TodoParser(object):
|
|||||||
elif org_projects:
|
elif org_projects:
|
||||||
issue.org_projects.extend(org_projects)
|
issue.org_projects.extend(org_projects)
|
||||||
elif len(cleaned_line):
|
elif len(cleaned_line):
|
||||||
|
if self.should_escape:
|
||||||
|
issue.body.append(self._escape_markdown(cleaned_line))
|
||||||
|
else:
|
||||||
issue.body.append(cleaned_line)
|
issue.body.append(cleaned_line)
|
||||||
|
|
||||||
if issue is not None and issue.identifier is not None and self.identifiers_dict is not None:
|
if issue is not None and issue.identifier is not None and self.identifiers_dict is not None:
|
||||||
@ -541,6 +547,23 @@ class TodoParser(object):
|
|||||||
|
|
||||||
return issue
|
return issue
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _escape_markdown(comment):
|
||||||
|
# All basic characters according to: https://www.markdownguide.org/basic-syntax
|
||||||
|
must_escaped = ['\\', '<', '>', '#', '`', '*', '_', '[', ']', '(', ')', '!', '+', '-', '.', '|', '{', '}', '~', '=']
|
||||||
|
|
||||||
|
escaped = ''
|
||||||
|
|
||||||
|
# Linear Escape Algorithm, because the algorithm ends in an infinite loop when using the function 'replace',
|
||||||
|
# which tries to replace all backslashes with duplicate backslashes, i.e. also the already other escaped
|
||||||
|
# characters.
|
||||||
|
for c in comment:
|
||||||
|
if c in must_escaped:
|
||||||
|
escaped += '\\' + c
|
||||||
|
else:
|
||||||
|
escaped += c
|
||||||
|
return escaped
|
||||||
|
|
||||||
def _get_line_status(self, comment):
|
def _get_line_status(self, comment):
|
||||||
"""Return a Tuple indicating whether this is an addition/deletion/unchanged, plus the cleaned comment."""
|
"""Return a Tuple indicating whether this is an addition/deletion/unchanged, plus the cleaned comment."""
|
||||||
addition_search = self.ADDITION_PATTERN.search(comment)
|
addition_search = self.ADDITION_PATTERN.search(comment)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user