mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-22 22:06:43 +00:00
Remove line breaks from diff
This commit is contained in:
parent
8c94400411
commit
e13bcf0586
19
main.py
19
main.py
@ -62,14 +62,17 @@ def main():
|
|||||||
|
|
||||||
for n, line in enumerate(diff_file):
|
for n, line in enumerate(diff_file):
|
||||||
# First look for a diff header so we can determine the file the changes relate to.
|
# First look for a diff header so we can determine the file the changes relate to.
|
||||||
header_search = header_pattern.search(line)
|
encoded_line = line.encode('utf-8')
|
||||||
|
cleaned_line = encoded_line.rstrip(b'\r\n').decode('utf-8')
|
||||||
|
|
||||||
|
header_search = header_pattern.search(cleaned_line)
|
||||||
if header_search:
|
if header_search:
|
||||||
files = header_search.group(0).split(' ')
|
files = header_search.group(0).split(' ')
|
||||||
curr_file = files[1][2:]
|
curr_file = files[1][2:]
|
||||||
line_counter = None
|
line_counter = None
|
||||||
else:
|
else:
|
||||||
# Look for hunks so we can get the line numbers for the changes.
|
# Look for hunks so we can get the line numbers for the changes.
|
||||||
hunk_search = hunk_start_pattern.search(line)
|
hunk_search = hunk_start_pattern.search(cleaned_line)
|
||||||
if hunk_search:
|
if hunk_search:
|
||||||
if curr_issue:
|
if curr_issue:
|
||||||
curr_issue['hunk'] = lines
|
curr_issue['hunk'] = lines
|
||||||
@ -83,9 +86,9 @@ def main():
|
|||||||
line_counter = hunk_start
|
line_counter = hunk_start
|
||||||
else:
|
else:
|
||||||
# Look for additions and deletions (specifically TODOs) within each hunk.
|
# Look for additions and deletions (specifically TODOs) within each hunk.
|
||||||
addition_search = addition_pattern.search(line)
|
addition_search = addition_pattern.search(cleaned_line)
|
||||||
if addition_search:
|
if addition_search:
|
||||||
lines.append(line[1:])
|
lines.append(cleaned_line[1:])
|
||||||
addition = addition_search.group(0)
|
addition = addition_search.group(0)
|
||||||
todo_search = todo_pattern.search(addition)
|
todo_search = todo_pattern.search(addition)
|
||||||
if todo_search:
|
if todo_search:
|
||||||
@ -115,18 +118,18 @@ def main():
|
|||||||
if line_counter is not None:
|
if line_counter is not None:
|
||||||
line_counter += 1
|
line_counter += 1
|
||||||
else:
|
else:
|
||||||
deletion_search = deletion_pattern.search(line)
|
deletion_search = deletion_pattern.search(cleaned_line)
|
||||||
if deletion_search:
|
if deletion_search:
|
||||||
deletion = deletion_search.group(0)
|
deletion = deletion_search.group(0)
|
||||||
todo_search = todo_pattern.search(deletion)
|
todo_search = todo_pattern.search(deletion)
|
||||||
if todo_search:
|
if todo_search:
|
||||||
closed_issues.append(todo_search.group(0))
|
closed_issues.append(todo_search.group(0))
|
||||||
else:
|
else:
|
||||||
lines.append(line[1:])
|
lines.append(cleaned_line[1:])
|
||||||
|
|
||||||
if previous_line_was_todo:
|
if previous_line_was_todo:
|
||||||
# Check if this is a continuation from the previous line.
|
# Check if this is a continuation from the previous line.
|
||||||
comment_search = comment_pattern.search(line)
|
comment_search = comment_pattern.search(cleaned_line)
|
||||||
if comment_search:
|
if comment_search:
|
||||||
curr_issue['body'] += '\n\n' + comment_search.group(0).lstrip()
|
curr_issue['body'] += '\n\n' + comment_search.group(0).lstrip()
|
||||||
line_counter += 1
|
line_counter += 1
|
||||||
@ -165,7 +168,7 @@ def main():
|
|||||||
and extension in languages_dict[language]['extensions']):
|
and extension in languages_dict[language]['extensions']):
|
||||||
markdown_language = languages_dict[language]['ace_mode']
|
markdown_language = languages_dict[language]['ace_mode']
|
||||||
if markdown_language:
|
if markdown_language:
|
||||||
body += '\n\n' + '```' + markdown_language + '\n'.join(hunk) + '```'
|
body += '\n\n' + '```' + markdown_language + '\n' + '\n'.join(hunk) + '```'
|
||||||
else:
|
else:
|
||||||
body += '\n\n' + '```' + '\n'.join(hunk) + '```'
|
body += '\n\n' + '```' + '\n'.join(hunk) + '```'
|
||||||
new_issue_body = {'title': title, 'body': body, 'labels': ['todo']}
|
new_issue_body = {'title': title, 'body': body, 'labels': ['todo']}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user