mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-22 22:06:43 +00:00
Merge pull request #241 from rgalonso/fix/handle-todo-comment-suffix
fix: don't include source with issue URL comment
This commit is contained in:
commit
59c6b5395c
3
Issue.py
3
Issue.py
@ -2,7 +2,7 @@ class Issue(object):
|
|||||||
"""Basic Issue model for collecting the necessary info to send to GitHub."""
|
"""Basic Issue model for collecting the necessary info to send to GitHub."""
|
||||||
|
|
||||||
def __init__(self, title, labels, assignees, milestone, body, hunk, file_name,
|
def __init__(self, title, labels, assignees, milestone, body, hunk, file_name,
|
||||||
start_line, num_lines, markdown_language, status, identifier, identifier_actual, ref, issue_url, issue_number, start_line_within_hunk=1):
|
start_line, num_lines, prefix, markdown_language, status, identifier, identifier_actual, ref, issue_url, issue_number, start_line_within_hunk=1):
|
||||||
self.title = title
|
self.title = title
|
||||||
self.labels = labels
|
self.labels = labels
|
||||||
self.assignees = assignees
|
self.assignees = assignees
|
||||||
@ -12,6 +12,7 @@ class Issue(object):
|
|||||||
self.file_name = file_name
|
self.file_name = file_name
|
||||||
self.start_line = start_line
|
self.start_line = start_line
|
||||||
self.num_lines = num_lines
|
self.num_lines = num_lines
|
||||||
|
self.prefix = prefix
|
||||||
self.markdown_language = markdown_language
|
self.markdown_language = markdown_language
|
||||||
self.status = status
|
self.status = status
|
||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
|
|||||||
@ -403,7 +403,7 @@ class TodoParser(object):
|
|||||||
for line_number_within_comment_block, line in enumerate(comment_lines):
|
for line_number_within_comment_block, line in enumerate(comment_lines):
|
||||||
line_status, committed_line = self._get_line_status(line)
|
line_status, committed_line = self._get_line_status(line)
|
||||||
line_statuses.append(line_status)
|
line_statuses.append(line_status)
|
||||||
cleaned_line = self._clean_line(committed_line, marker)
|
cleaned_line, pre_marker_length, post_marker_length = self._clean_line(committed_line, marker)
|
||||||
line_title, ref, identifier, identifier_actual = self._get_title(cleaned_line)
|
line_title, ref, identifier, identifier_actual = self._get_title(cleaned_line)
|
||||||
if line_title:
|
if line_title:
|
||||||
if prev_line_title and line_status == line_statuses[-2]:
|
if prev_line_title and line_status == line_statuses[-2]:
|
||||||
@ -423,6 +423,7 @@ class TodoParser(object):
|
|||||||
+ comment_block['start'] + line_number_within_comment_block),
|
+ comment_block['start'] + line_number_within_comment_block),
|
||||||
start_line_within_hunk=comment_block['start'] + line_number_within_comment_block + 1,
|
start_line_within_hunk=comment_block['start'] + line_number_within_comment_block + 1,
|
||||||
num_lines=1,
|
num_lines=1,
|
||||||
|
prefix=(' '*pre_marker_length)+(marker['pattern'] if marker['type'] == 'line' else '')+(' '*post_marker_length),
|
||||||
markdown_language=hunk_info['markdown_language'],
|
markdown_language=hunk_info['markdown_language'],
|
||||||
status=line_status,
|
status=line_status,
|
||||||
identifier=identifier,
|
identifier=identifier,
|
||||||
@ -532,8 +533,10 @@ class TodoParser(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _clean_line(comment, marker):
|
def _clean_line(comment, marker):
|
||||||
"""Remove unwanted symbols and whitespace."""
|
"""Remove unwanted symbols and whitespace."""
|
||||||
comment = comment.strip()
|
post_marker_length = 0
|
||||||
if marker['type'] == 'block':
|
if marker['type'] == 'block':
|
||||||
|
original_comment = comment
|
||||||
|
comment = comment.strip()
|
||||||
start_pattern = r'^' + marker['pattern']['start']
|
start_pattern = r'^' + marker['pattern']['start']
|
||||||
end_pattern = marker['pattern']['end'] + r'$'
|
end_pattern = marker['pattern']['end'] + r'$'
|
||||||
comment = re.sub(start_pattern, '', comment)
|
comment = re.sub(start_pattern, '', comment)
|
||||||
@ -541,10 +544,17 @@ class TodoParser(object):
|
|||||||
# Some block comments might have an asterisk on each line.
|
# Some block comments might have an asterisk on each line.
|
||||||
if '*' in start_pattern and comment.startswith('*'):
|
if '*' in start_pattern and comment.startswith('*'):
|
||||||
comment = comment.lstrip('*')
|
comment = comment.lstrip('*')
|
||||||
|
comment = comment.strip()
|
||||||
|
pre_marker_length = original_comment.find(comment)
|
||||||
else:
|
else:
|
||||||
pattern = r'^' + marker['pattern']
|
comment_segments = re.search(fr'^(.*?)({marker["pattern"]})(\s*)(.*)', comment)
|
||||||
comment = re.sub(pattern, '', comment)
|
if comment_segments:
|
||||||
return comment.strip()
|
pre_marker_text, _, post_marker_whitespace, comment = comment_segments.groups()
|
||||||
|
pre_marker_length = len(pre_marker_text)
|
||||||
|
post_marker_length = len(post_marker_whitespace)
|
||||||
|
else:
|
||||||
|
pre_marker_length = 0
|
||||||
|
return comment, pre_marker_length, post_marker_length
|
||||||
|
|
||||||
def _get_title(self, comment):
|
def _get_title(self, comment):
|
||||||
"""Check the passed comment for a new issue title (and reference, if specified)."""
|
"""Check the passed comment for a new issue title (and reference, if specified)."""
|
||||||
@ -553,13 +563,13 @@ class TodoParser(object):
|
|||||||
title_identifier_actual = None
|
title_identifier_actual = None
|
||||||
title_identifier = None
|
title_identifier = None
|
||||||
for identifier in self.identifiers:
|
for identifier in self.identifiers:
|
||||||
title_pattern = re.compile(fr'(\b{re.escape(identifier)}\b)(\(([^)]+)\))?\s*:?\s*(.+)', re.IGNORECASE)
|
title_pattern = re.compile(fr'(^.*?)(\s*?)(\b{re.escape(identifier)}\b)(\(([^)]+)\))?\s*:?\s*(.+)', re.IGNORECASE)
|
||||||
title_search = title_pattern.search(comment)
|
title_search = title_pattern.search(comment)
|
||||||
if title_search:
|
if title_search:
|
||||||
title_identifier_actual = title_search.group(1)
|
title_identifier_actual = title_search.group(3)
|
||||||
title_identifier = identifier
|
title_identifier = identifier
|
||||||
ref = title_search.group(3) # may be empty, which is OK
|
ref = title_search.group(5) # may be empty, which is OK
|
||||||
title = title_search.group(4)
|
title = title_search.group(6)
|
||||||
break
|
break
|
||||||
return title, ref, title_identifier, title_identifier_actual
|
return title, ref, title_identifier, title_identifier_actual
|
||||||
|
|
||||||
|
|||||||
2
main.py
2
main.py
@ -78,7 +78,7 @@ def process_diff(diff, client=Client(), insert_issue_urls=False, parser=TodoPars
|
|||||||
old_line = file_lines[line_number]
|
old_line = file_lines[line_number]
|
||||||
remove = fr'(?i:{raw_issue.identifier}).*{re.escape(raw_issue.title)}'
|
remove = fr'(?i:{raw_issue.identifier}).*{re.escape(raw_issue.title)}'
|
||||||
insert = f'Issue URL: {client.get_issue_url(new_issue_number)}'
|
insert = f'Issue URL: {client.get_issue_url(new_issue_number)}'
|
||||||
new_line = re.sub(remove, insert, old_line)
|
new_line = re.sub('^.*'+remove, raw_issue.prefix + insert, old_line)
|
||||||
# make sure the above operation worked as intended
|
# make sure the above operation worked as intended
|
||||||
if new_line != old_line:
|
if new_line != old_line:
|
||||||
# Check if the URL line already exists, if so abort.
|
# Check if the URL line already exists, if so abort.
|
||||||
|
|||||||
@ -110,10 +110,6 @@ class IssueUrlInsertionTest(unittest.TestCase):
|
|||||||
self._setUp(['test_same_title_in_same_file.diff'])
|
self._setUp(['test_same_title_in_same_file.diff'])
|
||||||
self._standardTest(5)
|
self._standardTest(5)
|
||||||
|
|
||||||
# There is a known bug related to this issue, so until it's resolved
|
|
||||||
# this is an expected failure.
|
|
||||||
# See #229
|
|
||||||
@unittest.expectedFailure
|
|
||||||
def test_comment_suffix_after_source_line(self):
|
def test_comment_suffix_after_source_line(self):
|
||||||
self._setUp(['test_comment_suffix_after_source_line.diff'])
|
self._setUp(['test_comment_suffix_after_source_line.diff'])
|
||||||
self._standardTest(1)
|
self._standardTest(1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user