Skip to content

Commit e6fcedc

Browse files
committed
Reformat code
1 parent 240db0f commit e6fcedc

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

main.py

+23-14
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self):
6464
self.auto_assign = os.getenv('INPUT_AUTO_ASSIGN', 'false') == 'true'
6565
self.actor = os.getenv('INPUT_ACTOR')
6666

67+
# noinspection PyMethodMayBeStatic
6768
def get_timestamp(self, commit):
6869
return commit.get('timestamp')
6970

@@ -220,7 +221,7 @@ def __init__(self):
220221
try:
221222
custom_identifiers_dict = json.loads(custom_identifiers)
222223
for identifier_dict in custom_identifiers_dict:
223-
if type(identifier_dict['name']) != str or type(identifier_dict['labels']) != list:
224+
if type(identifier_dict['name']) is not str or type(identifier_dict['labels']) is not list:
224225
raise TypeError
225226
self.identifiers = [identifier['name'] for identifier in custom_identifiers_dict]
226227
self.identifiers_dict = custom_identifiers_dict
@@ -256,6 +257,7 @@ def __init__(self):
256257
if custom_languages != '':
257258
# Load all custom languages
258259
for path in custom_languages.split(','):
260+
# noinspection PyBroadException
259261
try:
260262
# Decide if the path is a url or local file
261263
if path.startswith('http'):
@@ -302,9 +304,10 @@ def __init__(self):
302304
'language': lang['language'],
303305
'markers': lang['markers']
304306
})
305-
except:
307+
except Exception:
306308
print('An error occurred in the custom language file (\''+path+'\')')
307-
print('Please check the file, or if it represents undefined behavior, create an issue at \'https://github.com/alstr/todo-to-issue-action/issues\'')
309+
print('Please check the file, or if it represents undefined behavior, '
310+
'create an issue at \'https://github.com/alstr/todo-to-issue-action/issues\'')
308311

309312
# noinspection PyTypeChecker
310313
def parse(self, diff_file):
@@ -346,8 +349,8 @@ def parse(self, diff_file):
346349
continue
347350

348351
# Break this section down into individual changed code blocks.
349-
line_numbers = re.finditer(self.LINE_NUMBERS_PATTERN, hunk)
350-
for i, line_numbers in enumerate(line_numbers):
352+
line_numbers_iterator = re.finditer(self.LINE_NUMBERS_PATTERN, hunk)
353+
for i, line_numbers in enumerate(line_numbers_iterator):
351354
line_numbers_inner_search = re.search(self.LINE_NUMBERS_INNER_PATTERN, line_numbers.group(0))
352355
line_numbers_str = line_numbers_inner_search.group(0).strip('@@ -')
353356
start_line = line_numbers_str.split(' ')[1].strip('+')
@@ -367,6 +370,7 @@ def parse(self, diff_file):
367370
prev_index = len(code_blocks) - 1
368371
# Set the end of the last code block based on the start of this one.
369372
if prev_block and prev_block['file'] == block['file']:
373+
# noinspection PyTypedDict
370374
code_blocks[prev_index]['hunk_end'] = line_numbers.start()
371375
code_blocks[prev_index]['hunk'] = (prev_block['hunk']
372376
[prev_block['hunk_start']:line_numbers.start()])
@@ -405,13 +409,16 @@ def parse(self, diff_file):
405409
suff_escape_list.append(self._extract_character(to_escape['pattern']['start'], 1))
406410
search = to_escape['pattern']['end'].find(marker['pattern'])
407411
if search != -1:
408-
pref_escape_list.append(self._extract_character(to_escape['pattern']['end'], search - 1))
409-
410-
comment_pattern = (r'(^[+\-\s].*' +
411-
(r'(?<!(' + '|'.join(pref_escape_list) + r'))' if len(pref_escape_list) > 0 else '') +
412-
marker['pattern'] +
413-
(r'(?!(' + '|'.join(suff_escape_list) + r'))' if len(suff_escape_list) > 0 else '') +
414-
r'\s*.+$)')
412+
pref_escape_list.append(self._extract_character(to_escape['pattern']['end'],
413+
search - 1))
414+
415+
comment_pattern = (r'(^[+\-\s].*'
416+
+ (r'(?<!(' + '|'.join(pref_escape_list) + r'))' if len(pref_escape_list) > 0
417+
else '')
418+
+ marker['pattern']
419+
+ (r'(?!(' + '|'.join(suff_escape_list) + r'))' if len(suff_escape_list) > 0
420+
else '')
421+
+ r'\s*.+$)')
415422
comments = re.finditer(comment_pattern, block['hunk'], re.MULTILINE)
416423
extracted_comments = []
417424
prev_comment = None
@@ -543,15 +550,16 @@ def _extract_issue_if_exists(self, comment, marker, code_block):
543550
@staticmethod
544551
def _escape_markdown(comment):
545552
# All basic characters according to: https://www.markdownguide.org/basic-syntax
546-
must_escaped = ['\\', '<', '>', '#', '`', '*', '_', '[', ']', '(', ')', '!', '+', '-', '.', '|', '{', '}', '~', '=']
553+
must_escape = ['\\', '<', '>', '#', '`', '*', '_', '[', ']', '(', ')', '!', '+', '-', '.', '|', '{', '}', '~',
554+
'=']
547555

548556
escaped = ''
549557

550558
# Linear Escape Algorithm, because the algorithm ends in an infinite loop when using the function 'replace',
551559
# which tries to replace all backslashes with duplicate backslashes, i.e. also the already other escaped
552560
# characters.
553561
for c in comment:
554-
if c in must_escaped:
562+
if c in must_escape:
555563
escaped += '\\' + c
556564
else:
557565
escaped += c
@@ -657,6 +665,7 @@ def _get_milestone(self, comment):
657665
milestone = int(milestone)
658666
return milestone
659667

668+
# noinspection PyMethodMayBeStatic
660669
def _should_ignore(self, file):
661670
ignore_patterns = os.getenv('INPUT_IGNORE', None)
662671
if ignore_patterns:

0 commit comments

Comments
 (0)